Skip to content

Commit c6bfd9e

Browse files
committed
Added back MutList.add() and .addAll() methods. Hopefully, this is a good idea.
1 parent 812181c commit c6bfd9e

File tree

6 files changed

+132
-49
lines changed

6 files changed

+132
-49
lines changed

CHANGE_LOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ releases on the way from an old version to a new one. Fix any deprecation warni
55
release before upgrading to the next one. The documentation next to each Deprecated annotation
66
tells you what to use instead. Once we delete the deprecated methods, that documentation goes too.
77

8+
### Release 3.6.0 2021-09-21
9+
- Added back .add() and .addAll() methods to MutList.
10+
This is sort of an experiment to see if this is more helpful than dangerous.
11+
It's probably helpful, but I can't do this with all the appropriate methods/interfaces right now.
12+
813
## Release 3.5.10 2021-09-21
914
- Bumped dependencies
1015

LICENSE.txt

+69-29
Large diffs are not rendered by default.

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ The Clojure collections are licensed under the Eclipse Public License.
108108
Versions of them have been included in this project and modified to add type safety and implement different interfaces.
109109
These files are still derivative works under the EPL.
110110

111-
Unless otherwise stated, the rest of this work is licensed under the Apache 2.0 license.
112-
New contributions should be made under the Apache 2.0 license whenever practical.
113-
I believe it is more popular, clearer, and has been better tested in courts of law.
111+
Unless otherwise stated, the rest of this work may be licensed under EITHER the Eclipse 1.0 or the Apache 2.0.
112+
You get to choose!
113+
New contributions should be made under both licenses whenever practical.
114+
I believe Apache is more popular, clearer, and has been better tested in courts of law.
114115

115116
Hermit Crab Photo by [Rushen](https://www.flickr.com/photos/rushen/12171498934/in/photostream/)
116117

pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ http://mvnrepository.com/artifact/org.organicdesign/Paguro
3838
-->
3939
<groupId>org.organicdesign</groupId>
4040
<artifactId>Paguro</artifactId>
41-
<version>3.5.10</version>
41+
<version>3.6.0</version>
4242
<packaging>jar</packaging>
4343

4444
<name>Paguro</name>
4545
<description>Immutable Clojure collections and a Transformation abstraction for Java 8+, immutably, type-safely, and with good performance.</description>
4646
<url>https://github.com/GlenKPeterson/Paguro</url>
4747

4848
<licenses>
49-
<license>
50-
<name>The Apache License, Version 2.0</name>
51-
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
52-
<comments>The license for most of the files in this project.</comments>
53-
</license>
5449
<license>
5550
<name>Eclipse Public License - v 1.0</name>
5651
<url>https://www.eclipse.org/legal/epl-v10.html</url>
5752
<comments>For the persistent collections in the
5853
collections/ folder. These files are derivative
5954
works based on the Clojure source code.</comments>
6055
</license>
56+
<license>
57+
<name>The Apache License, Version 2.0</name>
58+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
59+
<comments>This is an optional license (user can choose it) for the files in this project that were never part of Clojure.</comments>
60+
</license>
6161
</licenses>
6262
<developers>
6363
<developer>
6464
<name>Glen K. Peterson</name>
65-
<email>glen@organicdesign.org</email>
65+
<email>glen[email protected]</email>
6666
<organization>PlanBase Inc.</organization>
6767
</developer>
6868
</developers>

src/main/java/org/organicdesign/fp/collections/MutList.java

+26-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import org.jetbrains.annotations.NotNull;
1717

18+
import java.util.Collection;
19+
1820
/**
1921
A mutate-in-place interface using the same copy-on-write methods as {@link BaseList} and
2022
{@link ImList} so that you can treat mutable and immutable lists the same.
@@ -28,16 +30,30 @@ public interface MutList<E> extends BaseList<E> {
2830
MutList<E> append(E val);
2931

3032
// TODO: Is this a good idea? Kotlin does this...
31-
// /**
32-
// Ensures that this collection contains the specified element (optional operation).
33-
// Returns true if this collection changed as a result of the call.
34-
// */
35-
// @SuppressWarnings("deprecation")
36-
// @Override default boolean add(E val) {
37-
// int origSize = size();
38-
// append(val);
39-
// return origSize != size();
40-
// }
33+
// I'm concerned that we cannot provide good implementations for all these methods.
34+
// Will implementing some be a benefit?
35+
// Or just a temptation to use other deprecated methods?
36+
// I'm going to try this with a few easy methods to see how it goes.
37+
// These are all technically "optional" operations anyway.
38+
/**
39+
Ensures that this collection contains the specified element (optional operation).
40+
Returns true if this collection changed as a result of the call.
41+
*/
42+
@SuppressWarnings("deprecation")
43+
@Override default boolean add(E val) {
44+
append(val);
45+
return true;
46+
}
47+
48+
/**
49+
* Appends all the elements in the specified collection to the end of this list,
50+
* in the order that they are returned by the specified collection's iterator.
51+
*/
52+
@SuppressWarnings("deprecation")
53+
@Override default boolean addAll(@NotNull Collection<? extends E> c) {
54+
concat(c);
55+
return true;
56+
}
4157

4258
/** Returns a immutable version of this mutable list. */
4359
ImList<E> immutable();

src/test/java/org/organicdesign/fp/collections/MutListTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,25 @@ static class TestList<E> implements MutList<E> {
5656
assertEquals(control.size(), test.size());
5757
assertEquals(control, test);
5858
}
59+
60+
@Test public void testOriginalMethods() {
61+
List<String> control = new ArrayList<>();
62+
MutList<String> test = new TestList<>(new ArrayList<>());
63+
64+
for (int i = 0; i < 32; i++) {
65+
String ord = ordinal(i);
66+
assertTrue(control.add(ord));
67+
assertTrue(test.add(ord));
68+
assertEquals(control.size(), test.size());
69+
assertEquals(control, test);
70+
}
71+
72+
List<String> moreStuff = Arrays.asList("this", "is", "more", "stuff");
73+
assertTrue(control.addAll(moreStuff));
74+
assertTrue(test.addAll(moreStuff));
75+
76+
assertEquals(control.size(), test.size());
77+
assertEquals(control, test);
78+
}
79+
5980
}

0 commit comments

Comments
 (0)