Skip to content

Commit d02cd3b

Browse files
committed
Various minor cleanups
1 parent fc661fe commit d02cd3b

File tree

9 files changed

+25
-26
lines changed

9 files changed

+25
-26
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package works.bosk;
22

3-
import java.util.ArrayList;
43
import java.util.Collection;
54
import java.util.Iterator;
65
import java.util.LinkedHashMap;
@@ -14,7 +13,6 @@
1413

1514
import static java.util.Arrays.asList;
1615
import static java.util.Collections.unmodifiableCollection;
17-
import static java.util.Collections.unmodifiableList;
1816
import static java.util.Collections.unmodifiableMap;
1917
import static java.util.LinkedHashMap.newLinkedHashMap;
2018
import static java.util.Objects.requireNonNull;
@@ -52,7 +50,7 @@ public E get(Identifier key) {
5250

5351
@Override
5452
public List<Identifier> ids() {
55-
return unmodifiableList(new ArrayList<>(contents.keySet()));
53+
return List.copyOf(contents.keySet());
5654
}
5755

5856
/**

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Listing<E> withoutEntity(E entity) {
120120
@Override
121121
public Iterator<Reference<E>> iterator() {
122122
Iterator<Identifier> idIter = ids.iterator();
123-
return new Iterator<Reference<E>>() {
123+
return new Iterator<>() {
124124
@Override
125125
public boolean hasNext() {
126126
return idIter.hasNext();
@@ -170,7 +170,7 @@ public Iterable<E> values() {
170170
// we know a Listing qualifies for Spliterator.IMMUTABLE. And let's give
171171
// a nice toString too, for debugging.
172172
AddressableByIdentifier<E> domain = this.domain.value();
173-
return new Iterable<E>() {
173+
return new Iterable<>() {
174174
@Override
175175
public Iterator<E> iterator() {
176176
return valueIteratorImpl(domain);
@@ -248,9 +248,16 @@ public Listing<E> filteredBy(Listing<E> other) {
248248

249249
private Iterator<E> valueIteratorImpl(AddressableByIdentifier<E> domain) {
250250
Iterator<Identifier> iter = ids.iterator();
251-
return new Iterator<E>() {
252-
@Override public boolean hasNext() { return iter.hasNext(); }
253-
@Override public E next() { return getOrThrow(domain, iter.next()); }
251+
return new Iterator<>() {
252+
@Override
253+
public boolean hasNext() {
254+
return iter.hasNext();
255+
}
256+
257+
@Override
258+
public E next() {
259+
return getOrThrow(domain, iter.next());
260+
}
254261
};
255262
}
256263

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public final Path then(List<String> segments) {
152152
if (segments.isEmpty()) {
153153
return this;
154154
} else {
155-
String firstSegment = validSegment(segments.get(0));
155+
String firstSegment = validSegment(segments.getFirst());
156156
if (isParameterSegment(firstSegment)) {
157157
if (segmentStream().anyMatch(firstSegment::equals)) {
158158
throw new MalformedPathException("Duplicate path parameter \"" + firstSegment + "\"");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public static <T> Constructor<T> theOnlyConstructorFor(Class<T> nodeClass) {
284284
throw new IllegalArgumentException("Ambiguous constructor list for " + nodeClass.getSimpleName() + ": " + constructors);
285285
}
286286
@SuppressWarnings("unchecked")
287-
Constructor<T> theConstructor = (Constructor<T>) constructors.get(0);
287+
Constructor<T> theConstructor = (Constructor<T>) constructors.getFirst();
288288
return theConstructor;
289289
}
290290

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package works.bosk;
22

33
import java.util.AbstractMap.SimpleImmutableEntry;
4-
import java.util.ArrayList;
54
import java.util.Collection;
65
import java.util.LinkedHashMap;
76
import java.util.List;
@@ -21,7 +20,6 @@
2120
import org.pcollections.OrderedPMap;
2221
import org.pcollections.OrderedPSet;
2322

24-
import static java.util.Collections.unmodifiableList;
2523
import static java.util.Objects.requireNonNull;
2624

2725
@EqualsAndHashCode
@@ -39,7 +37,7 @@ public final class SideTable<K extends Entity, V> implements EnumerableByIdentif
3937

4038
public boolean isEmpty() { return valuesById.isEmpty(); }
4139
public int size() { return valuesById.size(); }
42-
public List<Identifier> ids() { return unmodifiableList(new ArrayList<>(valuesById.keySet())); }
40+
public List<Identifier> ids() { return List.copyOf(valuesById.keySet()); }
4341
public Listing<K> keys() { return new Listing<>(domain, OrderedPSet.from(valuesById.keySet())); }
4442
public Collection<V> values() { return valuesById.values(); }
4543
public Set<Entry<Identifier, V>> idEntrySet() { return valuesById.entrySet(); }

bosk-mongo/src/main/java/works/bosk/drivers/mongo/internal/BsonSurgeon.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public BsonDocument gather(List<BsonDocument> partsList) {
224224

225225
Set<BsonString> alreadySeen = new HashSet<>();
226226

227-
BsonDocument rootRecipe = partsList.get(0);
227+
BsonDocument rootRecipe = partsList.getFirst();
228228
List<String> prefix = bsonPathSegments(rootRecipe.getString(BSON_PATH_FIELD));
229229

230230
BsonDocument whole = rootRecipe.getDocument(STATE_FIELD);
@@ -237,7 +237,7 @@ public BsonDocument gather(List<BsonDocument> partsList) {
237237
if (!bsonSegments.subList(0, prefix.size()).equals(prefix)) {
238238
throw new IllegalArgumentException("Part doc is not contained within the root doc. Part: " + bsonSegments + " Root:" + prefix);
239239
}
240-
String key = bsonSegments.get(bsonSegments.size()-1);
240+
String key = bsonSegments.getLast();
241241
BsonValue value = requireNonNull(entry.get(STATE_FIELD));
242242

243243
BsonDocument container = lookup(whole, bsonSegments.subList(prefix.size(), bsonSegments.size() - 1));

bosk-mongo/src/main/java/works/bosk/drivers/mongo/internal/PandoFormatDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ BsonState loadBsonState() throws UninitializedCollectionException {
203203
} catch (NoSuchElementException e) {
204204
throw new UninitializedCollectionException("No existing document", e);
205205
}
206-
BsonDocument mainPart = allParts.get(allParts.size()-1);
206+
BsonDocument mainPart = allParts.getLast();
207207
if (!ROOT_DOCUMENT_ID.equals(mainPart.get("_id"))) {
208208
throw new IllegalStateException("Cannot locate root document");
209209
}
@@ -288,7 +288,7 @@ private boolean isFinalEventOfTransaction(ChangeStreamDocument<BsonDocument> eve
288288
}
289289

290290
private void processTransaction(List<ChangeStreamDocument<BsonDocument>> events) throws UnprocessableEventException {
291-
ChangeStreamDocument<BsonDocument> finalEvent = events.get(events.size() - 1);
291+
ChangeStreamDocument<BsonDocument> finalEvent = events.getLast();
292292
switch (finalEvent.getOperationType()) {
293293
case INSERT: case REPLACE: {
294294
BsonDocument fullDocument = finalEvent.getFullDocument();

bosk-mongo/src/main/java/works/bosk/drivers/mongo/status/BsonComparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public Difference difference(BsonValue expected, BsonValue actual) {
1818
var differences = findSomeDifferences(expectedDoc, actualDoc);
1919
return switch (differences.size()) {
2020
case 0 -> new NoDifference();
21-
case 1 -> differences.get(0);
21+
case 1 -> differences.getFirst();
2222
default -> {
2323
// To prevent exponential fan-out, permit only max one compound inside another compound
2424
int numCompounds = 0;

bosk-testing/src/main/java/works/bosk/testing/junit/ParametersByNameContextProvider.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private List<String> allParameterNames(ExtensionContext context) {
8282
case 0:
8383
break;
8484
case 1:
85-
Collections.addAll(parameters, annotatedConstructors.get(0).getParameters());
85+
Collections.addAll(parameters, annotatedConstructors.getFirst().getParameters());
8686
break;
8787
default:
8888
throw new ParameterResolutionException("Multiple constructors annotated with " + ParametersByName.class.getSimpleName() + ": " + annotatedConstructors);
@@ -121,13 +121,9 @@ private Stream<?> invokeCorrespondingMethod(String name, Class<?> testClass) {
121121
return result;
122122
}
123123

124-
private static class ParameterBinder implements ParameterResolver {
125-
private final Map<String, ?> binding;
126-
127-
public ParameterBinder(Map<String, ?> binding) {
128-
this.binding = binding;
129-
}
130-
124+
private record ParameterBinder(
125+
Map<String, ?> binding
126+
) implements ParameterResolver {
131127
@Override
132128
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
133129
return binding.containsKey(parameterContext.getParameter().getName());

0 commit comments

Comments
 (0)