Skip to content

Commit

Permalink
use star imports everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Aug 18, 2024
1 parent 9785c69 commit 8eaabaa
Show file tree
Hide file tree
Showing 65 changed files with 711 additions and 695 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/comroid/annotations/AnnotatedTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
interface Extension {
default Wrap<AnnotatedElement> element() {
return Wrap.of(ReflectionHelper.fieldWithAnnotation(getClass(), AnnotatedTarget.class)
.stream()
.filter(fld -> AnnotatedElement.class.isAssignableFrom(fld.getType()))
.findAny()
.map(ThrowingFunction.sneaky(fld -> fld.get(this))))
.stream()
.filter(fld -> AnnotatedElement.class.isAssignableFrom(fld.getType()))
.findAny()
.map(ThrowingFunction.sneaky(fld -> fld.get(this))))
.castRef();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/comroid/annotations/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public int order() {
}

@Override
public boolean equals(Object o) {
return o instanceof Category c && hashCode() == c.value().hashCode();
public int hashCode() {
return getName().hashCode();
}

@Override
public int hashCode() {
return getName().hashCode();
public boolean equals(Object o) {
return o instanceof Category c && hashCode() == c.value().hashCode();
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/comroid/annotations/Description.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
enum Mode implements IntegerAttribute {Usage, Lines, Steps}

@Retention(RetentionPolicy.RUNTIME)
@Inherit(Inherit.Type.FromSupertype) @interface Config {
@Inherit(Inherit.Type.FromSupertype)
@interface Config {
Description[] value();
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/comroid/annotations/Ignore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
* Useful for explicitly including Ignored members
*/
@org.comroid.annotations.internal.Inherit(org.comroid.annotations.internal.Inherit.Type.FromParent)
@Retention(RetentionPolicy.RUNTIME) @interface Inherit {
@Retention(RetentionPolicy.RUNTIME)
@interface Inherit {
/**
* @return on which annotation processing to ignore the ancestors
*/
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/comroid/annotations/Localize.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
String value() default "";

@Retention(RetentionPolicy.RUNTIME)
@Inherit(Inherit.Type.None) @interface Imperative {}
@Inherit(Inherit.Type.None)
@interface Imperative {}
}
10 changes: 5 additions & 5 deletions src/main/java/org/comroid/annotations/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
@Inherit(Inherit.Type.FromSupertype)
public @interface Order {
Comparator<AnnotatedElement> COMPARATOR = Comparator.comparingInt(it ->
Annotations.findAnnotations(Order.class, it)
.findAny()
.map(Annotations.Result::getAnnotation)
.map(Order::value)
.orElse(0));
Annotations.findAnnotations(Order.class, it)
.findAny()
.map(Annotations.Result::getAnnotation)
.map(Order::value)
.orElse(0));

int value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public static Stream<Result<Description>> description(@NotNull AnnotatedElement

public static String descriptionText(@NotNull AnnotatedElement of) {
return toString(description(of)
.map(Result::getAnnotation)
.toArray(Description[]::new));
.map(Result::getAnnotation)
.toArray(Description[]::new));
}

public static Wrap<Category.Adapter> category(@NotNull AnnotatedElement of) {
Expand Down Expand Up @@ -137,12 +137,12 @@ public static <T> Stream<T> constants(Class<? extends T> type) {
.filter(fld -> {
final int mod = fld.getModifiers();
return isStatic(mod) && isPublic(mod)
&& fld.getType().isAssignableFrom(type);
&& fld.getType().isAssignableFrom(type);
})
.map(fld -> Invocable.ofFieldGet(fld).invokeRethrow())
// do we really need to go through supertypes recursively?
.collect(append(of(type.getSuperclass())
.flatMap(Annotations::constants)))
.flatMap(Annotations::constants)))
.flatMap(cast(type));
}

Expand Down
42 changes: 21 additions & 21 deletions src/main/java/org/comroid/api/Disposable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

@Deprecated
public interface Disposable extends Closeable, PropertyHolder {
@NonExtendable
default void addChildren(Closeable... childs) {
for (Closeable child : childs)
getCloseables().add(child);
}

@NonExtendable
default Set<? super Closeable> getCloseables() {
//noinspection unchecked
return ((Set<? super Closeable>) getPropertyCache().computeIfAbsent("disposable-children", key -> new HashSet<>()));
}

@NonExtendable
default void addChildren(Closeable... childs) {
for (Closeable child : childs)
getCloseables().add(child);
}

@OverrideOnly
@SuppressWarnings("RedundantThrows")
default void closeSelf() throws Exception {
Expand Down Expand Up @@ -60,24 +60,28 @@ default List<? extends Throwable> dispose() {
getCloseables().stream().map(Closeable.class::cast),
Stream.of(ThrowingRunnable.rethrowing(this::closeSelf, null)::run)
)
.map(closeable -> {
try {
closeable.close();
} catch (Exception e) {
return e;
}

return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList()));
.map(closeable -> {
try {
closeable.close();
} catch (Exception e) {
return e;
}

return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList()));
}

final class MultipleExceptions extends RuntimeException {
public MultipleExceptions(String message, Collection<? extends Throwable> causes) {
super(composeMessage(message, causes));
}

public MultipleExceptions(Collection<? extends Throwable> causes) {
super(composeMessage(null, causes));
}

private static String composeMessage(
@Nullable String baseMessage, Collection<? extends Throwable> throwables
) {
Expand Down Expand Up @@ -107,9 +111,5 @@ public String toString() {

return out.toString();
}

public MultipleExceptions(Collection<? extends Throwable> causes) {
super(composeMessage(null, causes));
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/org/comroid/api/Polyfill.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static java.util.Objects.isNull;
import static java.util.Objects.*;

@Experimental
@UtilityClass
public final class Polyfill {
@Deprecated
public static final String UUID_PATTERN = RegExpUtil.UUID4.pattern();
private static final CompletableFuture<?> infiniteFuture = new CompletableFuture<>();
private static final Pattern DURATION_PATTERN = Pattern.compile(
"((?<amount>\\d)+(?<unit>[yMwdhms][oi]?n?))");
Expand All @@ -60,6 +58,8 @@ public final class Polyfill {
86400L, "d", // days
604800L, "w" // weeks
);
@Deprecated
public static final String UUID_PATTERN = RegExpUtil.UUID4.pattern();

public static <T> T supplyOnce(Provider<T> provider, Function<T, T> writer, Supplier<T> accessor) {
final T accessed = accessor.get();
Expand Down Expand Up @@ -258,9 +258,9 @@ public static Color parseHexColor(String hex) {

public static String hexString(Color color) {
return '#'
+ Integer.toHexString(color.getRed())
+ Integer.toHexString(color.getGreen())
+ Integer.toHexString(color.getBlue());
+ Integer.toHexString(color.getRed())
+ Integer.toHexString(color.getGreen())
+ Integer.toHexString(color.getBlue());
}

public static Inet4Address parseIPv4(String ipv4) {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/org/comroid/api/abstr/AbstractMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@
import java.util.stream.Collectors;

public interface AbstractMap<K, V> extends Map<K, V> {
@Override
default boolean isEmpty() {
return size() == 0;
}

@Override
default int size() {
return entrySet().size();
}

@Override
default void putAll(@NotNull Map<? extends K, ? extends V> m) {
m.forEach(this::put);
default boolean isEmpty() {
return size() == 0;
}

@Override
Expand All @@ -34,23 +29,28 @@ default boolean containsValue(Object value) {
return values().stream().anyMatch(value::equals);
}

@Override
default void putAll(@NotNull Map<? extends K, ? extends V> m) {
m.forEach(this::put);
}

@NotNull
@Override
default Set<K> keySet() {
//noinspection SimplifyStreamApiCallChains
return Collections.unmodifiableSet(entrySet()
.stream()
.map(Entry::getKey)
.collect(Collectors.toSet()));
.stream()
.map(Entry::getKey)
.collect(Collectors.toSet()));
}

@NotNull
@Override
default List<V> values() {
//noinspection SimplifyStreamApiCallChains
return Collections.unmodifiableList(entrySet()
.stream()
.map(Entry::getValue)
.collect(Collectors.toList()));
.stream()
.map(Entry::getValue)
.collect(Collectors.toList()));
}
}
16 changes: 8 additions & 8 deletions src/main/java/org/comroid/api/attr/Aliased.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
import java.util.stream.Stream;

public interface Aliased extends AnnotatedTarget.Extension {
static Stream<String> $(AnnotatedElement element) {
return Stream.concat(
Stream.of(element)
.flatMap(Streams.cast(Named.class))
.flatMap(n -> Stream.of(n.getPrimaryName(), n.getAlternateName())),
Annotations.aliases(element).stream());
}

default String name() {
return Stream.concat(names(), Stream.of(this)
.flatMap(Streams.cast(Named.class))
Expand All @@ -24,12 +32,4 @@ default Stream<String> names() {
default Stream<String> aliases() {
return element().stream().flatMap(Aliased::$);
}

static Stream<String> $(AnnotatedElement element) {
return Stream.concat(
Stream.of(element)
.flatMap(Streams.cast(Named.class))
.flatMap(n -> Stream.of(n.getPrimaryName(), n.getAlternateName())),
Annotations.aliases(element).stream());
}
}
18 changes: 9 additions & 9 deletions src/main/java/org/comroid/api/data/Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ public N2(double x, double y) {
this.y = y;
}

@Override
public double[] toArray() {
return new double[]{ x, y };
}

@Override
public double getZ() {
return 0;
Expand All @@ -246,6 +241,11 @@ public Vector setW(double value) {
throw Vector.outOfBounds(IndexW);
}

@Override
public double[] toArray() {
return new double[]{ x, y };
}

@Override
public int n() {
return 2;
Expand Down Expand Up @@ -288,13 +288,13 @@ public N3(double x, double y, double z) {
}

@Override
public int n() {
return 3;
public double[] toArray() {
return new double[]{ x, y, z };
}

@Override
public double[] toArray() {
return new double[]{ x, y, z };
public int n() {
return 3;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/comroid/api/data/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public final class Version implements Comparable<Version> {
public static final Pattern PATTERN = Pattern.compile(
"(?<major>\\d+)\\.(?<minor>\\d+)\\.?(?<patch>\\d+)?[.\\-_]?(?<candidate>(s(nap" +
"(shot)?)?|a(lpha)?|b(eta)?|(r(elease)?|c?))+)?[.\\-_]?(?<hotfix>\\d+)?");
"(shot)?)?|a(lpha)?|b(eta)?|(r(elease)?|c?))+)?[.\\-_]?(?<hotfix>\\d+)?");
private final int major;
private final int minor;
private final int patch;
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/comroid/api/data/bind/DataStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ <R extends java.lang.reflect.Member & AnnotatedElement> boolean filterPropertyMe
return checkAccess(fld) && !struct.getDeclaredProperties().containsKey(member.getName());
else if (member instanceof Method mtd)
return checkAccess(mtd)
&& (member.getName().startsWith("get") && member.getName().length() > 3)
&& mtd.getParameterCount() == 0
&& !struct.getDeclaredProperties().containsKey(Capitalization.Current.getProperties()
&& (member.getName().startsWith("get") && member.getName().length() > 3)
&& mtd.getParameterCount() == 0
&& !struct.getDeclaredProperties().containsKey(Capitalization.Current.getProperties()
.convert(member.getName().substring(3)));
else return false;
}
Expand Down Expand Up @@ -150,11 +150,11 @@ <R extends java.lang.reflect.Member & AnnotatedElement, P> DataStructure<T>.Prop
.filter(candidate -> {
var setterName = candidate.getName();
return setterName.startsWith("set")
&& setterName.length() > 3
&& setterName.equals("set" + UpperCamelCase.convert(name[0]))
&& checkAccess(candidate)
&& candidate.getParameterCount() == 1
&& ValueType.of(candidate.getParameterTypes()[0]).equals(type);
&& setterName.length() > 3
&& setterName.equals("set" + UpperCamelCase.convert(name[0]))
&& checkAccess(candidate)
&& candidate.getParameterCount() == 1
&& ValueType.of(candidate.getParameterTypes()[0]).equals(type);
})
.findAny())
.peek(parts::add)
Expand Down Expand Up @@ -224,7 +224,7 @@ private void setMetadata(Member member, AnnotatedElement... sources) {

<R extends java.lang.reflect.Member & AnnotatedElement> boolean filterConstructorMembers(R member) {
var base = (member instanceof Method || member instanceof java.lang.reflect.Constructor<?>)
&& !member.getName().startsWith("set") && checkAccess(member);
&& !member.getName().startsWith("set") && checkAccess(member);
if (member instanceof Method mtd)
return base && mtd.getReturnType().equals(target);
return base;
Expand Down
Loading

0 comments on commit 8eaabaa

Please sign in to comment.