Skip to content

Commit

Permalink
MONDRIAN: Oops!
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 8289]
  • Loading branch information
julianhyde committed Dec 9, 2006
1 parent ef9d5b9 commit 4ac119d
Show file tree
Hide file tree
Showing 2 changed files with 679 additions and 674 deletions.
44 changes: 23 additions & 21 deletions src/main/mondrian/olap/EnumeratedValues.java
Expand Up @@ -24,9 +24,11 @@
* <i>ClassName</i> instance</code> member to hold the singleton instance.
* {@link Access} is a simple example of this.</p>
*/
public class EnumeratedValues implements Cloneable {
/** map symbol names to values */
private Map<String, Value> valuesByName = new HashMap<String, Value>();
public class EnumeratedValues<V extends EnumeratedValues.Value>
implements Cloneable
{
/** Map symbol names to values */
private Map<String, V> valuesByName = new LinkedHashMap<String, V>();

/** the smallest ordinal value */
private int min = Integer.MAX_VALUE;
Expand All @@ -50,8 +52,8 @@ public EnumeratedValues() {
/**
* Creates an enumeration, with an array of values, and freezes it.
*/
public EnumeratedValues(Value[] values) {
for (Value value : values) {
public EnumeratedValues(V[] values) {
for (V value : values) {
register(value);
}
makeImmutable();
Expand All @@ -63,7 +65,7 @@ public EnumeratedValues(Value[] values) {
*/
public EnumeratedValues(String[] names) {
for (int i = 0; i < names.length; i++) {
register(new BasicValue(names[i], i, names[i]));
register((V) new BasicValue(names[i], i, names[i]));
}
makeImmutable();
}
Expand All @@ -74,7 +76,7 @@ public EnumeratedValues(String[] names) {
*/
public EnumeratedValues(String[] names, int[] codes) {
for (int i = 0; i < names.length; i++) {
register(new BasicValue(names[i], codes[i], names[i]));
register((V) new BasicValue(names[i], codes[i], names[i]));
}
makeImmutable();
}
Expand All @@ -85,12 +87,12 @@ public EnumeratedValues(String[] names, int[] codes) {
*/
public EnumeratedValues(String[] names, int[] codes, String[] descriptions) {
for (int i = 0; i < names.length; i++) {
register(new BasicValue(names[i], codes[i], descriptions[i]));
register((V) new BasicValue(names[i], codes[i], descriptions[i]));
}
makeImmutable();
}

public Object clone() {
public EnumeratedValues<V> clone() {
EnumeratedValues clone;
try {
clone = (EnumeratedValues) super.clone();
Expand All @@ -107,7 +109,7 @@ public Object clone() {
* already be immutable.
*/
public EnumeratedValues getMutableClone() {
return (EnumeratedValues) clone();
return clone();
}

/**
Expand All @@ -117,7 +119,7 @@ public EnumeratedValues getMutableClone() {
* @pre !isImmutable()
* @pre value.getName() != null
*/
public void register(Value value) {
public void register(V value) {
assert value != null : "pre: value != null";
Util.assertPrecondition(!isImmutable(), "isImmutable()");
final String name = value.getName();
Expand Down Expand Up @@ -193,10 +195,10 @@ public final boolean isValid(int ordinal) {
*
* @pre isImmutable()
*/
public final Value getValue(int ordinal) {
public final V getValue(int ordinal) {
Util.assertPrecondition(isImmutable());

return ordinalToValueMap[ordinal - min];
return (V) ordinalToValueMap[ordinal - min];
}

/**
Expand Down Expand Up @@ -243,8 +245,8 @@ public final int getOrdinal(String name) {
* @throws Error if the name is not a member of the enumeration and
* <code>fail</code> is true
*/
public Value getValue(String name, final boolean fail) {
final Value value = valuesByName.get(name);
public V getValue(String name, final boolean fail) {
final V value = valuesByName.get(name);
if (value == null && fail) {
throw new Error("Unknown enum name: " + name);
}
Expand All @@ -259,10 +261,10 @@ public Value getValue(String name, final boolean fail) {
* @throws Error if the name is not a member of the enumeration and
* <code>fail</code> is true
*/
public Value getValueIgnoreCase(String name, boolean fail) {
public V getValueIgnoreCase(String name, boolean fail) {
for (Value value : ordinalToValueMap) {
if (value != null && value.getName().equalsIgnoreCase(name)) {
return value;
return (V) value;
}
}
if (fail) {
Expand All @@ -272,7 +274,7 @@ public Value getValueIgnoreCase(String name, boolean fail) {
}

/**
* Returns the names in this enumeration, in no particular order.
* Returns the names in this enumeration, in declaration order.
*/
public String[] getNames() {
return valuesByName.keySet().toArray(emptyStringArray);
Expand All @@ -281,8 +283,8 @@ public String[] getNames() {
/**
* Returns the members of this enumeration, sorted by name.
*/
public List<Value> getValuesSortedByName() {
List<Value> list = new ArrayList<Value>();
public List<V> getValuesSortedByName() {
List<V> list = new ArrayList<V>();
final String[] names = getNames();
Arrays.sort(names);
for (String name : names) {
Expand All @@ -305,7 +307,7 @@ public RuntimeException badValue(int ordinal) {
* Returns an exception indicating that we didn't expect to find this value
* here.
*/
public RuntimeException unexpected(Value value) {
public RuntimeException unexpected(V value) {
return Util.newInternal("Was not expecting value '" + value +
"' for enumeration '" + getClass().getName() +
"' in this context");
Expand Down

0 comments on commit 4ac119d

Please sign in to comment.