Skip to content

Commit

Permalink
Release 0.9.21
Browse files Browse the repository at this point in the history
  • Loading branch information
magicwerk committed Jul 22, 2023
2 parents 5ab5577 + 9e05fb6 commit 21526dd
Show file tree
Hide file tree
Showing 45 changed files with 582 additions and 424 deletions.
4 changes: 2 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Get the library from Maven Central.
Gradle:

```
api 'org.magicwerk.brownies:brownies-collections:0.9.20'
api 'org.magicwerk.brownies:brownies-collections:0.9.21'
```

Maven:
Expand All @@ -39,6 +39,6 @@ Maven:
<dependency>
<groupId>org.magicwerk.brownies</groupId>
<artifactId>brownies-collections</artifactId>
<version>0.9.20</version>
<version>0.9.21</version>
</dependency>
```
33 changes: 16 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,33 @@ repositories {
}

dependencies {
testImplementation "org.magicwerk.brownies:brownies-collections:0.9.19"
testImplementation "org.magicwerk.brownies:brownies-core:0.9.9"
testImplementation "org.magicwerk.brownies:brownies-javassist:0.9.9"
testImplementation "org.magicwerk.brownies:brownies-jdom:0.9.9"
testImplementation "org.magicwerk.brownies:brownies-html:0.9.9"
testImplementation "org.magicwerk.brownies:brownies-test:0.9.9"
testImplementation "org.magicwerk.brownies:brownies-tools:0.9.9"
testImplementation "org.magicwerk.magictest:magictest:0.9.9"
testImplementation "org.magicwerk.magictest:magictest-ng:0.9.9"
testImplementation "org.magicwerk.brownies:brownies-core:0.9.11"
testImplementation "org.magicwerk.brownies:brownies-javassist:0.9.11"
testImplementation "org.magicwerk.brownies:brownies-jdom:0.9.11"
testImplementation "org.magicwerk.brownies:brownies-html:0.9.11"
testImplementation "org.magicwerk.brownies:brownies-test:0.9.11"
testImplementation "org.magicwerk.brownies:brownies-tools:0.9.11"
testImplementation "org.magicwerk.magictest:magictest:0.9.11"
testImplementation "org.magicwerk.magictest:magictest-ng:0.9.11"

testImplementation "junit:junit:4.8.2"
testImplementation "junit:junit:4.13.2"
testImplementation "com.google.guava:guava-testlib:31.1-jre"
testImplementation "com.github.javaparser:javaparser-core:3.24.0"
testImplementation "com.github.javaparser:javaparser-core:3.25.1"

testImplementation 'org.apache.commons:commons-collections4:4.0'
testImplementation 'org.javolution:javolution-core-java:6.0.0'
testImplementation 'it.unimi.dsi:fastutil:7.0.9'

testImplementation 'org.slf4j:slf4j-api:1.7.4'
testImplementation 'ch.qos.logback:logback-classic:1.0.11'
testImplementation 'ch.qos.logback:logback-core:1.0.11'
testImplementation 'org.slf4j:slf4j-api:1.7.36'
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
testImplementation 'ch.qos.logback:logback-core:1.2.11'
testImplementation 'org.apache.commons:commons-lang3:3.12.0'
testImplementation 'de.schlichtherle.truezip:truezip-file:7.7.10'
testImplementation 'de.schlichtherle.truezip:truezip-path:7.7.10'
testImplementation 'de.schlichtherle.truezip:truezip-driver-zip:7.7.10'
testImplementation 'org.javassist:javassist:3.28.0-GA'
testImplementation 'org.jdom:jdom2:2.0.6'
testImplementation 'org.openjdk.jmh:jmh-core:1.33'
testImplementation 'org.javassist:javassist:3.29.2-GA'
testImplementation 'org.jdom:jdom2:2.0.6.1'
testImplementation 'org.openjdk.jmh:jmh-core:1.36'
}


Expand Down

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions magictest/org/magicwerk/brownies/collections/Key2ListTest.ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,23 @@
<error></error>
</traceStep>
</traceTest>
<traceTest name="testRemoveAllByKey1">
<runDate>2023-05-26T14:11:17.469+02:00</runDate>
<runDuration>0.0065287</runDuration>
<exception></exception>
<traceClass>org.magicwerk.brownies.collections.Key2List</traceClass>
<traceMethod>removeAllByKey1</traceMethod>
<traceStep>
<description>
<paramText outputType="TEXT" param="Description">"removeAllByKey1"</paramText>
</description>
<parameters>
<paramText outputType="VALUE" param="#1">"\"A\""</paramText>
</parameters>
<result>
<paramText outputType="VALUE" param="Result">"{ \r\n [A, B1], \r\n [A, B2] \r\n}"</paramText>
</result>
<error></error>
</traceStep>
</traceTest>
</testClass>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,8 @@
</traceStep>
</traceTest>
<traceTest name="testKey">
<runDate>2015-01-10T18:10:57.777+01:00</runDate>
<runDuration>0.017870771</runDuration>
<runDate>2023-05-28T23:44:47.337+02:00</runDate>
<runDuration>0.059449499</runDuration>
<exception></exception>
<traceClass>org.magicwerk.brownies.collections.KeyCollection</traceClass>
<traceMethod>/.+/</traceMethod>
Expand Down Expand Up @@ -1139,6 +1139,62 @@
</result>
<error></error>
</traceStep>
<traceStep>
<description>
<paramText outputType="TEXT" param="Description">"add"</paramText>
</description>
<parameters>
<paramText outputType="VALUE" param="This">"{ \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="#1">"null"</paramText>
</parameters>
<result>
<paramText outputType="VALUE" param="This">"{ \r\n null, \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="Result">"true"</paramText>
</result>
<error></error>
</traceStep>
<traceStep>
<description>
<paramText outputType="TEXT" param="Description">"getCount"</paramText>
</description>
<parameters>
<paramText outputType="VALUE" param="This">"{ \r\n null, \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="#1">"null"</paramText>
</parameters>
<result>
<paramText outputType="VALUE" param="This">"{ \r\n null, \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="Result">"1"</paramText>
</result>
<error></error>
</traceStep>
<traceStep>
<description>
<paramText outputType="TEXT" param="Description">"add"</paramText>
</description>
<parameters>
<paramText outputType="VALUE" param="This">"{ \r\n null, \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="#1">"null"</paramText>
</parameters>
<result>
<paramText outputType="VALUE" param="This">"{ \r\n null, \r\n null, \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="Result">"true"</paramText>
</result>
<error></error>
</traceStep>
<traceStep>
<description>
<paramText outputType="TEXT" param="Description">"getCount"</paramText>
</description>
<parameters>
<paramText outputType="VALUE" param="This">"{ \r\n null, \r\n null, \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="#1">"null"</paramText>
</parameters>
<result>
<paramText outputType="VALUE" param="This">"{ \r\n null, \r\n null, \r\n b (0) \r\n}"</paramText>
<paramText outputType="VALUE" param="Result">"2"</paramText>
</result>
<error></error>
</traceStep>
<traceStep>
<description>
<text outputType="VALUE">"-- Sort --"</text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public static <E> BigList<E> create(Collection<? extends E> coll) {
* @return created list
* @param <E> type of elements stored in the list
*/
@SuppressWarnings("unchecked")
public static <E> BigList<E> create(E... elems) {
BigList<E> list = new BigList<E>();
if (elems != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/magicwerk/brownies/collections/GapList.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public static <E> GapList<E> create(Collection<? extends E> coll) {
public static <E> GapList<E> create(E... elems) {
GapList<E> list = new GapList<E>();
if (elems != null) {
if (elems != null) {
list.init(elems);
}
list.init(elems);
}
return list;
}
Expand Down Expand Up @@ -400,12 +398,14 @@ boolean isNormalized() {
*/
@SuppressWarnings("unchecked")
void init(Object[] values, int size) {
assert (size <= values.length);

this.values = (E[]) values;
this.size = size;

start = 0;
end = size;
if (end >= values.length) {
if (end == values.length) {
end -= values.length;
}
gapSize = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/magicwerk/brownies/collections/ICollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,18 @@ default int countIf(Predicate<? super E> predicate) {
*/
<R> IList<R> filterMap(Predicate<E> filter, Function<E, R> func);

/**
* Returns a copy of this collection with all its elements.
*
* @return a copy of this collection
*/
ICollection<E> copy();

/**
* Returns an empty copy of this collection.
*
* @return an empty copy of this collection
*/
ICollection<E> crop();

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.NoSuchElementException;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
* ICollectionTools offers default implementations of Collection functionality.
Expand Down Expand Up @@ -137,8 +138,8 @@ public static <E> int countIf(Collection<E> coll, Predicate<? super E> predicate
* @param predicate filter predicate
* @return created list
*/
public static <E> IList<E> filter(Collection<E> coll, Predicate<? super E> predicate) {
IList<E> list = GapList.create();
public static <E, C extends Collection<E>> C filter(Collection<E> coll, Predicate<? super E> predicate, Supplier<C> factory) {
C list = factory.get();
for (E e : coll) {
if (predicate.test(e)) {
list.add(e);
Expand All @@ -153,8 +154,8 @@ public static <E> IList<E> filter(Collection<E> coll, Predicate<? super E> predi
* @param func mapping function
* @return created list
*/
public static <E, R> IList<R> map(Collection<E> coll, Function<E, R> func) {
IList<R> list = GapList.create();
public static <E, R, C extends Collection<R>> C map(Collection<E> coll, Function<E, R> func, Supplier<C> factory) {
C list = factory.get();
for (E e : coll) {
list.add(func.apply(e));
}
Expand All @@ -169,7 +170,19 @@ public static <E, R> IList<R> map(Collection<E> coll, Function<E, R> func) {
* @return created list
*/
public static <E, R> IList<R> mapFilter(Collection<E> coll, Function<E, R> func, Predicate<R> filter) {
IList<R> list = GapList.create();
return mapFilter(coll, func, filter, GapList::new);
}

/**
* Create a new collection by applying the specified mapping function to all elements and then filtering it.
*
* @param func mapping function
* @param filter filter predicate
* @param factory factory to create collection
* @return created list
*/
public static <E, R, C extends Collection<R>> C mapFilter(Collection<E> coll, Function<E, R> func, Predicate<R> filter, Supplier<C> factory) {
C list = factory.get();
for (E e : coll) {
R r = func.apply(e);
if (filter.test(r)) {
Expand All @@ -186,8 +199,20 @@ public static <E, R> IList<R> mapFilter(Collection<E> coll, Function<E, R> func,
* @param func mapping function
* @return created list
*/
public static <E, R> IList<R> filterMap(Collection<E> coll, Predicate<E> filter, Function<E, R> func) {
IList<R> list = GapList.create();
public static <E, R, C extends Collection<R>> IList<R> filterMap(Collection<E> coll, Predicate<E> filter, Function<E, R> func) {
return filterMap(coll, filter, func, GapList::new);
}

/**
* Create a new collection by applying the specified filter first and then the mapping function to all elements selected.
*
* @param filter filter predicate
* @param func mapping function
* @param factory factory to create collection
* @return created list
*/
public static <E, R, C extends Collection<R>> C filterMap(Collection<E> coll, Predicate<E> filter, Function<E, R> func, Supplier<C> factory) {
C list = factory.get();
for (E e : coll) {
if (filter.test(e)) {
list.add(func.apply(e));
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/magicwerk/brownies/collections/IList.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static Object[] toArray(Collection<?> coll) {
*
* @return a modifiable copy of this list
*/
@Override
@SuppressWarnings("unchecked")
public IList<E> copy() {
return (IList<E>) clone();
Expand Down Expand Up @@ -110,6 +111,7 @@ public Object clone() {
*
* @return an empty copy of this list
*/
@Override
public IList<E> crop() {
return doCreate(0);
}
Expand Down Expand Up @@ -417,6 +419,7 @@ static int hashCodeElem(Object elem) {
* @param elem element to count
* @return count how many times the specified element is contained in the list
*/
// See java.util.Collections.frequency(Collection<?>, Object)
public int count(E elem) {
int count = 0;
int size = size();
Expand Down Expand Up @@ -1649,6 +1652,7 @@ public boolean addAll(int index, Collection<? extends E> coll) {
* @param elems elements to be added to this list
* @return <tt>true</tt> if this list changed as a result of the call
*/
@SuppressWarnings("unchecked")
public boolean addArray(E... elems) {
return doAddAll(-1, new IReadOnlyListFromArray<E>(elems));
}
Expand All @@ -1673,7 +1677,7 @@ public boolean addArray(int index, E[] elems, int offset, int length) {
* @return <tt>true</tt> if this list changed as a result of the call
* @throws IndexOutOfBoundsException if the index is invalid
*/
public boolean addArray(int index, E... elems) {
public boolean addArray(int index, @SuppressWarnings("unchecked") E... elems) {
checkIndexAdd(index);

return doAddAll(index, new IReadOnlyListFromArray<E>(elems));
Expand Down Expand Up @@ -1746,6 +1750,7 @@ public void setAll(int index, Collection<? extends E> coll) {
* @param elems array with elements to set
* @throws IndexOutOfBoundsException if the range is invalid
*/
@SuppressWarnings("unchecked")
public void setArray(int index, E... elems) {
int arrayLen = elems.length;
checkRange(index, arrayLen);
Expand Down Expand Up @@ -1821,6 +1826,7 @@ public void putAll(int index, Collection<? extends E> coll) {
* @param index index of first element to set or add
* @param elems array with elements to set or add
*/
@SuppressWarnings("unchecked")
public void putArray(int index, E... elems) {
putAll(index, new IReadOnlyListFromArray<E>(elems));
}
Expand Down Expand Up @@ -1876,6 +1882,7 @@ public void initAll(Collection<? extends E> coll) {
* @param elems array with elements
* @throws IndexOutOfBoundsException if the length is invalid
*/
@SuppressWarnings("unchecked")
public void initArray(E... elems) {
initAll(new IReadOnlyListFromArray<E>(elems));
}
Expand Down Expand Up @@ -1937,6 +1944,7 @@ public void replaceAll(int index, int len, Collection<? extends E> coll) {
* @param elems array with elements which replace the old elements, use null if elements should only be removed
* @throws IndexOutOfBoundsException if the range is invalid
*/
@SuppressWarnings("unchecked")
public void replaceArray(int index, int len, E... elems) {
replaceAll(index, len, new IReadOnlyListFromArray<E>(elems));
}
Expand Down
Loading

0 comments on commit 21526dd

Please sign in to comment.