01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.outerj.daisy.query.model;
17:
18: import java.util.*;
19:
20: /**
21: * Enumeration of types that can occur in queries. This is a superset of
22: * {@link org.outerj.daisy.repository.ValueType}.
23: */
24: public enum QValueType {
25: UNDEFINED("undefined"), STRING("string"), DATE("date"), DATETIME(
26: "datetime"), LONG("long"), DOUBLE("double"), DECIMAL(
27: "decimal"), BOOLEAN("boolean"), XML("xml"), VERSION_STATE(
28: "version_state"), LINK("link"), DOCID("docid");
29:
30: private final String name;
31: private static final EnumMap<QValueType, EnumSet<QValueType>> compatibleTypes = new EnumMap<QValueType, EnumSet<QValueType>>(
32: QValueType.class);
33: static {
34: EnumSet<QValueType> UNDEFINED_SINGLETON = EnumSet.of(UNDEFINED);
35: for (QValueType type : QValueType.values())
36: compatibleTypes.put(type, UNDEFINED_SINGLETON);
37:
38: compatibleTypes.put(DATE, EnumSet.of(DATETIME, UNDEFINED));
39: compatibleTypes.put(DATETIME, EnumSet.of(DATE, UNDEFINED));
40: compatibleTypes.put(LONG, EnumSet.of(DECIMAL, UNDEFINED));
41: compatibleTypes.put(DOUBLE, EnumSet
42: .of(DECIMAL, LONG, UNDEFINED));
43: compatibleTypes.put(DECIMAL, EnumSet.of(DECIMAL, LONG,
44: UNDEFINED));
45: }
46:
47: private QValueType(String name) {
48: this .name = name;
49: }
50:
51: public String toString() {
52: return name;
53: }
54:
55: public boolean isCompatible(QValueType otherValueType) {
56: return otherValueType == this
57: || compatibleTypes.get(this).contains(otherValueType);
58: }
59: }
|