1
0
mirror of https://github.com/lucko/LuckPerms.git synced 2025-09-09 13:50:52 +02:00

misc cleanup

This commit is contained in:
Luck
2017-12-23 23:51:42 +00:00
parent 862fe6e2e3
commit 6602b23f09
36 changed files with 281 additions and 4022 deletions

View File

@@ -34,6 +34,7 @@ import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Represents a permission node.
@@ -354,43 +355,127 @@ public interface Node extends Map.Entry<String, Boolean> {
*/
interface Builder {
/**
* Sets the value of negated for the node
*
* @param negated the value
* @return the builder
* @see Node#isNegated()
*/
@Nonnull
Builder setNegated(boolean negated);
/**
* Sets the value of the node
*
* @param value the value
* @return the builder
* @see Node#getValuePrimitive()
*/
@Nonnull
Builder setValue(boolean value);
/**
* Warning: this value does not persist, and disappears when the holder is re-loaded.
* It is therefore only useful for transient nodes.
* Sets the override property for the node
*
* <p>Warning: this value does not persist, and disappears when the holder is re-loaded.
* It is therefore only useful for transient nodes.</p>
*
* @param override the override state
* @return the builder
* @see Node#isOverride()
*/
@Nonnull
Builder setOverride(boolean override);
/**
* Sets the nodes expiry as a unix timestamp in seconds
*
* @param expireAt the expiry time
* @return the builder
* @see Node#getExpiryUnixTime()
*/
@Nonnull
Builder setExpiry(long expireAt);
/**
* Sets the world value for the node
*
* @param world the world value
* @return the builder
* @see Node#getWorld()
*/
@Nonnull
Builder setWorld(@Nonnull String world);
Builder setWorld(@Nullable String world);
/**
* Sets the server value for the node
*
* @param server the world value
* @return the builder
* @see Node#getServer()
*/
@Nonnull
Builder setServer(@Nonnull String server) throws IllegalArgumentException;
Builder setServer(@Nullable String server);
/**
* Appends an extra context onto the node
*
* @param key the context key
* @param value the context value
* @return the builder
* @see ContextSet
* @see Node#getContexts()
*/
@Nonnull
Builder withExtraContext(@Nonnull String key, @Nonnull String value);
/**
* Appends extra contexts onto the node
*
* @param map a map of contexts
* @see ContextSet
* @see Node#getContexts()
*/
@Nonnull
Builder withExtraContext(@Nonnull Map<String, String> map);
/**
* Appends extra contexts onto the node
*
* @param context a set of contexts
* @see ContextSet
* @see Node#getContexts()
*/
@Nonnull
Builder withExtraContext(@Nonnull Set<Map.Entry<String, String>> context);
/**
* Appends an extra context onto the node
*
* @param entry the context
* @return the builder
* @see ContextSet
* @see Node#getContexts()
*/
@Nonnull
Builder withExtraContext(@Nonnull Map.Entry<String, String> entry);
/**
* Appends extra contexts onto the node
*
* @param set a contextset
* @see ContextSet
* @see Node#getContexts()
*/
@Nonnull
Builder withExtraContext(@Nonnull ContextSet set);
/**
* Creates a node instance from the builder
*
* @return a new node instance
*/
@Nonnull
Node build();
}

View File

@@ -95,8 +95,8 @@ abstract class AbstractContextSet implements ContextSet {
final Multimap<String, String> otherContexts;
if (other instanceof MutableContextSet) {
otherContexts = ((MutableContextSet) other).backing();
if (other instanceof AbstractContextSet) {
otherContexts = ((AbstractContextSet) other).backing();
} else {
otherContexts = other.toMultimap();
}

View File

@@ -229,12 +229,19 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
* A builder for {@link ImmutableContextSet}
*/
public static final class Builder {
private final ImmutableSetMultimap.Builder<String, String> builder = ImmutableSetMultimap.builder();
private ImmutableSetMultimap.Builder<String, String> builder;
private Builder() {
}
private synchronized ImmutableSetMultimap.Builder<String, String> builder() {
if (builder == null) {
builder = ImmutableSetMultimap.builder();
}
return builder;
}
/**
* Adds a new key value pair to the set
*
@@ -244,7 +251,7 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
*/
@Nonnull
public Builder add(@Nonnull String key, @Nonnull String value) {
builder.put(sanitizeKey(key), sanitizeValue(value));
builder().put(sanitizeKey(key), sanitizeValue(value));
return this;
}
@@ -309,12 +316,11 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
@Nonnull
public Builder addAll(@Nonnull ContextSet contextSet) {
checkNotNull(contextSet, "contextSet");
if (contextSet instanceof MutableContextSet) {
MutableContextSet other = ((MutableContextSet) contextSet);
builder.putAll(other.backing());
} else if (contextSet instanceof ImmutableContextSet) {
ImmutableContextSet other = ((ImmutableContextSet) contextSet);
builder.putAll(other.backing());
if (contextSet instanceof AbstractContextSet) {
AbstractContextSet other = ((AbstractContextSet) contextSet);
if (!other.isEmpty()) {
builder().putAll(other.backing());
}
} else {
addAll(contextSet.toMultimap());
}
@@ -323,7 +329,11 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con
@Nonnull
public ImmutableContextSet build() {
return new ImmutableContextSet(builder.build());
if (builder == null) {
return empty();
} else {
return new ImmutableContextSet(builder.build());
}
}
}

View File

@@ -281,11 +281,8 @@ public final class MutableContextSet extends AbstractContextSet implements Conte
*/
public void addAll(@Nonnull ContextSet contextSet) {
checkNotNull(contextSet, "contextSet");
if (contextSet instanceof MutableContextSet) {
MutableContextSet other = ((MutableContextSet) contextSet);
this.map.putAll(other.map);
} else if (contextSet instanceof ImmutableContextSet) {
ImmutableContextSet other = ((ImmutableContextSet) contextSet);
if (contextSet instanceof AbstractContextSet) {
AbstractContextSet other = ((AbstractContextSet) contextSet);
this.map.putAll(other.backing());
} else {
addAll(contextSet.toMultimap());