001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.functor.range;
018
019/**
020 * Range factory.
021 *
022 * @since 1.0
023 * @version $Revision$ $Date$
024 */
025public final class Ranges {
026
027    /**
028     * Hidden constructor as this only is a helper class with static methods.
029     */
030    private Ranges() {
031    }
032
033    // Integer ranges
034    /**
035     * Create a new IntegerRange.
036     *
037     * @param from start
038     * @param to end
039     * @return IntegerRange
040     */
041    public static IntegerRange integerRange(Number from, Number to) {
042        return new IntegerRange(from, to);
043    }
044
045    /**
046     * Create a new IntegerRange.
047     *
048     * @param from start
049     * @param to end
050     * @param step increment
051     * @return IntegerRange
052     */
053    public static IntegerRange integerRange(Number from, Number to, Number step) {
054        return new IntegerRange(from, to, step);
055    }
056
057    /**
058     * Create a new IntegerRange.
059     *
060     * @param from start
061     * @param to end
062     * @return IntegerRange
063     */
064    public static IntegerRange integerRange(int from, int to) {
065        return new IntegerRange(from, to);
066    }
067
068    /**
069     * Create a new IntegerRange.
070     *
071     * @param from start
072     * @param to end
073     * @param step increment
074     * @return IntegerRange
075     */
076    public static IntegerRange integerRange(int from, int to, int step) {
077        return new IntegerRange(from, to, step);
078    }
079
080    /**
081     * Create a new IntegerRange.
082     *
083     * @param from start
084     * @param leftBoundType type of left bound
085     * @param to end
086     * @param rightBoundType type of right bound
087     * @return IntegerRange
088     */
089    public static IntegerRange integerRange(int from, BoundType leftBoundType,
090                                            int to, BoundType rightBoundType) {
091        return new IntegerRange(from, leftBoundType, to, rightBoundType);
092    }
093
094    /**
095     * Create a new IntegerRange.
096     *
097     * @param from start
098     * @param leftBoundType type of left bound
099     * @param to end
100     * @param rightBoundType type of right bound
101     * @param step increment
102     * @return IntegerRange
103     */
104    public static IntegerRange integerRange(int from, BoundType leftBoundType,
105                                            int to, BoundType rightBoundType,
106                                            int step) {
107        return new IntegerRange(from, leftBoundType, to, rightBoundType, step);
108    }
109
110    /**
111     * Create a new IntegerRange.
112     *
113     * @param leftEndpoint start
114     * @param rightEndpoint end
115     * @param step increment
116     * @return IntegerRange
117     */
118    public static IntegerRange integerRange(Endpoint<Integer> leftEndpoint,
119                                                Endpoint<Integer> rightEndpoint,
120                                                int step) {
121        return new IntegerRange(leftEndpoint, rightEndpoint, step);
122    }
123
124    /**
125     * Create a new LongRange.
126     *
127     * @param from start
128     * @param to end
129     * @return LongRange
130     */
131    public static LongRange longRange(Number from, Number to) {
132        return new LongRange(from, to);
133    }
134
135    /**
136     * Create a new IntegerRange.
137     *
138     * @param from start
139     * @param to end
140     * @param step increment
141     * @return LongRange
142     */
143    public static LongRange longRange(Number from, Number to, Number step) {
144        return new LongRange(from, to, step);
145    }
146
147    // Long ranges
148    /**
149     * Create a new LongRange.
150     *
151     * @param from start
152     * @param to end
153     * @return LongRange
154     */
155    public static LongRange longRange(long from, long to) {
156        return new LongRange(from, to);
157    }
158
159    /**
160     * Create a new LongRange.
161     *
162     * @param from start
163     * @param to end
164     * @param step increment
165     * @return LongRange
166     */
167    public static LongRange longRange(long from, long to, long step) {
168        return new LongRange(from, to, step);
169    }
170
171    /**
172     * Create a new LongRange.
173     *
174     * @param from start
175     * @param leftBoundType type of left bound
176     * @param to end
177     * @param rightBoundType type of right bound
178     * @return LongRange
179     */
180    public static LongRange longRange(long from, BoundType leftBoundType,
181                                      long to, BoundType rightBoundType) {
182        return new LongRange(from, leftBoundType, to, rightBoundType);
183    }
184
185    /**
186     * Create a new LongRange.
187     *
188     * @param from start
189     * @param leftBoundType type of left bound
190     * @param to end
191     * @param rightBoundType type of right bound
192     * @param step increment
193     * @return LongRange
194     */
195    public static LongRange longRange(long from, BoundType leftBoundType,
196                                      long to, BoundType rightBoundType,
197                                      long step) {
198        return new LongRange(from, leftBoundType, to, rightBoundType, step);
199    }
200
201    /**
202     * Create a new LongRange.
203     *
204     * @param leftEndpoint start
205     * @param rightEndpoint end
206     * @param step increment
207     * @return LongRange
208     */
209    public static LongRange longRange(Endpoint<Long> leftEndpoint,
210                                                Endpoint<Long> rightEndpoint,
211                                                long step) {
212        return new LongRange(leftEndpoint, rightEndpoint, step);
213    }
214
215    // Float ranges
216    /**
217     * Create a new FloatRange.
218     *
219     * @param from start
220     * @param to end
221     * @return FloatRange
222     */
223    public static FloatRange floatRange(Number from, Number to) {
224        return new FloatRange(from, to);
225    }
226
227    /**
228     * Create a new FloatRange.
229     *
230     * @param from start
231     * @param to end
232     * @param step increment
233     * @return FloatRange
234     */
235    public static FloatRange floatRange(Number from, Number to, Number step) {
236        return new FloatRange(from, to, step);
237    }
238
239    /**
240     * Create a new FloatRange.
241     *
242     * @param from start
243     * @param to end
244     * @return FloatRange
245     */
246    public static FloatRange floatRange(float from, float to) {
247        return new FloatRange(from, to);
248    }
249
250    /**
251     * Create a new FloatRange.
252     *
253     * @param from start
254     * @param to end
255     * @param step increment
256     * @return FloatRange
257     */
258    public static FloatRange floatRange(float from, float to, float step) {
259        return new FloatRange(from, to, step);
260    }
261
262    /**
263     * Create a new FloatRange.
264     *
265     * @param from start
266     * @param leftBoundType type of left bound
267     * @param to end
268     * @param rightBoundType type of right bound
269     * @return FloatRange
270     */
271    public static FloatRange floatRange(float from, BoundType leftBoundType,
272                                        float to, BoundType rightBoundType) {
273        return new FloatRange(from, leftBoundType, to, rightBoundType);
274    }
275
276    /**
277     * Create a new FloatRange.
278     *
279     * @param from start
280     * @param leftBoundType type of left bound
281     * @param to end
282     * @param rightBoundType type of right bound
283     * @param step increment
284     * @return FloatRange
285     */
286    public static FloatRange floatRange(float from, BoundType leftBoundType,
287                                        float to, BoundType rightBoundType,
288                                        float step) {
289        return new FloatRange(from, leftBoundType, to, rightBoundType, step);
290    }
291
292    /**
293     * Create a new FloatRange.
294     *
295     * @param leftEndpoint start
296     * @param rightEndpoint end
297     * @param step increment
298     * @return FloatRange
299     */
300    public static FloatRange floatRange(Endpoint<Float> leftEndpoint,
301                                                Endpoint<Float> rightEndpoint,
302                                                float step) {
303        return new FloatRange(leftEndpoint, rightEndpoint, step);
304    }
305
306    // Double ranges
307    /**
308     * Create a new DoubleRange.
309     *
310     * @param from start
311     * @param to end
312     * @return DoubleRange
313     */
314    public static DoubleRange doubleRange(Number from, Number to) {
315        return new DoubleRange(from, to);
316    }
317
318    /**
319     * Create a new DoubleRange.
320     *
321     * @param from start
322     * @param to end
323     * @param step increment
324     * @return DoubleRange
325     */
326    public static DoubleRange doubleRange(Number from, Number to, Number step) {
327        return new DoubleRange(from, to, step);
328    }
329
330    /**
331     * Create a new DoubleRange.
332     *
333     * @param from start
334     * @param to end
335     * @return DoubleRange
336     */
337    public static DoubleRange doubleRange(double from, double to) {
338        return new DoubleRange(from, to);
339    }
340
341    /**
342     * Create a new DoubleRange.
343     *
344     * @param from start
345     * @param to end
346     * @param step increment
347     * @return DoubleRange
348     */
349    public static DoubleRange doubleRange(double from, double to, double step) {
350        return new DoubleRange(from, to, step);
351    }
352
353    /**
354     * Create a new DoubleRange.
355     *
356     * @param from start
357     * @param leftBoundType type of left bound
358     * @param to end
359     * @param rightBoundType type of right bound
360     * @param step increment
361     * @return DoubleRange
362     */
363    public static DoubleRange doubleRange(double from, BoundType leftBoundType,
364                                          double to, BoundType rightBoundType,
365                                          double step) {
366        return new DoubleRange(from, leftBoundType, to, rightBoundType, step);
367    }
368
369    /**
370     * Create a new DoubleRange.
371     *
372     * @param from start
373     * @param leftBoundType type of left bound
374     * @param to end
375     * @param rightBoundType type of right bound
376     * @return DoubleRange
377     */
378    public static DoubleRange doubleRange(double from, BoundType leftBoundType,
379                                          double to, BoundType rightBoundType) {
380        return new DoubleRange(from, leftBoundType, to, rightBoundType);
381    }
382
383    /**
384     * Create a new DoubleRange.
385     *
386     * @param leftEndpoint start
387     * @param rightEndpoint end
388     * @param step increment
389     * @return DoubleRange
390     */
391    public static DoubleRange doubleRange(Endpoint<Double> leftEndpoint,
392                                                Endpoint<Double> rightEndpoint,
393                                                double step) {
394        return new DoubleRange(leftEndpoint, rightEndpoint, step);
395    }
396
397    // Character ranges
398    /**
399     * Create a new CharacterRange.
400     *
401     * @param from start
402     * @param to end
403     * @return CharacterRange
404     */
405    public static CharacterRange characterRange(char from, char to) {
406        return new CharacterRange(from, to);
407    }
408
409    /**
410     * Create a new CharacterRange.
411     *
412     * @param from start
413     * @param to end
414     * @param step increment
415     * @return CharacterRange
416     */
417    public static CharacterRange characterRange(char from, char to, int step) {
418        return new CharacterRange(from, to, step);
419    }
420
421    /**
422     * Create a new CharacterRange.
423     *
424     * @param from start
425     * @param leftBoundType type of left bound
426     * @param to end
427     * @param rightBoundType type of right bound
428     * @return CharacterRange
429     */
430    public static CharacterRange characterRange(char from,
431                                                BoundType leftBoundType,
432                                                char to,
433                                                BoundType rightBoundType) {
434        return new CharacterRange(from, leftBoundType, to, rightBoundType);
435    }
436
437    /**
438     * Create a new CharacterRange.
439     *
440     * @param from start
441     * @param leftBoundType type of left bound
442     * @param to end
443     * @param rightBoundType type of right bound
444     * @param step increment
445     * @return CharacterRange
446     */
447    public static CharacterRange characterRange(char from,
448                                                BoundType leftBoundType,
449                                                char to,
450                                                BoundType rightBoundType,
451                                                int step) {
452        return new CharacterRange(from, leftBoundType, to, rightBoundType, step);
453    }
454
455    /**
456     * Create a new CharacterRange.
457     *
458     * @param leftEndpoint start
459     * @param rightEndpoint end
460     * @param step increment
461     * @return CharacterRange
462     */
463    public static CharacterRange characterRange(Endpoint<Character> leftEndpoint,
464                                                Endpoint<Character> rightEndpoint,
465                                                int step) {
466        return new CharacterRange(leftEndpoint, rightEndpoint, step);
467    }
468}