Skip to content

Commit

Permalink
Renamed immutable collection interface to follow standard convention
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jul 30, 2021
1 parent e471ead commit 30aa9ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/main/java/net/fortuna/ical4j/model/ComponentList.java
Expand Up @@ -40,7 +40,7 @@
* Defines a list of iCalendar components.
* @author Ben Fortuna
*/
public class ComponentList<T extends Component> implements ContentContainer<T> {
public class ComponentList<T extends Component> implements ContentCollection<T> {

private final List<T> components;

Expand All @@ -61,21 +61,21 @@ public ComponentList(List<? extends T> components) {
}

@Override
public ContentContainer<T> add(T content) {
public ContentCollection<T> add(T content) {
List<T> copy = new ArrayList<>(components);
copy.add(content);
return new ComponentList<>(copy);
}

@Override
public ContentContainer<T> addAll(Collection<T> content) {
public ContentCollection<T> addAll(Collection<T> content) {
List<T> copy = new ArrayList<>(components);
copy.addAll(content);
return new ComponentList<>(copy);
}

@Override
public ContentContainer<T> remove(T content) {
public ContentCollection<T> remove(T content) {
List<T> copy = new ArrayList<>(components);
if (copy.remove(content)) {
return new ComponentList<>(copy);
Expand All @@ -85,7 +85,7 @@ public ContentContainer<T> remove(T content) {
}

@Override
public ContentContainer<T> removeAll(String... name) {
public ContentCollection<T> removeAll(String... name) {
List<String> names = Arrays.asList(name);
List<T> copy = new ArrayList<>(components);
if (copy.removeIf(c -> names.contains(c.getName()))) {
Expand All @@ -96,7 +96,7 @@ public ContentContainer<T> removeAll(String... name) {
}

@Override
public ContentContainer<T> replace(T content) {
public ContentCollection<T> replace(T content) {
List<T> copy = new ArrayList<>(components);
copy.removeIf(c -> c.getName().equals(content.getName()));
copy.add(content);
Expand Down
Expand Up @@ -6,17 +6,25 @@
import java.util.Optional;
import java.util.stream.Collectors;

public interface ContentContainer<T extends Content> 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 <T>
*/
public interface ContentCollection<T extends Content> extends Serializable {

ContentContainer<T> add(T content);
ContentCollection<T> add(T content);

ContentContainer<T> addAll(Collection<T> content);
ContentCollection<T> addAll(Collection<T> content);

ContentContainer<T> remove(T content);
ContentCollection<T> remove(T content);

ContentContainer<T> removeAll(String... name);
ContentCollection<T> removeAll(String... name);

ContentContainer<T> replace(T content);
ContentCollection<T> replace(T content);

List<T> getAll();

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/fortuna/ical4j/model/ParameterList.java
Expand Up @@ -40,7 +40,7 @@
* Accessor implementation for a list of iCalendar parameters.
* @author Ben Fortuna
*/
public class ParameterList implements ContentContainer<Parameter> {
public class ParameterList implements ContentCollection<Parameter> {

private final List<Parameter> parameters;

Expand All @@ -60,21 +60,21 @@ public ParameterList(List<Parameter> list) {
}

@Override
public ContentContainer<Parameter> add(Parameter content) {
public ContentCollection<Parameter> add(Parameter content) {
List<Parameter> copy = new ArrayList<>(parameters);
copy.add(content);
return new ParameterList(copy);
}

@Override
public ContentContainer<Parameter> addAll(Collection<Parameter> content) {
public ContentCollection<Parameter> addAll(Collection<Parameter> content) {
List<Parameter> copy = new ArrayList<>(parameters);
copy.addAll(content);
return new ParameterList(copy);
}

@Override
public ContentContainer<Parameter> remove(Parameter content) {
public ContentCollection<Parameter> remove(Parameter content) {
List<Parameter> copy = new ArrayList<>(parameters);
if (copy.remove(content)) {
return new ParameterList(copy);
Expand All @@ -84,7 +84,7 @@ public ContentContainer<Parameter> remove(Parameter content) {
}

@Override
public ContentContainer<Parameter> removeAll(String... name) {
public ContentCollection<Parameter> removeAll(String... name) {
List<String> names = Arrays.asList(name);
List<Parameter> copy = new ArrayList<>(parameters);
if (copy.removeIf(p -> names.contains(p.getName()))) {
Expand All @@ -95,7 +95,7 @@ public ContentContainer<Parameter> removeAll(String... name) {
}

@Override
public ContentContainer<Parameter> replace(Parameter content) {
public ContentCollection<Parameter> replace(Parameter content) {
List<Parameter> copy = new ArrayList<>(parameters);
copy.removeIf(p -> p.getName().equals(content.getName()));
copy.add(content);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/fortuna/ical4j/model/PropertyList.java
Expand Up @@ -40,7 +40,7 @@
* Accessor implementation for a list of iCalendar properties.
* @author Ben Fortuna
*/
public class PropertyList implements ContentContainer<Property> {
public class PropertyList implements ContentCollection<Property> {

private final List<Property> properties;

Expand All @@ -61,21 +61,21 @@ public PropertyList(List<Property> properties) {
}

@Override
public ContentContainer<Property> add(Property content) {
public ContentCollection<Property> add(Property content) {
List<Property> copy = new ArrayList<>(properties);
copy.add(content);
return new PropertyList(copy);
}

@Override
public ContentContainer<Property> addAll(Collection<Property> content) {
public ContentCollection<Property> addAll(Collection<Property> content) {
List<Property> copy = new ArrayList<>(properties);
copy.addAll(content);
return new PropertyList(copy);
}

@Override
public ContentContainer<Property> remove(Property content) {
public ContentCollection<Property> remove(Property content) {
List<Property> copy = new ArrayList<>(properties);
if (copy.remove(content)) {
return new PropertyList(copy);
Expand All @@ -85,7 +85,7 @@ public ContentContainer<Property> remove(Property content) {
}

@Override
public ContentContainer<Property> removeAll(String... name) {
public ContentCollection<Property> removeAll(String... name) {
List<String> names = Arrays.asList(name);
List<Property> copy = new ArrayList<>(properties);
if (copy.removeIf(p -> names.contains(p.getName()))) {
Expand All @@ -96,7 +96,7 @@ public ContentContainer<Property> removeAll(String... name) {
}

@Override
public ContentContainer<Property> replace(Property content) {
public ContentCollection<Property> replace(Property content) {
List<Property> copy = new ArrayList<>(properties);
copy.removeIf(p -> p.getName().equals(content.getName()));
copy.add(content);
Expand Down

0 comments on commit 30aa9ac

Please sign in to comment.