View Javadoc
1   /*
2    * #%L
3    * MiscellaneousOperator.java - mongodb-async-driver - Allanbank Consulting, Inc.
4    * %%
5    * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  
21  package com.allanbank.mongodb.builder;
22  
23  import com.allanbank.mongodb.Version;
24  
25  /**
26   * MiscellaneousOperator provides the set of miscellaneous operators.
27   * 
28   * @api.yes This enumeration is part of the driver's API. Public and protected
29   *          members will be deprecated for at least 1 non-bugfix release
30   *          (version numbers are <major>.<minor>.<bugfix>)
31   *          before being removed or modified.
32   * @copyright 2012-2013, Allanbank Consulting, Inc., All Rights Reserved
33   */
34  public enum MiscellaneousOperator implements Operator {
35      /**
36       * Operator to ensure that all values provided in the operand existing in
37       * the array field.
38       */
39      ALL("$all"),
40  
41      /**
42       * A pseudo-operator to add a comment to a query.
43       * 
44       * @since MongoDB 2.2
45       */
46      COMMENT("$comment", Version.VERSION_2_2),
47  
48      /** Provides the ability to match an entire array element at once. */
49      ELEMENT_MATCH("$elemMatch"),
50  
51      /** Check to see if a field exists or not. */
52      EXISTS("$exists"),
53  
54      /** Checks if a value for a field is present in the operand array. */
55      IN("$in"),
56  
57      /**
58       * Performs a modulo operation on a field and is equivalent to the where
59       * statement <code>field % d == m</code>.
60       */
61      MOD("$mod"),
62  
63      /** Checks if a value for a field is not present in the operand array. */
64      NIN("$nin"),
65  
66      /** Test if a field matches a specified regular expression. */
67      REG_EX("$regex"),
68  
69      /** Compares the length of the array field. */
70      SIZE("$size"),
71  
72      /**
73       * Support for text searches.
74       * 
75       * @since MongoDB 2.6
76       */
77      TEXT("$text", Version.VERSION_2_6),
78  
79      /** Check if a value's type matches the expected type. */
80      TYPE("$type"),
81  
82      /** Support for an ad-hoc JavaScript expression. */
83      WHERE("$where");
84  
85      /**
86       * The modifier for the {@link #TEXT} operator to specify the language of
87       * the query terms.
88       * 
89       * @since MongoDB 2.6
90       */
91      public static final String LANGUAGE_MODIFIER = "$language";
92  
93      /**
94       * The modifier for the {@link #TEXT} operator to specify the the query
95       * terms.
96       * 
97       * @since MongoDB 2.6
98       */
99      public static final String SEARCH_MODIFIER = "$search";
100 
101     /** The operator's token to use when sending to the server. */
102     private final String myToken;
103 
104     /** The first MongoDB version to support the operator. */
105     private final Version myVersion;
106 
107     /**
108      * Creates a new MiscellaneousOperator.
109      * 
110      * @param token
111      *            The token to use when sending to the server.
112      */
113     private MiscellaneousOperator(final String token) {
114         this(token, null);
115     }
116 
117     /**
118      * Creates a new MiscellaneousOperator.
119      * 
120      * @param token
121      *            The token to use when sending to the server.
122      * @param version
123      *            The first MongoDB version to support the operator.
124      */
125     private MiscellaneousOperator(final String token, final Version version) {
126         myToken = token;
127         myVersion = version;
128     }
129 
130     /**
131      * The token for the operator that can be sent to the server.
132      * 
133      * @return The token for the operator.
134      */
135     @Override
136     public String getToken() {
137         return myToken;
138     }
139 
140     /**
141      * Returns the first MongoDB version to support the operator.
142      * 
143      * @return The first MongoDB version to support the operator. If
144      *         <code>null</code> then the version is not known and can be
145      *         assumed to be all currently supported versions.
146      */
147     @Override
148     public Version getVersion() {
149         return myVersion;
150     }
151 
152 }