View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.sql.parser.sql.common.enums;
19  
20  import lombok.Getter;
21  import lombok.RequiredArgsConstructor;
22  
23  import java.util.Collection;
24  import java.util.EnumSet;
25  
26  /**
27   * Direction type enum.
28   */
29  @RequiredArgsConstructor
30  @Getter
31  public enum DirectionType {
32      
33      NEXT("NEXT"),
34      
35      PRIOR("PRIOR"),
36      
37      FIRST("FIRST"),
38      
39      LAST("LAST"),
40      
41      ABSOLUTE_COUNT("ABSOLUTE"),
42      
43      RELATIVE_COUNT("RELATIVE"),
44      
45      COUNT(""),
46      
47      ALL("ALL"),
48      
49      FORWARD("FORWARD"),
50      
51      FORWARD_COUNT("FORWARD"),
52      
53      FORWARD_ALL("FORWARD ALL"),
54      
55      BACKWARD("BACKWARD"),
56      
57      BACKWARD_COUNT("BACKWARD"),
58      
59      BACKWARD_ALL("BACKWARD ALL");
60      
61      private static final Collection<DirectionType> ALL_DIRECTION_TYPES = EnumSet.of(ALL, FORWARD_ALL, BACKWARD_ALL);
62      
63      private static final Collection<DirectionType> FORWARD_COUNT_DIRECTION_TYPES = EnumSet.of(DirectionType.NEXT, DirectionType.COUNT, DirectionType.FORWARD, DirectionType.FORWARD_COUNT);
64      
65      private static final Collection<DirectionType> BACKWARD_COUNT_DIRECTION_TYPES = EnumSet.of(DirectionType.PRIOR, DirectionType.BACKWARD, DirectionType.BACKWARD_COUNT);
66      
67      private final String name;
68      
69      /**
70       * Is all direction type.
71       * 
72       * @param directionType direction type
73       * @return is all direction type or not
74       */
75      public static boolean isAllDirectionType(final DirectionType directionType) {
76          return ALL_DIRECTION_TYPES.contains(directionType);
77      }
78      
79      /**
80       * Is forward count direction type.
81       *
82       * @param directionType direction type
83       * @return is forward count direction type or not
84       */
85      public static boolean isForwardCountDirectionType(final DirectionType directionType) {
86          return FORWARD_COUNT_DIRECTION_TYPES.contains(directionType);
87      }
88      
89      /**
90       * Is backward count direction type.
91       *
92       * @param directionType direction type
93       * @return is backward count direction type or not
94       */
95      public static boolean isBackwardCountDirectionType(final DirectionType directionType) {
96          return BACKWARD_COUNT_DIRECTION_TYPES.contains(directionType);
97      }
98  }