Skip to content

Commit 93d26dd

Browse files
committed
Reduce lombok more.
We're pretty close to no lombok in the library (only in tests). The stumbling blocks are: - @DeleGate for the Reference subtypes - @value for the PathCompiler.Step subtypes (because they're inner classes)
1 parent ff2cf7d commit 93d26dd

File tree

14 files changed

+433
-187
lines changed

14 files changed

+433
-187
lines changed

bosk-core/src/main/java/works/bosk/BindingEnvironment.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import java.util.LinkedHashMap;
44
import java.util.Map;
5+
import java.util.Objects;
56
import java.util.function.BiConsumer;
6-
import lombok.EqualsAndHashCode;
7-
import lombok.RequiredArgsConstructor;
87
import works.bosk.exceptions.ParameterAlreadyBoundException;
98
import works.bosk.exceptions.ParameterUnboundException;
109

1110
import static java.util.Collections.emptyMap;
1211
import static java.util.Collections.singletonMap;
1312
import static java.util.Collections.unmodifiableMap;
14-
import static lombok.AccessLevel.PRIVATE;
1513
import static works.bosk.Path.isValidParameterName;
1614
import static works.bosk.Path.parameterNameFromSegment;
1715

@@ -20,8 +18,6 @@
2018
* Used to supply or extract values for parameters in a parameterized {@link Path}
2119
* or {@link Reference}.
2220
*/
23-
@RequiredArgsConstructor(access = PRIVATE)
24-
@EqualsAndHashCode
2521
public final class BindingEnvironment {
2622
/**
2723
* This should use an ordered map, like LinkedHashMap, because in some contexts,
@@ -30,6 +26,10 @@ public final class BindingEnvironment {
3026
*/
3127
private final Map<String, Identifier> bindings;
3228

29+
private BindingEnvironment(Map<String, Identifier> bindings) {
30+
this.bindings = bindings;
31+
}
32+
3333
/**
3434
* @return an environment with no names bound
3535
*/
@@ -39,7 +39,7 @@ public static BindingEnvironment empty() {
3939

4040
/**
4141
* @return an environment with the given <code>name</code> bound to the given <code>value</code>,
42-
* and no other names bound
42+
* and no other names bound
4343
* @throws IllegalArgumentException if the given name is not a valid parameter name
4444
*/
4545
public static BindingEnvironment singleton(String name, Identifier value) {
@@ -68,9 +68,9 @@ public BindingEnvironment overlay(BindingEnvironment other) {
6868

6969
/**
7070
* @param name (without the surrounding hyphens)
71-
* @throws ParameterUnboundException if the name is not bound
72-
* @throws IllegalArgumentException if the name is not valid
7371
* @return The value bound to the given <code>name</code>
72+
* @throws ParameterUnboundException if the name is not bound
73+
* @throws IllegalArgumentException if the name is not valid
7474
*/
7575
public Identifier get(String name) {
7676
Identifier result = bindings.get(validParameterName(name));
@@ -135,6 +135,7 @@ public static Builder empty() {
135135

136136
/**
137137
* Binds <code>name</code> to <code>value</code>.
138+
*
138139
* @return <code>this</code>
139140
* @throws ParameterAlreadyBoundException if <code>name</code> has a binding.
140141
*/
@@ -149,6 +150,7 @@ public Builder bind(String name, Identifier value) {
149150

150151
/**
151152
* Binds <code>name</code> to <code>value</code> regardless of whether <code>name</code> is already bound.
153+
*
152154
* @return <code>this</code>
153155
*/
154156
public Builder rebind(String name, Identifier value) {
@@ -158,6 +160,7 @@ public Builder rebind(String name, Identifier value) {
158160

159161
/**
160162
* Causes the given name to be unbound in this environment.
163+
*
161164
* @return <code>this</code>
162165
*/
163166
public Builder unbind(String name) {
@@ -167,6 +170,7 @@ public Builder unbind(String name) {
167170

168171
/**
169172
* Can be called more than once.
173+
*
170174
* @return a {@link BindingEnvironment} with the desired contents
171175
*/
172176
public BindingEnvironment build() {
@@ -180,5 +184,19 @@ public String toString() {
180184
return bindings.toString();
181185
}
182186

187+
@Override
188+
public boolean equals(Object o) {
189+
if (o == null || getClass() != o.getClass()) {
190+
return false;
191+
}
192+
BindingEnvironment that = (BindingEnvironment) o;
193+
return Objects.equals(bindings, that.bindings);
194+
}
195+
196+
@Override
197+
public int hashCode() {
198+
return Objects.hashCode(bindings);
199+
}
200+
183201
private static final BindingEnvironment EMPTY_ENVIRONMENT = new BindingEnvironment(emptyMap());
184202
}

bosk-core/src/main/java/works/bosk/Catalog.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
import java.util.LinkedHashMap;
66
import java.util.List;
77
import java.util.Map;
8+
import java.util.Objects;
89
import java.util.Spliterator;
910
import java.util.stream.Stream;
10-
import lombok.EqualsAndHashCode;
11-
import lombok.RequiredArgsConstructor;
1211
import org.pcollections.OrderedPMap;
1312

1413
import static java.util.Arrays.asList;
1514
import static java.util.Collections.unmodifiableCollection;
1615
import static java.util.Collections.unmodifiableMap;
1716
import static java.util.LinkedHashMap.newLinkedHashMap;
1817
import static java.util.Objects.requireNonNull;
19-
import static lombok.AccessLevel.PRIVATE;
2018

2119
/**
2220
* An ordered collection of entities included by value. Mainly useful to represent
@@ -34,14 +32,20 @@
3432
* @author pdoyle
3533
*
3634
*/
37-
@RequiredArgsConstructor(access=PRIVATE)
38-
@EqualsAndHashCode
3935
public final class Catalog<E extends Entity> implements Iterable<E>, EnumerableByIdentifier<E> {
4036
private final OrderedPMap<Identifier, E> contents;
4137

42-
public int size() { return contents.size(); }
38+
private Catalog(OrderedPMap<Identifier, E> contents) {
39+
this.contents = contents;
40+
}
4341

44-
public boolean isEmpty() { return contents.isEmpty(); }
42+
public int size() {
43+
return contents.size();
44+
}
45+
46+
public boolean isEmpty() {
47+
return contents.isEmpty();
48+
}
4549

4650
@Override
4751
public E get(Identifier key) {
@@ -98,7 +102,7 @@ public boolean containsAllIDs(Stream<Identifier> keys) {
98102
}
99103

100104
public boolean containsAllIDs(Iterable<Identifier> keys) {
101-
for (Identifier key: keys) {
105+
for (Identifier key : keys) {
102106
if (!containsID(key)) {
103107
return false;
104108
}
@@ -115,7 +119,7 @@ public boolean containsAll(Stream<E> entities) {
115119
}
116120

117121
public boolean containsAll(Iterable<E> entities) {
118-
for (E entity: entities) {
122+
for (E entity : entities) {
119123
if (!contains(entity)) {
120124
return false;
121125
}
@@ -139,7 +143,7 @@ public static <TT extends Entity> Catalog<TT> of(Stream<TT> entities) {
139143

140144
public static <TT extends Entity> Catalog<TT> of(Collection<TT> entities) {
141145
Map<Identifier, TT> newValues = newLinkedHashMap(entities.size());
142-
for (TT entity: entities) {
146+
for (TT entity : entities) {
143147
TT old = newValues.put(requireNonNull(entity.id()), entity);
144148
if (old != null) {
145149
throw new IllegalArgumentException("Multiple entities with id " + old.id());
@@ -171,4 +175,17 @@ public String toString() {
171175
return contents.toString();
172176
}
173177

178+
@Override
179+
public boolean equals(Object o) {
180+
if (o == null || getClass() != o.getClass()) {
181+
return false;
182+
}
183+
Catalog<?> catalog = (Catalog<?>) o;
184+
return Objects.equals(contents, catalog.contents);
185+
}
186+
187+
@Override
188+
public int hashCode() {
189+
return Objects.hashCode(contents);
190+
}
174191
}

bosk-core/src/main/java/works/bosk/Identifier.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package works.bosk;
22

3-
import lombok.AccessLevel;
4-
import lombok.EqualsAndHashCode;
5-
import lombok.RequiredArgsConstructor;
3+
import java.util.Objects;
64
import org.jetbrains.annotations.NotNull;
75

86
/**
97
* The means by which {@link Entity entities} are identified within
108
* a particular domain, such as a {@link Catalog} or {@link SideTable}.
119
*/
12-
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
13-
@EqualsAndHashCode
1410
public final class Identifier {
15-
@NotNull final String value;
11+
@NotNull
12+
final String value;
13+
14+
private Identifier(@NotNull String value) {
15+
this.value = value;
16+
}
1617

1718
// TODO: Intern these. No need to have several Identifier objects for the same value
1819
public static Identifier from(String value) {
@@ -35,5 +36,22 @@ public static synchronized Identifier unique(String prefix) {
3536

3637
private static long uniqueIdCounter = 1000;
3738

38-
@Override public String toString() { return value; }
39+
@Override
40+
public String toString() {
41+
return value;
42+
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (o == null || getClass() != o.getClass()) {
47+
return false;
48+
}
49+
Identifier that = (Identifier) o;
50+
return Objects.equals(value, that.value);
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hashCode(value);
56+
}
3957
}

bosk-core/src/main/java/works/bosk/ListValue.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import java.util.List;
88
import java.util.function.Function;
99
import java.util.stream.Collector;
10-
import lombok.AccessLevel;
11-
import lombok.RequiredArgsConstructor;
1210

1311
/**
1412
* An immutable {@link List} that can be used in a {@link Bosk}.
@@ -37,11 +35,14 @@
3735
*
3836
* @author pdoyle
3937
*/
40-
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
4138
public class ListValue<T> extends AbstractList<T> {
4239
protected final T[] entries;
4340

44-
@SuppressWarnings({ "unchecked" })
41+
protected ListValue(T[] entries) {
42+
this.entries = entries;
43+
}
44+
45+
@SuppressWarnings({"unchecked"})
4546
public static <TT> ListValue<TT> empty() {
4647
return EMPTY;
4748
}
@@ -62,7 +63,7 @@ public static <TT> ListValue<TT> from(Collection<TT> entries) {
6263
if (entries.isEmpty()) {
6364
return empty();
6465
} else {
65-
return new ListValue<>((TT[])entries.toArray());
66+
return new ListValue<>((TT[]) entries.toArray());
6667
}
6768
}
6869

@@ -114,10 +115,10 @@ public int hashCode() {
114115
Collector<TT, ?, ListValue<TT>> toListValue() {
115116
Function<List<TT>, ListValue<TT>> finisher = ListValue::from;
116117
return Collector.of(
117-
ArrayList::new,
118-
List::add,
119-
(left, right) -> { left.addAll(right); return left; },
120-
finisher);
118+
ArrayList::new,
119+
List::add,
120+
(left, right) -> { left.addAll(right); return left; },
121+
finisher);
121122
}
122123

123124
@SuppressWarnings("rawtypes")

bosk-core/src/main/java/works/bosk/Listing.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
import java.util.LinkedHashMap;
99
import java.util.List;
1010
import java.util.Map;
11+
import java.util.Objects;
1112
import java.util.Spliterator;
1213
import java.util.function.Consumer;
1314
import java.util.stream.Stream;
1415
import java.util.stream.StreamSupport;
15-
import lombok.AccessLevel;
16-
import lombok.EqualsAndHashCode;
17-
import lombok.RequiredArgsConstructor;
1816
import org.pcollections.OrderedPSet;
1917
import works.bosk.exceptions.NonexistentReferenceException;
2018

@@ -27,16 +25,32 @@
2725
* An immutable ordered collection of references to {@link Entity entities}
2826
* housed in a particular {@link #domain} {@link Catalog}.
2927
*
30-
* @author pdoyle
31-
*
3228
* @param <E> the type of {@link Entity} to which this listing's entries refer.
29+
* @author pdoyle
3330
*/
34-
@EqualsAndHashCode(callSuper = false)
35-
@RequiredArgsConstructor(access=AccessLevel.PACKAGE)
3631
public final class Listing<E extends Entity> extends AbstractCollection<Reference<E>> {
3732
private final CatalogReference<E> domain;
3833
private final OrderedPSet<Identifier> ids;
3934

35+
Listing(CatalogReference<E> domain, OrderedPSet<Identifier> ids) {
36+
this.domain = domain;
37+
this.ids = ids;
38+
}
39+
40+
@Override
41+
public boolean equals(Object o) {
42+
if (o == null || getClass() != o.getClass()) {
43+
return false;
44+
}
45+
Listing<?> listing = (Listing<?>) o;
46+
return Objects.equals(domain, listing.domain) && Objects.equals(ids, listing.ids);
47+
}
48+
49+
@Override
50+
public int hashCode() {
51+
return Objects.hash(domain, ids);
52+
}
53+
4054
/**
4155
* The {@link Catalog} in which all the {@link #ids()} reside.
4256
*/
@@ -202,7 +216,7 @@ public List<E> valueList() {
202216

203217
public Map<Identifier, E> valueMap() {
204218
Map<Identifier, E> result = new LinkedHashMap<>();
205-
for (Identifier id: ids) {
219+
for (Identifier id : ids) {
206220
result.put(id, getOrThrow(domain.value(), id));
207221
}
208222
return unmodifiableMap(result);
@@ -216,7 +230,7 @@ public static <TT extends Entity> Listing<TT> empty(Reference<Catalog<TT>> domai
216230
return new Listing<>(CatalogReference.from(domain), OrderedPSet.empty());
217231
}
218232

219-
public static <TT extends Entity> Listing<TT> of(Reference<Catalog<TT>> domain, Identifier...ids) {
233+
public static <TT extends Entity> Listing<TT> of(Reference<Catalog<TT>> domain, Identifier... ids) {
220234
return of(domain, Arrays.asList(ids));
221235
}
222236

@@ -280,11 +294,15 @@ public E next() {
280294
*
281295
* @author pdoyle
282296
*/
283-
@RequiredArgsConstructor
284297
private final class DomainLookupSpliterator implements Spliterator<E> {
285298
private final Spliterator<Identifier> idSpliterator;
286299
private final AddressableByIdentifier<E> domain;
287300

301+
public DomainLookupSpliterator(Spliterator<Identifier> idSpliterator, AddressableByIdentifier<E> domain) {
302+
this.idSpliterator = idSpliterator;
303+
this.domain = domain;
304+
}
305+
288306
@Override
289307
public boolean tryAdvance(Consumer<? super E> action) {
290308
return idSpliterator.tryAdvance(id -> action.accept(getOrThrow(domain, id)));

0 commit comments

Comments
 (0)