1   /*
2    * Copyright 2017 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package com.linecorp.centraldogma.common;
18  
19  import static com.linecorp.centraldogma.internal.Util.validateFilePath;
20  import static java.util.Objects.requireNonNull;
21  
22  import java.util.Collections;
23  import java.util.List;
24  
25  import com.google.common.base.MoreObjects;
26  
27  final class IdentityQuery<T> implements Query<T> {
28  
29      private final String path;
30      private final QueryType queryType;
31  
32      IdentityQuery(String path, QueryType queryType) {
33          this.path = validateFilePath(path, "path");
34          this.queryType = requireNonNull(queryType, "queryType");
35      }
36  
37      @Override
38      public String path() {
39          return path;
40      }
41  
42      @Override
43      public QueryType type() {
44          return queryType;
45      }
46  
47      @Override
48      public List<String> expressions() {
49          return Collections.emptyList();
50      }
51  
52      @Override
53      public T apply(T input) {
54          return requireNonNull(input, "input");
55      }
56  
57      @Override
58      public int hashCode() {
59          return path.hashCode();
60      }
61  
62      @Override
63      public boolean equals(Object obj) {
64          if (!(obj instanceof IdentityQuery)) {
65              return false;
66          }
67  
68          if (this == obj) {
69              return true;
70          }
71  
72          final IdentityQuery<?> that = (IdentityQuery<?>) obj;
73  
74          return path().equals(that.path());
75      }
76  
77      @Override
78      public String toString() {
79          return MoreObjects.toStringHelper(this)
80                            .add("path", path)
81                            .add("queryType", queryType)
82                            .toString();
83      }
84  }