Skip to content

Commit

Permalink
Rename collection interfaces as recommended in "Escape from the Plane…
Browse files Browse the repository at this point in the history
…t of the Collections" by Stuart Marks and Maurice Naftalin.

Watch https://www.youtube.com/watch?v=aj6E0KF6sd4&ab_channel=Devoxx

Rename ReadOnlyCollection to ReadableCollection.
- Rationale: Subtypes may allow mutation of the collection. Hence, the "ReadOnly" in the name may be misleading.

Rename ImmutableCollection to PersistentCollection.
- Rationale: Subtypes may allow mutation of the collection. Hence, the "Immutable" in the name may be misleading.
  • Loading branch information
wrandelshofer committed Oct 18, 2024
1 parent f5f860c commit 3cf55e3
Show file tree
Hide file tree
Showing 300 changed files with 2,334 additions and 2,326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.jhotdraw8.fxbase.concurrent.WorkState;
import org.jhotdraw8.fxbase.control.Disableable;
import org.jhotdraw8.fxcollection.typesafekey.Key;
import org.jhotdraw8.icollection.immutable.ImmutableMap;
import org.jhotdraw8.icollection.persistent.PersistentMap;
import org.jspecify.annotations.Nullable;

import java.net.URI;
Expand Down Expand Up @@ -134,7 +134,7 @@ default void setDataFormat(@Nullable DataFormat newValue) {
* @return Returns a CompletionStage which is completed with the data format that was
* actually used for reading the file.
*/
CompletionStage<DataFormat> read(URI uri, @Nullable DataFormat format, ImmutableMap<Key<?>, Object> options, boolean insert, WorkState<Void> workState);
CompletionStage<DataFormat> read(URI uri, @Nullable DataFormat format, PersistentMap<Key<?>, Object> options, boolean insert, WorkState<Void> workState);

/**
* Sets the content of this activity by asynchronously reading the data from
Expand All @@ -154,7 +154,7 @@ default void setDataFormat(@Nullable DataFormat newValue) {
* @param options reading options
* @return a completable worker for monitoring the progress of the read operation
*/
default CompletableWorker<Void> read(URI uri, ImmutableMap<Key<?>, Object> options) {
default CompletableWorker<Void> read(URI uri, PersistentMap<Key<?>, Object> options) {
SimpleCompletableWorker<Void> worker = new SimpleCompletableWorker<>(new SimpleWorkState<>(getApplication().getResources().getFormatted("file.reading.worker.title", uri.getPath())));
worker.completeExceptionally(new UnsupportedOperationException());
return worker;
Expand All @@ -178,7 +178,7 @@ default CompletableWorker<Void> read(URI uri, ImmutableMap<Key<?>, Object> optio
* @return Returns a CompletionStage which is completed when the write
* operation has finished.
*/
CompletionStage<Void> write(URI uri, @Nullable DataFormat format, ImmutableMap<Key<?>, Object> options, WorkState<Void> workState);
CompletionStage<Void> write(URI uri, @Nullable DataFormat format, PersistentMap<Key<?>, Object> options, WorkState<Void> workState);

/**
* Asynchronously writes the content of this activity into the specified uri.
Expand All @@ -197,7 +197,7 @@ default CompletableWorker<Void> read(URI uri, ImmutableMap<Key<?>, Object> optio
* @param options writing options
* @return a completable worker for monitoring the progress of the write operation
*/
default CompletableWorker<Void> write(URI uri, ImmutableMap<Key<?>, Object> options, WorkState<Void> state) {
default CompletableWorker<Void> write(URI uri, PersistentMap<Key<?>, Object> options, WorkState<Void> state) {
return FXWorker.work(getApplication().getExecutor(), s -> null, state);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package org.jhotdraw8.collection.computed;

import org.jhotdraw8.icollection.exception.SizeLimitExceededException;
import org.jhotdraw8.icollection.readonly.AbstractReadOnlyList;
import org.jhotdraw8.icollection.readable.AbstractReadableList;

import java.util.function.LongFunction;

Expand All @@ -12,7 +12,7 @@
/**
* A read-only list over values that are computed from the indices of the list.
*/
public class ComputedList<E> extends AbstractReadOnlyList<E> {
public class ComputedList<E> extends AbstractReadableList<E> {
private final boolean descending;
private final long size;
private final long from;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
/*
* @(#)MappedReadOnlyList.java
* @(#)MappedReadableList.java
* Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
*/
package org.jhotdraw8.collection.mapped;

import org.jhotdraw8.icollection.facade.ReadOnlySequencedCollectionFacade;
import org.jhotdraw8.icollection.readonly.AbstractReadOnlyList;
import org.jhotdraw8.icollection.readonly.ReadOnlyList;
import org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection;
import org.jhotdraw8.icollection.facade.ReadableSequencedCollectionFacade;
import org.jhotdraw8.icollection.readable.AbstractReadableList;
import org.jhotdraw8.icollection.readable.ReadableList;
import org.jhotdraw8.icollection.readable.ReadableSequencedCollection;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.function.Function;

/**
* Maps a {@link ReadOnlyList} to a different element type.
* Maps a {@link ReadableList} to a different element type.
* <p>
* The underlying List is referenced - not copied.
*
* @param <E> the mapped element type
* @param <F> the original element type
* @author Werner Randelshofer
*/
public final class MappedReadOnlyList<E, F> extends AbstractReadOnlyList<E> {
public final class MappedReadableList<E, F> extends AbstractReadableList<E> {

private final ReadOnlyList<F> backingList;
private final ReadableList<F> backingList;
private final Function<F, E> mapf;

public MappedReadOnlyList(ReadOnlyList<F> backingList, Function<F, E> mapf) {
public MappedReadableList(ReadableList<F> backingList, Function<F, E> mapf) {
this.backingList = backingList;
this.mapf = mapf;
}
Expand Down Expand Up @@ -95,8 +95,8 @@ public void remove() {
}

@Override
public ReadOnlySequencedCollection<E> readOnlyReversed() {
return new ReadOnlySequencedCollectionFacade<>(
public ReadableSequencedCollection<E> readOnlyReversed() {
return new ReadableSequencedCollectionFacade<>(
this::reverseIterator,
this::iterator,
this::size,
Expand All @@ -118,7 +118,7 @@ public int size() {
}

@Override
public ReadOnlyList<E> readOnlySubList(int fromIndex, int toIndex) {
return new MappedReadOnlyList<>(backingList.readOnlySubList(fromIndex, toIndex), mapf);
public ReadableList<E> readOnlySubList(int fromIndex, int toIndex) {
return new MappedReadableList<>(backingList.readOnlySubList(fromIndex, toIndex), mapf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.jhotdraw8.collection.primitive;

import org.jhotdraw8.icollection.readonly.AbstractReadOnlySet;
import org.jhotdraw8.icollection.readable.AbstractReadableSet;
import org.jspecify.annotations.Nullable;

import java.util.Iterator;
Expand All @@ -14,7 +14,7 @@
/**
* Represents a set of integers in a given range.
*/
public class IntRangeSet extends AbstractReadOnlySet<Integer> {
public class IntRangeSet extends AbstractReadableSet<Integer> {
private final int from;
private final int to;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.jhotdraw8.collection.spliterator;

import org.jhotdraw8.icollection.readonly.ReadOnlyList;
import org.jhotdraw8.icollection.readable.ReadableList;
import org.jspecify.annotations.Nullable;

import java.util.ListIterator;
Expand All @@ -14,22 +14,22 @@

/**
* A {@link ListIterator}, and {@link Spliterator} for a
* {@link ReadOnlyList}.
* {@link ReadableList}.
* <p>
* Does not perform modification checks.
*
* @param <E> the element type
*/
public class ReadOnlyListSpliterator<E> extends AbstractListIteratorSpliterator<E> {
private final ReadOnlyList<E> list;
private final ReadableList<E> list;
private int index;
private final int size;

public ReadOnlyListSpliterator(ReadOnlyList<E> list) {
public ReadOnlyListSpliterator(ReadableList<E> list) {
this(list, 0, list.size());
}

public ReadOnlyListSpliterator(ReadOnlyList<E> list, int index, int size) {
public ReadOnlyListSpliterator(ReadableList<E> list, int index, int size) {
this.list = list;
this.size = size;
this.index = index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import org.jhotdraw8.css.parser.CssToken;
import org.jhotdraw8.icollection.VectorList;
import org.jhotdraw8.icollection.immutable.ImmutableList;
import org.jhotdraw8.icollection.readonly.ReadOnlyList;
import org.jhotdraw8.icollection.persistent.PersistentList;
import org.jhotdraw8.icollection.readable.ReadableList;
import org.jspecify.annotations.Nullable;

import java.util.List;
Expand All @@ -20,8 +20,8 @@
*/
public class AtRule extends Rule {
private final String atKeyword;
private final ImmutableList<CssToken> header;
private final ImmutableList<CssToken> body;
private final PersistentList<CssToken> header;
private final PersistentList<CssToken> body;

/**
* Creates a new instance.
Expand Down Expand Up @@ -76,7 +76,7 @@ public String getAtKeyword() {
*
* @return the header tokens
*/
public ReadOnlyList<CssToken> getHeader() {
public ReadableList<CssToken> getHeader() {
return header;
}

Expand All @@ -85,7 +85,7 @@ public ReadOnlyList<CssToken> getHeader() {
*
* @return the body tokens
*/
public ReadOnlyList<CssToken> getBody() {
public ReadableList<CssToken> getBody() {
return body;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.jhotdraw8.css.parser.CssToken;
import org.jhotdraw8.icollection.VectorList;
import org.jhotdraw8.icollection.immutable.ImmutableList;
import org.jhotdraw8.icollection.persistent.PersistentList;
import org.jspecify.annotations.Nullable;

import java.util.List;
Expand All @@ -20,7 +20,7 @@
public class Declaration extends AbstractSyntaxTree {
private final @Nullable String namespace;
private final String propertyName;
private final ImmutableList<CssToken> terms;
private final PersistentList<CssToken> terms;
private final int startPos;
private final int endPos;
private final int lineNumber;
Expand All @@ -47,7 +47,7 @@ public String getPropertyName() {
return propertyName;
}

public ImmutableList<CssToken> getTerms() {
public PersistentList<CssToken> getTerms() {
return terms;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.jhotdraw8.css.parser.CssToken;
import org.jhotdraw8.css.parser.CssTokenType;
import org.jhotdraw8.icollection.VectorList;
import org.jhotdraw8.icollection.readonly.ReadOnlyList;
import org.jhotdraw8.icollection.readable.ReadableList;
import org.jspecify.annotations.Nullable;

import java.util.List;
Expand All @@ -23,7 +23,7 @@
*/
public class SelectorGroup extends Selector {

private final ReadOnlyList<Selector> selectors;
private final ReadableList<Selector> selectors;

public SelectorGroup(@Nullable SourceLocator sourceLocator, Selector selector) {
super(sourceLocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package org.jhotdraw8.css.ast;

import org.jhotdraw8.icollection.VectorList;
import org.jhotdraw8.icollection.immutable.ImmutableList;
import org.jhotdraw8.icollection.persistent.PersistentList;
import org.jspecify.annotations.Nullable;

import java.util.List;
Expand All @@ -18,7 +18,7 @@
public class StyleRule extends Rule {

private final SelectorGroup selectorList;
private final ImmutableList<Declaration> declarations;
private final PersistentList<Declaration> declarations;

public StyleRule(@Nullable SourceLocator sourceLocator, SelectorGroup selectorGroup, List<Declaration> declarations) {
super(sourceLocator);
Expand All @@ -43,7 +43,7 @@ public SelectorGroup getSelectorGroup() {
return selectorList;
}

public ImmutableList<Declaration> getDeclarations() {
public PersistentList<Declaration> getDeclarations() {
return declarations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package org.jhotdraw8.css.ast;

import org.jhotdraw8.icollection.VectorList;
import org.jhotdraw8.icollection.immutable.ImmutableList;
import org.jhotdraw8.icollection.readonly.ReadOnlyList;
import org.jhotdraw8.icollection.persistent.PersistentList;
import org.jhotdraw8.icollection.readable.ReadableList;
import org.jspecify.annotations.Nullable;

import java.net.URI;
Expand All @@ -24,8 +24,8 @@ public class Stylesheet extends AbstractSyntaxTree {


private final @Nullable URI uri;
private final ImmutableList<Rule> rules;
private final ImmutableList<StyleRule> styleRules;
private final PersistentList<Rule> rules;
private final PersistentList<StyleRule> styleRules;

public Stylesheet(@Nullable URI uri, List<Rule> rules) {
super(new SourceLocator(0, 1, uri));
Expand All @@ -52,7 +52,7 @@ public Stylesheet(@Nullable URI uri, List<Rule> rules) {
*
* @return the rules
*/
public ReadOnlyList<StyleRule> getStyleRules() {
public ReadableList<StyleRule> getStyleRules() {
return styleRules;
}

Expand All @@ -61,7 +61,7 @@ public ReadOnlyList<StyleRule> getStyleRules() {
*
* @return the rules
*/
public ReadOnlyList<Rule> getRules() {
public ReadableList<Rule> getRules() {
return rules;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jhotdraw8.css.parser.CssTokenizer;
import org.jhotdraw8.css.parser.StreamCssTokenizer;
import org.jhotdraw8.icollection.VectorList;
import org.jhotdraw8.icollection.immutable.ImmutableList;
import org.jhotdraw8.icollection.persistent.PersistentList;
import org.jspecify.annotations.Nullable;

import java.io.IOException;
Expand Down Expand Up @@ -157,7 +157,7 @@ default T fromString(CharBuffer buf, @Nullable IdResolver idResolver) throws Par
@Override
@Nullable String getHelpText();

default ImmutableList<String> getExamples() {
default PersistentList<String> getExamples() {
return VectorList.of();
}

Expand Down
Loading

0 comments on commit 3cf55e3

Please sign in to comment.