Skip to content

Commit

Permalink
Expose the empty, immutable ConfigNode and ConfigList
Browse files Browse the repository at this point in the history
  • Loading branch information
Steanky committed Mar 10, 2024
1 parent 927e5d8 commit ad668ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public Set<Entry<String, ConfigElement>> entrySet() {
}
}

private static final class ConfigListView extends AbstractConfigList implements Immutable, RandomAccess {
static final class ConfigListView extends AbstractConfigList implements Immutable, RandomAccess {
private final ConfigList underlying;

private ConfigListView(ConfigList underlying) {
Expand Down Expand Up @@ -232,8 +232,8 @@ public int size() {
}
}

private static final class EmptyImmutableConfigList extends AbstractConfigList implements Immutable, RandomAccess {
private static final ConfigList INSTANCE = new EmptyImmutableConfigList();
static final class EmptyImmutableConfigList extends AbstractConfigList implements Immutable, RandomAccess {
static final ConfigList INSTANCE = new EmptyImmutableConfigList();

private EmptyImmutableConfigList() {

Expand Down Expand Up @@ -270,8 +270,8 @@ public int size() {
}
}

private static final class EmptyImmutableConfigNode extends AbstractConfigNode implements Immutable {
private static final ConfigNode INSTANCE = new EmptyImmutableConfigNode();
static final class EmptyImmutableConfigNode extends AbstractConfigNode implements Immutable {
static final ConfigNode INSTANCE = new EmptyImmutableConfigNode();

private EmptyImmutableConfigNode() {
}
Expand Down Expand Up @@ -330,7 +330,7 @@ public Set<Entry<String, ConfigElement>> entrySet() {
}
}

private static final class ImmutableConfigNode extends AbstractConfigNode implements Immutable {
static final class ImmutableConfigNode extends AbstractConfigNode implements Immutable {
private final Map<String, ConfigElement> map;

private ImmutableConfigNode(Map<String, ConfigElement> trusted) {
Expand Down Expand Up @@ -380,7 +380,7 @@ public Set<Entry<String, ConfigElement>> entrySet() {
}
}

private static final class ImmutableConfigList extends AbstractConfigList implements Immutable, RandomAccess {
static final class ImmutableConfigList extends AbstractConfigList implements Immutable, RandomAccess {
private final ConfigElement[] elements;

private ImmutableConfigList(ConfigElement[] elements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
* Represents an ordered collection of {@link ConfigElement} objects. ConfigList does not support null values.
*/
public interface ConfigList extends ConfigElement, List<ConfigElement>, ConfigContainer {
/**
* The shared, immutable empty ConfigList.
*/
ConfigList EMPTY = ConfigContainers.EmptyImmutableConfigList.INSTANCE;

/**
* Similarly to {@link ConfigNode#of(Object...)}, builds a new {@link ArrayConfigList} from the given object array.
* Objects that are instances of {@link ConfigElement} will be added to the resulting list directly, whereas objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
* {@link ConfigPrimitive} instance containing null.</p>
*/
public interface ConfigNode extends ConfigElement, Map<String, ConfigElement>, ConfigContainer {
/**
* The shared, immutable empty ConfigNode.
*/
ConfigNode EMPTY = ConfigContainers.EmptyImmutableConfigNode.INSTANCE;

/**
* Overload of {@link ConfigNode#of(Object...)}. Returns a new, empty {@link LinkedConfigNode}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/**
* Marker interface indicating a {@link ConfigContainer} implementation is immutable; i.e. its mutating methods, like
* {@link ConfigList#add(Object)} or {@link ConfigNode#put(Object, Object)}, will throw an exception if called, and
* cannot change the container itself.
* cannot change the container itself. However, the contents may still change if there is an underlying container
* that is mutable.
* <p>
* Additionally, implementations must ensure that any sub-containers are also immutable.
*/
Expand Down

0 comments on commit ad668ad

Please sign in to comment.