diff --git a/src/main/java/net/fortuna/ical4j/model/ComponentList.java b/src/main/java/net/fortuna/ical4j/model/ComponentList.java index 7e8208d13..c3553ce94 100644 --- a/src/main/java/net/fortuna/ical4j/model/ComponentList.java +++ b/src/main/java/net/fortuna/ical4j/model/ComponentList.java @@ -40,7 +40,7 @@ * Defines a list of iCalendar components. * @author Ben Fortuna */ -public class ComponentList implements ContentContainer { +public class ComponentList implements ContentCollection { private final List components; @@ -61,21 +61,21 @@ public ComponentList(List components) { } @Override - public ContentContainer add(T content) { + public ContentCollection add(T content) { List copy = new ArrayList<>(components); copy.add(content); return new ComponentList<>(copy); } @Override - public ContentContainer addAll(Collection content) { + public ContentCollection addAll(Collection content) { List copy = new ArrayList<>(components); copy.addAll(content); return new ComponentList<>(copy); } @Override - public ContentContainer remove(T content) { + public ContentCollection remove(T content) { List copy = new ArrayList<>(components); if (copy.remove(content)) { return new ComponentList<>(copy); @@ -85,7 +85,7 @@ public ContentContainer remove(T content) { } @Override - public ContentContainer removeAll(String... name) { + public ContentCollection removeAll(String... name) { List names = Arrays.asList(name); List copy = new ArrayList<>(components); if (copy.removeIf(c -> names.contains(c.getName()))) { @@ -96,7 +96,7 @@ public ContentContainer removeAll(String... name) { } @Override - public ContentContainer replace(T content) { + public ContentCollection replace(T content) { List copy = new ArrayList<>(components); copy.removeIf(c -> c.getName().equals(content.getName())); copy.add(content); diff --git a/src/main/java/net/fortuna/ical4j/model/ContentContainer.java b/src/main/java/net/fortuna/ical4j/model/ContentCollection.java similarity index 59% rename from src/main/java/net/fortuna/ical4j/model/ContentContainer.java rename to src/main/java/net/fortuna/ical4j/model/ContentCollection.java index ec1196e0b..eebe4e3ed 100644 --- a/src/main/java/net/fortuna/ical4j/model/ContentContainer.java +++ b/src/main/java/net/fortuna/ical4j/model/ContentCollection.java @@ -6,17 +6,25 @@ import java.util.Optional; import java.util.stream.Collectors; -public interface ContentContainer extends Serializable { +/** + * Implementors of this interface support the immutable collection contract specified by this interface. + * + * The contract states that any mutation function will not modify the underlying collection, but rather + * will return a copy of the collection with the applied mutation. + * + * @param + */ +public interface ContentCollection extends Serializable { - ContentContainer add(T content); + ContentCollection add(T content); - ContentContainer addAll(Collection content); + ContentCollection addAll(Collection content); - ContentContainer remove(T content); + ContentCollection remove(T content); - ContentContainer removeAll(String... name); + ContentCollection removeAll(String... name); - ContentContainer replace(T content); + ContentCollection replace(T content); List getAll(); diff --git a/src/main/java/net/fortuna/ical4j/model/ParameterList.java b/src/main/java/net/fortuna/ical4j/model/ParameterList.java index 7bf19adb6..f75a64958 100644 --- a/src/main/java/net/fortuna/ical4j/model/ParameterList.java +++ b/src/main/java/net/fortuna/ical4j/model/ParameterList.java @@ -40,7 +40,7 @@ * Accessor implementation for a list of iCalendar parameters. * @author Ben Fortuna */ -public class ParameterList implements ContentContainer { +public class ParameterList implements ContentCollection { private final List parameters; @@ -60,21 +60,21 @@ public ParameterList(List list) { } @Override - public ContentContainer add(Parameter content) { + public ContentCollection add(Parameter content) { List copy = new ArrayList<>(parameters); copy.add(content); return new ParameterList(copy); } @Override - public ContentContainer addAll(Collection content) { + public ContentCollection addAll(Collection content) { List copy = new ArrayList<>(parameters); copy.addAll(content); return new ParameterList(copy); } @Override - public ContentContainer remove(Parameter content) { + public ContentCollection remove(Parameter content) { List copy = new ArrayList<>(parameters); if (copy.remove(content)) { return new ParameterList(copy); @@ -84,7 +84,7 @@ public ContentContainer remove(Parameter content) { } @Override - public ContentContainer removeAll(String... name) { + public ContentCollection removeAll(String... name) { List names = Arrays.asList(name); List copy = new ArrayList<>(parameters); if (copy.removeIf(p -> names.contains(p.getName()))) { @@ -95,7 +95,7 @@ public ContentContainer removeAll(String... name) { } @Override - public ContentContainer replace(Parameter content) { + public ContentCollection replace(Parameter content) { List copy = new ArrayList<>(parameters); copy.removeIf(p -> p.getName().equals(content.getName())); copy.add(content); diff --git a/src/main/java/net/fortuna/ical4j/model/PropertyList.java b/src/main/java/net/fortuna/ical4j/model/PropertyList.java index bb1d9b4bf..e283c35fc 100644 --- a/src/main/java/net/fortuna/ical4j/model/PropertyList.java +++ b/src/main/java/net/fortuna/ical4j/model/PropertyList.java @@ -40,7 +40,7 @@ * Accessor implementation for a list of iCalendar properties. * @author Ben Fortuna */ -public class PropertyList implements ContentContainer { +public class PropertyList implements ContentCollection { private final List properties; @@ -61,21 +61,21 @@ public PropertyList(List properties) { } @Override - public ContentContainer add(Property content) { + public ContentCollection add(Property content) { List copy = new ArrayList<>(properties); copy.add(content); return new PropertyList(copy); } @Override - public ContentContainer addAll(Collection content) { + public ContentCollection addAll(Collection content) { List copy = new ArrayList<>(properties); copy.addAll(content); return new PropertyList(copy); } @Override - public ContentContainer remove(Property content) { + public ContentCollection remove(Property content) { List copy = new ArrayList<>(properties); if (copy.remove(content)) { return new PropertyList(copy); @@ -85,7 +85,7 @@ public ContentContainer remove(Property content) { } @Override - public ContentContainer removeAll(String... name) { + public ContentCollection removeAll(String... name) { List names = Arrays.asList(name); List copy = new ArrayList<>(properties); if (copy.removeIf(p -> names.contains(p.getName()))) { @@ -96,7 +96,7 @@ public ContentContainer removeAll(String... name) { } @Override - public ContentContainer replace(Property content) { + public ContentCollection replace(Property content) { List copy = new ArrayList<>(properties); copy.removeIf(p -> p.getName().equals(content.getName())); copy.add(content);