1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }