1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.query.validate;
25
26 import java.util.Arrays;
27 import java.util.EnumSet;
28 import java.util.Set;
29 import net.jcip.annotations.Immutable;
30 import org.modeshape.common.collection.Collections;
31 import org.modeshape.graph.query.model.Operator;
32 import org.modeshape.graph.query.validate.Schemata.Column;
33
34 @Immutable
35 class ImmutableColumn implements Column {
36
37 public static final Set<Operator> ALL_OPERATORS = Collections.unmodifiableSet(EnumSet.allOf(Operator.class));
38 public static final Set<Operator> NO_OPERATORS = Collections.unmodifiableSet(EnumSet.noneOf(Operator.class));
39
40 public static final boolean DEFAULT_FULL_TEXT_SEARCHABLE = false;
41 public static final boolean DEFAULT_ORDERABLE = true;
42
43 private final boolean fullTextSearchable;
44 private final boolean orderable;
45 private final String name;
46 private final String type;
47 private final Set<Operator> operators;
48
49 protected ImmutableColumn( String name,
50 String type ) {
51 this(name, type, DEFAULT_FULL_TEXT_SEARCHABLE, DEFAULT_ORDERABLE, ALL_OPERATORS);
52 }
53
54 protected ImmutableColumn( String name,
55 String type,
56 boolean fullTextSearchable ) {
57 this(name, type, fullTextSearchable, DEFAULT_ORDERABLE, ALL_OPERATORS);
58 }
59
60 protected ImmutableColumn( String name,
61 String type,
62 boolean fullTextSearchable,
63 boolean orderable,
64 Operator... operators ) {
65 this(name, type, fullTextSearchable, orderable,
66 operators != null && operators.length != 0 ? EnumSet.copyOf(Arrays.asList(operators)) : null);
67 }
68
69 protected ImmutableColumn( String name,
70 String type,
71 boolean fullTextSearchable,
72 boolean orderable,
73 Set<Operator> operators ) {
74 this.name = name;
75 this.type = type;
76 this.fullTextSearchable = fullTextSearchable;
77 this.orderable = orderable;
78 this.operators = operators == null || operators.isEmpty() ? ALL_OPERATORS : Collections.unmodifiableSet(EnumSet.copyOf(operators));
79 assert this.name != null;
80 assert this.type != null;
81 assert this.operators != null;
82 }
83
84
85
86
87
88
89 public String getName() {
90 return name;
91 }
92
93
94
95
96
97
98 public String getPropertyType() {
99 return type;
100 }
101
102
103
104
105
106
107 public boolean isFullTextSearchable() {
108 return fullTextSearchable;
109 }
110
111
112
113
114
115
116 public boolean isOrderable() {
117 return orderable;
118 }
119
120
121
122
123
124
125 public Set<Operator> getOperators() {
126 return operators;
127 }
128
129
130
131
132
133
134 @Override
135 public String toString() {
136 return this.name + "(" + type + ")";
137 }
138 }