001: /**********************************************************************
002: Copyright (c) 2004 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.metadata;
019:
020: import java.io.Serializable;
021:
022: import org.jpox.util.StringUtils;
023:
024: /**
025: * Representation of whether an item is indexed or not.
026: * @version $Revision: 1.5 $
027: */
028: public class IndexedValue implements Serializable {
029: /** indexed true **/
030: public static final IndexedValue TRUE = new IndexedValue(1);
031: /** indexed false **/
032: public static final IndexedValue FALSE = new IndexedValue(2);
033: /** indexed unique **/
034: public static final IndexedValue UNIQUE = new IndexedValue(3);
035:
036: /**
037: * The type id.
038: */
039: private final int typeId;
040:
041: /**
042: * constructor
043: * @param i type id
044: */
045: private IndexedValue(int i) {
046: this .typeId = i;
047: }
048:
049: /**
050: * Indicates whether some other object is "equal to" this one.
051: * @param o the reference object with which to compare.
052: * @return true if this object is the same as the obj argument;
053: * false otherwise.
054: */
055: public boolean equals(Object o) {
056: if (o instanceof IndexedValue) {
057: return ((IndexedValue) o).typeId == typeId;
058: }
059: return false;
060: }
061:
062: /**
063: * Returns a string representation of the object.
064: * @return a string representation of the object.
065: */
066: public String toString() {
067: switch (typeId) {
068: case 1:
069: return "true";
070: case 2:
071: return "false";
072: case 3:
073: return "unique";
074: }
075: return "";
076: }
077:
078: /**
079: * Accessor for the type.
080: * @return Type
081: **/
082: public int getType() {
083: return typeId;
084: }
085:
086: /**
087: * Obtain a IndexedValue for the given name by <code>value</code>
088: * @param value the name
089: * @return the IndexedValue found or IndexedValue.TRUE if not found. If <code>value</code> is null, returns null.
090: */
091: public static IndexedValue getIndexedValue(final String value) {
092: if (StringUtils.isWhitespace(value)) {
093: return null;
094: } else if (IndexedValue.TRUE.toString().equals(value)) {
095: return IndexedValue.TRUE;
096: } else if (IndexedValue.FALSE.toString().equals(value)) {
097: return IndexedValue.FALSE;
098: } else if (IndexedValue.UNIQUE.toString().equals(value)) {
099: return IndexedValue.UNIQUE;
100: }
101: return IndexedValue.TRUE;
102: }
103: }
|