Skip to content

Commit a0cc191

Browse files
authored
Merge pull request boskworks#170 from prdoyle/mucho-cleanup
Lots of minor cleanup
2 parents 5358a03 + 8c8f3d8 commit a0cc191

File tree

36 files changed

+107
-180
lines changed

36 files changed

+107
-180
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,6 @@ provide integrations with other technologies.
171171

172172
The subprojects are listed in [settings.gradle](settings.gradle), and each has its own `README.md` describing what it is.
173173

174-
### Gradle setup
175-
176-
Each project has its own `build.gradle`.
177-
Common settings across projects are in custom plugins under the [buildSrc directory](buildSrc/src/main/groovy).
178-
179174
### Versioning
180175

181176
In the long run, we'll use the usual semantic versioning.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.lang.reflect.Type;
55
import works.bosk.drivers.ForwardingDriver;
66
import works.bosk.exceptions.FlushFailureException;
7-
import works.bosk.exceptions.InitializationFailureException;
87
import works.bosk.exceptions.InvalidTypeException;
98

109
/**
@@ -43,8 +42,6 @@ public interface BoskDriver {
4342
* an initial root. Such a driver cannot be used on its own to initialize a Bosk,
4443
* but it can be used downstream of a {@link ForwardingDriver} provided there is
4544
* another downstream driver that can provide the initial root instead.
46-
*
47-
* @see InitializationFailureException
4845
*/
4946
StateTreeNode initialRoot(Type rootType) throws InvalidTypeException, IOException, InterruptedException;
5047

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: 13 additions & 6 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);
@@ -183,7 +183,7 @@ public Spliterator<E> spliterator() {
183183

184184
@Override
185185
public String toString() {
186-
return StreamSupport.stream(spliterator(), false).collect(toList()).toString();
186+
return StreamSupport.stream(spliterator(), false).toList().toString();
187187
}
188188
};
189189
}
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ public final Path then(String... segments) {
149149
* @throws MalformedPathException if <code>segments</code> contains an invalid path segment.
150150
*/
151151
public final Path then(List<String> segments) {
152-
if (segments.size() == 0) {
152+
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 + "\"");
@@ -372,7 +372,7 @@ public static boolean isParameterSegment(String segment) {
372372
}
373373

374374
public static boolean isValidParameterName(String name) {
375-
if (name.length() == 0) {
375+
if (name.isEmpty()) {
376376
return false;
377377
} else if (!isValidFirstCharacter(name.codePointAt(0))) {
378378
return false;

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,7 @@ public static Type parameterType(Type parameterizedType, Class<?> genericClass,
180180
// interfaces must have consistent types, so any occurrence of the
181181
// interface will serve.
182182
//
183-
Type supertype = actualClass.getGenericSuperclass();
184-
if (supertype == null || !genericClass.isAssignableFrom(rawClass(supertype))) {
185-
// Must come from interface inheritance
186-
supertype = null; // Help catch errors
187-
for (Type candidate: actualClass.getGenericInterfaces()) {
188-
if (genericClass.isAssignableFrom(rawClass(candidate))) {
189-
supertype = candidate;
190-
break;
191-
}
192-
}
193-
assert supertype != null: "If genericClass isAssignableFrom actualClass, and they're not equal, then it must be assignable from something actualClass inherits";
194-
}
183+
Type supertype = lowestCompatibleSupertype(genericClass, actualClass);
195184

196185
// Recurse with supertype
197186
Type returned = parameterType(supertype, genericClass, index);
@@ -203,6 +192,22 @@ public static Type parameterType(Type parameterizedType, Class<?> genericClass,
203192
}
204193
}
205194

195+
private static Type lowestCompatibleSupertype(Class<?> requiredSupertype, Class<?> givenClass) {
196+
Type supertype = givenClass.getGenericSuperclass();
197+
if (supertype == null || !requiredSupertype.isAssignableFrom(rawClass(supertype))) {
198+
// Must come from interface inheritance
199+
supertype = null; // Help catch errors
200+
for (Type candidate: givenClass.getGenericInterfaces()) {
201+
if (requiredSupertype.isAssignableFrom(rawClass(candidate))) {
202+
supertype = candidate;
203+
break;
204+
}
205+
}
206+
assert supertype != null: "If requiredSupertype isAssignableFrom givenClass, and they're not equal, then it must be assignable from something givenClass inherits";
207+
}
208+
return supertype;
209+
}
210+
206211
/**
207212
* @param typeWithVariables a {@link Type} that may or may not contain references to {@link TypeVariable}s.
208213
* @param environmentType the type that defines what those variables mean
@@ -244,10 +249,6 @@ public static Class<?> rawClass(Type sourceType) {
244249
}
245250
}
246251

247-
public static Type referenceTypeFor(Type targetType) {
248-
return Types.parameterizedType(Reference.class, targetType);
249-
}
250-
251252
public static Method getterMethod(Class<?> objectClass, String fieldName) throws InvalidTypeException {
252253
String methodName = fieldName; // fluent
253254
for (Class<?> c = objectClass; c != Object.class; c = c.getSuperclass()) {
@@ -283,7 +284,7 @@ public static <T> Constructor<T> theOnlyConstructorFor(Class<T> nodeClass) {
283284
throw new IllegalArgumentException("Ambiguous constructor list for " + nodeClass.getSimpleName() + ": " + constructors);
284285
}
285286
@SuppressWarnings("unchecked")
286-
Constructor<T> theConstructor = (Constructor<T>) constructors.get(0);
287+
Constructor<T> theConstructor = (Constructor<T>) constructors.getFirst();
287288
return theConstructor;
288289
}
289290

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-core/src/main/java/works/bosk/exceptions/InitializationFailureException.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

bosk-core/src/main/java/works/bosk/exceptions/TunneledCheckedException.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

bosk-core/src/main/java/works/bosk/util/Classes.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import works.bosk.SideTableReference;
1414
import works.bosk.TaggedUnion;
1515
import works.bosk.VariantCase;
16-
import works.bosk.exceptions.InvalidTypeException;
1716

1817
/**
1918
* An imperfect, non-idiomatic way to describe complex parameterized types.
@@ -64,7 +63,7 @@ public static <V> Class<MapValue<V>> mapValue(Class<V> valueClass) {
6463
return (Class)MapValue.class;
6564
}
6665

67-
public static <V extends VariantCase> Class<TaggedUnion<V>> taggedUnion(Class<V> variantCaseClass, String... segments) throws InvalidTypeException {
66+
public static <V extends VariantCase> Class<TaggedUnion<V>> taggedUnion(Class<V> variantCaseClass, String... segments) {
6867
return (Class)TaggedUnion.class;
6968
}
7069
}

0 commit comments

Comments
 (0)