1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.search.api.request;
20
21 import java.time.Instant;
22 import java.util.Map;
23 import java.util.Objects;
24
25 import static java.util.Objects.requireNonNull;
26
27
28
29
30 public abstract class Field {
31 private final String fieldName;
32
33 private Field(String fieldName) {
34 this.fieldName = requireNonNull(fieldName);
35 }
36
37
38
39
40 public String getFieldName() {
41 return fieldName;
42 }
43
44
45
46
47
48 public abstract Object getFieldValue(Map<Field, Object> record);
49
50 @Override
51 public boolean equals(Object o) {
52 if (this == o) {
53 return true;
54 }
55 if (o == null || getClass() != o.getClass()) {
56 return false;
57 }
58 Field fieldName1 = (Field) o;
59 return Objects.equals(getFieldName(), fieldName1.getFieldName());
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(getFieldName());
65 }
66
67 @Override
68 public String toString() {
69 return fieldName;
70 }
71
72 public static class StringField extends Field {
73 public StringField(String fieldName) {
74 super(fieldName);
75 }
76
77 @Override
78 public String getFieldValue(Map<Field, Object> record) {
79 return (String) record.get(this);
80 }
81 }
82
83 public static class NumberField extends Field {
84 public NumberField(String fieldName) {
85 super(fieldName);
86 }
87
88 @Override
89 public Number getFieldValue(Map<Field, Object> record) {
90 return (Number) record.get(this);
91 }
92 }
93
94 public static class BooleanField extends Field {
95 public BooleanField(String fieldName) {
96 super(fieldName);
97 }
98
99 @Override
100 public Boolean getFieldValue(Map<Field, Object> record) {
101 return (Boolean) record.get(this);
102 }
103 }
104
105
106
107
108 public static class InstantField extends Field {
109 public InstantField(String fieldName) {
110 super(fieldName);
111 }
112
113 public Instant getFieldValue(Map<Field, Object> record) {
114 return (Instant) record.get(this);
115 }
116 }
117 }