Skip to content

Commit

Permalink
Merge branch 'release/4.30.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
astrapi69 committed Jun 25, 2018
2 parents bc116b3 + e8b2d3e commit 59c1ffd
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 17 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
## Change log
----------------------

Version 4.30.1
-------------

ADDED:

- new factory methods for create map objects with a given map
- new method isEqualListOfArrays in ListExtensions created

CHANGED:

- javadoc extended and improved

Version 4.30
-------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Than you can add the dependency to your dependencies:

...
<!-- SILLY-COLLECTIONS version -->
<silly-collections.version>4.30</silly-collections.version>
<silly-collections.version>4.30.1</silly-collections.version>
...
<dependencies>
...
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>silly-collections</artifactId>
<version>4.30</version>
<version>4.30.1</version>

<name>${project.artifactId}</name>

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/de/alpharogroup/collections/CollectionExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@ public static <T> boolean isEqualCollection(Collection<T> one, Collection<T> oth
{
return false;
}
return CollectionUtils.retainAll(one, other).isEmpty();
Collection<T> retainAll = CollectionUtils.retainAll(one, other);
return retainAll.isEmpty() || one.containsAll(other) && other.containsAll(one);
}

/**
* Difference.
* Removes all of the first given collection's elements that are also contained in the second
* given collection.
*
* @param <T>
* the generic type
* @param collection1
* the collection 1
* @param collection2
* the collection 2
* @param one
* the collection where the element will be removed if any containing elements exists
* @param other
* collection containing elements to be removed from the first given collection
*/
public static <T> void difference(final Collection<T> collection1,
final Collection<T> collection2)
public static <T> void difference(final Collection<T> one, final Collection<T> other)
{
// collection1.stream().filter(e -> !collection1.contains(e)).collect(Collectors.toSet());
collection1.removeAll(collection2);
one.removeAll(other);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/de/alpharogroup/collections/list/ListExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package de.alpharogroup.collections.list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -163,6 +164,39 @@ public static <T> List<T> getSameElementsFromLists(final List<T> toSearch, final
return foundElements;
}

/**
* Compare the given two {@link Collection} objects in equality.
*
* @param <T>
* the generic type of the elements
* @param one
* the one
* @param other
* the other
* @return true, if the given two {@link Collection} objects are equal otherwise false
*/
public static <T> boolean isEqualListOfArrays(List<T[]> one, List<T[]> other)
{
if (one == null && other == null)
{
return true;
}

if ((one == null && other != null) || one != null && other == null
|| one.size() != other.size())
{
return false;
}
for (int i = 0; i < one.size(); i++)
{
if (!Arrays.deepEquals(one.get(i), other.get(i)))
{
return false;
}
}
return true;
}

/**
* Checks if the given element is the first in the given list.
*
Expand Down
155 changes: 151 additions & 4 deletions src/main/java/de/alpharogroup/collections/map/MapFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ public static <K, V> Map<K, V> newInsertionOrderMap()
return new InsertionOrderMap<>();
}

/**
* Factory method for create a new {@link InsertionOrderMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param initialCapacity
* the initial capacity
*
* @return The new {@link InsertionOrderMap}.
*/
public static <K, V> Map<K, V> newInsertionOrderMap(final int initialCapacity)
{
return new InsertionOrderMap<>(initialCapacity);
}

/**
* Factory method for create a new {@link InsertionOrderMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param map
* the map
* @return The new {@link InsertionOrderMap}.
*/
public static <K, V> Map<K, V> newInsertionOrderMap(Map<K, V> map)
{
return new InsertionOrderMap<>(map);
}

/**
* Factory method for {@link java.util.Map} that acts like a javascript associative array.
*
Expand Down Expand Up @@ -108,6 +141,22 @@ public static <K, V> ConcurrentHashMap<K, V> newConcurrentHashMap()
return new ConcurrentHashMap<>();
}

/**
* Factory method for create a new {@link ConcurrentHashMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param map
* the map
* @return The new {@link ConcurrentHashMap}.
*/
public static <K, V> ConcurrentHashMap<K, V> newConcurrentHashMap(Map<K, V> map)
{
return new ConcurrentHashMap<>(map);
}

/**
* Factory method for create a new {@link ConcurrentHashMap}.
*
Expand Down Expand Up @@ -139,6 +188,22 @@ public static <K, V> Map<K, V> newHashMap()
return new HashMap<>();
}

/**
* Factory method for create a new {@link HashMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param map
* the map
* @return The new {@link HashMap}.
*/
public static <K, V> Map<K, V> newHashMap(Map<K, V> map)
{
return new HashMap<>(map);
}

/**
* Factory method for create a new {@link LinkedHashMap}.
*
Expand All @@ -154,6 +219,22 @@ public static <K, V> Map<K, V> newLinkedHashMap()
return new LinkedHashMap<>();
}

/**
* Factory method for create a new {@link LinkedHashMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param map
* the map
* @return The new {@link LinkedHashMap}.
*/
public static <K, V> Map<K, V> newLinkedHashMap(Map<K, V> map)
{
return new LinkedHashMap<>(map);
}

/**
* Factory method for create a new {@link LinkedHashMap}.
*
Expand Down Expand Up @@ -198,15 +279,14 @@ public static <K, V> Map<K, V> newHashMap(final int initialCapacity)
*
* @return The new {@link LazyMap}.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <K, V> Map<K, V> newLazyMap()
{
return LazyMap.lazyMap(new HashMap<K, V>(), new InstantiateFactory(HashMap.class));
return newLazyHashMap();
}

/**
* Factory method for create a new {@link LazyMap} from commons-collections4 that encapsulates a
* {@link TreeMap}.
* {@link HashMap}.
*
* @param <K>
* the generic type of the key
Expand All @@ -215,10 +295,61 @@ public static <K, V> Map<K, V> newLazyMap()
*
* @return The new {@link LazyMap}.
*/
public static <K, V> Map<K, V> newLazyHashMap()
{
return newLazyHashMap(new HashMap<K, V>());
}

/**
* Factory method for create a new {@link LazyMap} from commons-collections4 that encapsulates a
* {@link HashMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param map
* the map to initialize with it
* @return The new {@link LazyMap}.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <K, V> Map<K, V> newLazyHashMap(HashMap<K, V> map)
{
return LazyMap.lazyMap(map, new InstantiateFactory(HashMap.class));
}

/**
* Factory method for create a new {@link LazyMap} from commons-collections4 that encapsulates a
* {@link TreeMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
*
* @return The new {@link LazyMap}.
*/
public static <K, V> Map<K, V> newLazyTreeMap()
{
return LazyMap.lazyMap(new TreeMap<K, V>(), new InstantiateFactory(TreeMap.class));
return newLazyTreeMap(new TreeMap<K, V>());
}

/**
* Factory method for create a new {@link LazyMap} from commons-collections4 that encapsulates a
* {@link TreeMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param map
* the map
* @return The new {@link LazyMap}.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <K, V> Map<K, V> newLazyTreeMap(TreeMap<K, V> map)
{
return LazyMap.lazyMap(map, new InstantiateFactory(TreeMap.class));
}

/**
Expand Down Expand Up @@ -256,6 +387,22 @@ public static <K, V> Map<K, V> newTreeMap()
return new TreeMap<>();
}

/**
* Factory method for create a new {@link TreeMap}.
*
* @param <K>
* the generic type of the key
* @param <V>
* the generic type of the value
* @param map
* the map
* @return The new {@link TreeMap}.
*/
public static <K, V> Map<K, V> newTreeMap(Map<K, V> map)
{
return new TreeMap<>(map);
}

/**
* Factory method for create a new {@link TreeMap}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void testDifference()
@Test
public void testEqualCollections()
{
// TODO implement unit test cases...
boolean actual;
boolean expected;
String[] lineOne;
Expand Down
Loading

0 comments on commit 59c1ffd

Please sign in to comment.