|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbstractStringIdentifierGenerator.java | - | 50% | 50% | 50% |
|
1 | /* | |
2 | * Copyright 2002-2004 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.apache.commons.id; | |
17 | ||
18 | /** | |
19 | * <p>Abstract superclass for StringIdentifierGenerator implementations.</p> | |
20 | * | |
21 | * @author Commons-Id team | |
22 | * @version $Id: AbstractStringIdentifierGenerator.java 155450 2005-02-26 13:22:31Z dirkv $ | |
23 | */ | |
24 | public abstract class AbstractStringIdentifierGenerator implements StringIdentifierGenerator { | |
25 | ||
26 | /** | |
27 | * Constant representing unlimited identifier length, returned by {@link #maxLength()} | |
28 | * when there is no upper bound to the length of an identifier in the sequence | |
29 | */ | |
30 | public static final int INFINITE_MAX_LENGTH = -1; | |
31 | ||
32 | /** | |
33 | * Maximum length for a numeric string representing a long value | |
34 | */ | |
35 | protected static final int MAX_LONG_NUMERIC_VALUE_LENGTH = | |
36 | Long.toString(Long.MIN_VALUE).length(); | |
37 | ||
38 | /** | |
39 | * Number of alphanumeric characters | |
40 | */ | |
41 | protected static final int ALPHA_NUMERIC_CHARSET_SIZE = 36; | |
42 | ||
43 | /** | |
44 | * Maximum length for an alphanumeric string representing a long value | |
45 | */ | |
46 | protected static final int MAX_LONG_ALPHANUMERIC_VALUE_LENGTH = | |
47 | Long.toString(Long.MAX_VALUE, ALPHA_NUMERIC_CHARSET_SIZE).length(); | |
48 | ||
49 | /** | |
50 | * Maximum length for a numeric string representing an integer value | |
51 | */ | |
52 | protected static final int MAX_INT_NUMERIC_VALUE_LENGTH = | |
53 | Integer.toString(Integer.MIN_VALUE).length(); | |
54 | ||
55 | /** | |
56 | * Maximum length for an alphanumeric string representing an integer value | |
57 | */ | |
58 | protected static final int MAX_INT_ALPHANUMERIC_VALUE_LENGTH = | |
59 | Integer.toString(Integer.MAX_VALUE, ALPHA_NUMERIC_CHARSET_SIZE).length(); | |
60 | ||
61 | /** | |
62 | * Default size of an alphanumeric identifier | |
63 | */ | |
64 | protected static final int DEFAULT_ALPHANUMERIC_IDENTIFIER_SIZE = 15; | |
65 | ||
66 | /** | |
67 | * Constructor | |
68 | */ | |
69 | 53 | protected AbstractStringIdentifierGenerator() { |
70 | 53 | super(); |
71 | } | |
72 | ||
73 | /** | |
74 | * <p>Gets the next identifier in the sequence.</p> | |
75 | * | |
76 | * @return the next String identifier in sequence | |
77 | */ | |
78 | public abstract String nextStringIdentifier(); | |
79 | ||
80 | /** | |
81 | * <p>Returns the maximum length (number or characters) for an identifier | |
82 | * from this sequence, or INFINITE_MAX_LENGTH if there is no upper bound to the length.</p> | |
83 | * | |
84 | * <p>The default implementation returns INFINITE_MAX_LENGTH. Implementations | |
85 | * with bounded length identifiers should override this method to | |
86 | * return the maximum length of a generated identifier.</p> | |
87 | * | |
88 | * @return the maximum identifier length, or INFINITE_MAX_LENGTH if there is no upper bound | |
89 | */ | |
90 | 0 | public long maxLength() { |
91 | 0 | return INFINITE_MAX_LENGTH; |
92 | } | |
93 | ||
94 | /** | |
95 | * <p>Returns the minimum length (number of characters) for an identifier | |
96 | * from this sequence.</p> | |
97 | * | |
98 | * <p>The default implementation returns 0. Implementations | |
99 | * with identifiers having a postive minimum length should override this | |
100 | * method to return the maximum length of a generated identifier.</p> | |
101 | * | |
102 | * @return the minimum identifier length | |
103 | */ | |
104 | 0 | public long minLength() { |
105 | 0 | return 0; |
106 | } | |
107 | ||
108 | /** | |
109 | * <p>Gets the next identifier in the sequence as an Object.</p> | |
110 | * | |
111 | * @return the next identifier in sequence | |
112 | */ | |
113 | 13 | public Object nextIdentifier() { |
114 | 13 | return nextStringIdentifier(); |
115 | } | |
116 | } |
|