Skip to content

Commit a8e46d7

Browse files
committed
Reduce API surface and remove some defaulted methods
1 parent 5139b68 commit a8e46d7

File tree

4 files changed

+13
-62
lines changed

4 files changed

+13
-62
lines changed

src/main/java/org/spongepowered/api/registry/RegistryKey.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* @param <T> The type
3939
*/
40-
public interface RegistryKey<T> extends Comparable<RegistryKey<?>> {
40+
public interface RegistryKey<T> {
4141

4242
static <T> RegistryKey<T> of(final RegistryType<T> registry, final ResourceKey location) {
4343
return Sponge.game().factoryProvider().provide(Factory.class).of(Objects.requireNonNull(registry, "registry"),
@@ -59,16 +59,6 @@ static <T> RegistryKey<T> of(final RegistryType<T> registry, final ResourceKey l
5959
*/
6060
ResourceKey location();
6161

62-
@Override
63-
default int compareTo(final RegistryKey<?> registryKey) {
64-
final int registry = this.registry().compareTo(registryKey.registry());
65-
if (registry != 0) {
66-
return registry;
67-
}
68-
69-
return this.location().compareTo(registryKey.location());
70-
}
71-
7262
/**
7363
* Generates a utility {@link RegistryReference reference} used to assist in querying a value from this key
7464
*

src/main/java/org/spongepowered/api/tag/DefaultedTag.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.spongepowered.api.registry.RegistryHolder;
3030
import org.spongepowered.api.registry.ValueNotFoundException;
3131

32-
import java.util.Objects;
3332
import java.util.function.Supplier;
3433
import java.util.stream.Stream;
3534

@@ -45,12 +44,12 @@ static <T> DefaultedTag<T> of(final DefaultedRegistryType<T> registryType, final
4544
Supplier<RegistryHolder> defaultHolder();
4645

4746
/**
48-
* Returns the {@link Stream} of values tagged by this tag in the {@link #defaultHolder()}.
47+
* Returns the {@link Stream} of values tagged by this tag.
4948
*
5049
* <p>Great care needs to be made in calling this method with any uncertainty as to
51-
* if the {@link #registry()} will exist in the {@link #defaultHolder()}. Should the
52-
* key lack a value, a {@link ValueNotFoundException} will be thrown. Therefore, it
53-
* is advised to call {@link #findValues()} instead.</p>
50+
* if the {@link #registry()} will exist in the holder. Should the key lack a value,
51+
* a {@link ValueNotFoundException} will be thrown. Therefore, it is advised to call
52+
* {@link #findValues()} instead.</p>
5453
*
5554
* @return The {@link Stream} of values
5655
*/
@@ -59,7 +58,7 @@ default Stream<T> values() {
5958
}
6059

6160
/**
62-
* Returns the {@link Stream} of values tagged by this tag in the {@link #defaultHolder()}
61+
* Returns the {@link Stream} of values tagged by this tag in the holder
6362
* if it contains this tag's {@link #registry()}, or {@link Stream#empty()} otherwise.
6463
*
6564
* @return The {@link Stream} of values
@@ -69,12 +68,10 @@ default Stream<T> findValues() {
6968
}
7069

7170
/**
72-
* Returns whether this tag is associated with the given value in the {@link #defaultHolder()}.
71+
* Returns whether this tag is associated with the given value.
7372
*
7473
* @param value The value
75-
* @return true if this tag is associated with the given value in the {@link #defaultHolder()}
74+
* @return true if this tag is associated with the given value
7675
*/
77-
default boolean contains(final T value) {
78-
return this.findValues().anyMatch(Objects.requireNonNull(value, "value")::equals);
79-
}
76+
boolean contains(T value);
8077
}

src/main/java/org/spongepowered/api/tag/Tag.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* {@link BlockTypeTags#LOGS_THAT_BURN}</li>
5151
* </ul>
5252
*/
53-
public interface Tag<T> extends ResourceKeyed, Comparable<Tag<?>> {
53+
public interface Tag<T> extends ResourceKeyed {
5454

5555
static <T> Tag<T> of(final RegistryType<T> registryType, final ResourceKey key) {
5656
return Sponge.game().factoryProvider().provide(Tag.Factory.class).of(registryType, key);
@@ -63,16 +63,6 @@ static <T> Tag<T> of(final RegistryType<T> registryType, final ResourceKey key)
6363
*/
6464
RegistryType<T> registry();
6565

66-
@Override
67-
default int compareTo(final Tag<?> tag) {
68-
final int registry = this.registry().compareTo(tag.registry());
69-
if (registry != 0) {
70-
return registry;
71-
}
72-
73-
return this.key().compareTo(tag.key());
74-
}
75-
7666
DefaultedTag<T> asDefaultedTag(Supplier<RegistryHolder> holder);
7767

7868
DefaultedTag<T> asScopedTag();

src/main/java/org/spongepowered/api/tag/Taggable.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,55 +26,29 @@
2626

2727
import org.spongepowered.api.registry.DefaultedRegistryType;
2828
import org.spongepowered.api.registry.DefaultedRegistryValue;
29-
import org.spongepowered.api.registry.Registry;
30-
import org.spongepowered.api.registry.RegistryHolder;
3129

32-
import java.util.Objects;
3330
import java.util.stream.Stream;
3431

3532
/**
3633
* A type that may be included in one or more {@link Tag} collections.
3734
*/
38-
@SuppressWarnings("unchecked")
3935
public interface Taggable<T extends Taggable<T>> extends DefaultedRegistryValue {
4036

4137
/**
4238
* Gets all {@link Tag}s that have been associated with this object in the given registry.
4339
*
4440
* @return The {@link Stream} of {@link Tag}s.
4541
*/
46-
default Stream<Tag<T>> tags(final DefaultedRegistryType<T> registryType) {
47-
final Registry<T> registry = Objects.requireNonNull(registryType, "registryType").get();
48-
return registry.tags().filter(tag -> this.is(registry, tag));
49-
}
50-
51-
/**
52-
* Returns whether the given tag is associated with this object in the given registry holder.
53-
*
54-
* @param tag The tag
55-
* @return true if the given tag is associated with this object in the given registry holder
56-
*/
57-
default boolean is(final RegistryHolder registryHolder, final Tag<T> tag) {
58-
return registryHolder.findRegistry(tag.registry()).map(r -> this.is(r, tag)).orElse(false);
59-
}
60-
61-
/**
62-
* Returns whether the given tag is associated with this object in the given registry.
63-
*
64-
* @param tag The tag
65-
* @return true if the given tag is associated with this object in the given registry
66-
*/
67-
default boolean is(final Registry<T> registry, final Tag<T> tag) {
68-
return registry.taggedValues(tag).anyMatch(this::equals);
69-
}
42+
Stream<Tag<T>> tags(DefaultedRegistryType<T> registryType);
7043

7144
/**
7245
* Returns whether the given tag is associated with this object.
7346
*
7447
* @param tag The tag
7548
* @return true if the given tag is associated with this object
7649
*/
77-
default boolean is(final DefaultedTag<T> tag) {
50+
@SuppressWarnings("unchecked")
51+
default boolean is(DefaultedTag<T> tag) {
7852
return tag.contains((T) this);
7953
}
8054
}

0 commit comments

Comments
 (0)