View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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       * {@inheritDoc}
86       * 
87       * @see org.modeshape.graph.query.validate.Schemata.Column#getName()
88       */
89      public String getName() {
90          return name;
91      }
92  
93      /**
94       * {@inheritDoc}
95       * 
96       * @see org.modeshape.graph.query.validate.Schemata.Column#getPropertyType()
97       */
98      public String getPropertyType() {
99          return type;
100     }
101 
102     /**
103      * {@inheritDoc}
104      * 
105      * @see org.modeshape.graph.query.validate.Schemata.Column#isFullTextSearchable()
106      */
107     public boolean isFullTextSearchable() {
108         return fullTextSearchable;
109     }
110 
111     /**
112      * {@inheritDoc}
113      * 
114      * @see org.modeshape.graph.query.validate.Schemata.Column#isOrderable()
115      */
116     public boolean isOrderable() {
117         return orderable;
118     }
119 
120     /**
121      * {@inheritDoc}
122      * 
123      * @see org.modeshape.graph.query.validate.Schemata.Column#getOperators()
124      */
125     public Set<Operator> getOperators() {
126         return operators;
127     }
128 
129     /**
130      * {@inheritDoc}
131      * 
132      * @see java.lang.Object#toString()
133      */
134     @Override
135     public String toString() {
136         return this.name + "(" + type + ")";
137     }
138 }