BetterLists 1.1 clean code with sonarlint
This commit is contained in:
@@ -4,7 +4,7 @@ An extension of the java.util.List interface which include some of the C# LINQ u
|
||||
|
||||
List classes are extended as well. (ArrayList -> BetterArrayList)
|
||||
|
||||
Current version v1.0
|
||||
Current version v1.1
|
||||
|
||||
Before BetterLists :
|
||||
```Java
|
||||
@@ -30,8 +30,29 @@ NOTE : Please note that, unlike C# LINQ, these functions are not optimized at lo
|
||||
|
||||
## Download
|
||||
|
||||
* [betterlists-1.0.jar](../../raw/master/download/betterlists-1.0.jar)
|
||||
* [betterlists-1.0-sources.jar](../../raw/master/download/betterlists-1.0-sources.jar)
|
||||
* [betterlists-1.1.jar](../../raw/master/download/betterlists-1.0.jar)
|
||||
|
||||
## Maven
|
||||
|
||||
You can use this project as a maven dependency with this :
|
||||
```XML
|
||||
<repositories>
|
||||
...
|
||||
<repository>
|
||||
<id>klemek.betterlists</id>
|
||||
<url>https://github.com/klemek/betterlists/raw/mvn-repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
...
|
||||
<dependencies>
|
||||
...
|
||||
<dependency>
|
||||
<groupId>klemek</groupId>
|
||||
<artifactId>betterlists</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
## All code examples
|
||||
### List
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,6 @@ package fr.klemek.betterlists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An extension of the java.util.ArrayList class which include some of the C#
|
||||
@@ -24,7 +23,7 @@ public class BetterArrayList<T> extends ArrayList<T> implements BetterList<T> {
|
||||
* - the collection whose elements are to be placed into this list
|
||||
*/
|
||||
public static <T> BetterArrayList<T> fromList(Collection<T> c) {
|
||||
return new BetterArrayList<T>(c);
|
||||
return new BetterArrayList<>(c);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +77,6 @@ public class BetterArrayList<T> extends ArrayList<T> implements BetterList<T> {
|
||||
*/
|
||||
@Override
|
||||
public BetterArrayList<T> subList(int fromIndex, int toIndex) {
|
||||
return (BetterArrayList<T>) ((List<T>) this).subList(fromIndex, toIndex);
|
||||
return (BetterArrayList<T>) this.subList(fromIndex, toIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package fr.klemek.betterlists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An extension of the java.util.LinkedList class which include some of the C#
|
||||
@@ -24,7 +23,7 @@ public class BetterLinkedList<T> extends LinkedList<T> implements BetterList<T>
|
||||
* - the collection whose elements are to be placed into this list
|
||||
*/
|
||||
public static <T> BetterLinkedList<T> fromList(Collection<T> c) {
|
||||
return new BetterLinkedList<T>(c);
|
||||
return new BetterLinkedList<>(c);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +67,7 @@ public class BetterLinkedList<T> extends LinkedList<T> implements BetterList<T>
|
||||
*/
|
||||
@Override
|
||||
public BetterLinkedList<T> subList(int fromIndex, int toIndex) {
|
||||
return (BetterLinkedList<T>) ((List<T>) this).subList(fromIndex, toIndex);
|
||||
return (BetterLinkedList<T>) this.subList(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.klemek.betterlists;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Function;
|
||||
@@ -82,7 +81,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* in the other.
|
||||
*/
|
||||
public default BetterList<T> exclusion(List<T> other) {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
for (T element : this)
|
||||
if (!other.contains(element))
|
||||
out.add(element);
|
||||
@@ -274,16 +273,9 @@ public interface BetterList<T> extends List<T> {
|
||||
* @return a List whose elements are sorted according to a key.
|
||||
*/
|
||||
public default <E extends Comparable<E>> BetterList<T> orderBy(Function<T, E> selector){
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
out.addAll(this);
|
||||
Collections.sort(out, new Comparator<T>() {
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return selector.apply(o1).compareTo(selector.apply(o2));
|
||||
}
|
||||
|
||||
});
|
||||
Collections.sort(out, (o1,o2) -> selector.apply(o1).compareTo(selector.apply(o2)));
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -294,16 +286,9 @@ public interface BetterList<T> extends List<T> {
|
||||
* @return a List whose elements are sorted according to a key.
|
||||
*/
|
||||
public default <E extends Comparable<E>> BetterList<T> orderByDescending(Function<T, E> selector){
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
out.addAll(this);
|
||||
Collections.sort(out, new Comparator<T>() {
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return selector.apply(o2).compareTo(selector.apply(o1));
|
||||
}
|
||||
|
||||
});
|
||||
Collections.sort(out, (o1,o2) -> selector.apply(o2).compareTo(selector.apply(o1)));
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -314,7 +299,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* reverse order.
|
||||
*/
|
||||
public default BetterList<T> reverse() {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>(this.size());
|
||||
for (T element : this)
|
||||
out.add(0, element);
|
||||
return out;
|
||||
@@ -331,7 +316,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* function on each element of the sequence.
|
||||
*/
|
||||
public default <E> BetterList<E> select(Function<T, E> selector) {
|
||||
BetterList<E> out = new BetterArrayList<E>();
|
||||
BetterList<E> out = new BetterArrayList<>();
|
||||
for (T element : this)
|
||||
out.add(selector.apply(element));
|
||||
return out;
|
||||
@@ -348,7 +333,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* index in the sequence.
|
||||
*/
|
||||
public default BetterList<T> skip(int count) {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
int n = 0;
|
||||
for (T element : this) {
|
||||
if (n >= count)
|
||||
@@ -369,7 +354,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* specified by predicate.
|
||||
*/
|
||||
public default BetterList<T> skipWhile(Function<T, Boolean> predicate) {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
boolean match = true;
|
||||
for (T element : this)
|
||||
if (!match || !predicate.apply(element)) {
|
||||
@@ -405,7 +390,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* of the input sequence.
|
||||
*/
|
||||
public default BetterList<T> take(int count) {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>(count);
|
||||
int n = 0;
|
||||
for (T element : this) {
|
||||
if (n < count)
|
||||
@@ -426,7 +411,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* the element at which the test no longer passes.
|
||||
*/
|
||||
public default BetterList<T> takeWhile(Function<T, Boolean> predicate) {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
for (T element : this)
|
||||
if (predicate.apply(element))
|
||||
out.add(element);
|
||||
@@ -445,7 +430,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* duplicates.
|
||||
*/
|
||||
public default BetterList<T> union(List<T> other) {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
for (T element : this)
|
||||
if (other.contains(element))
|
||||
out.add(element);
|
||||
@@ -461,7 +446,7 @@ public interface BetterList<T> extends List<T> {
|
||||
* condition.
|
||||
*/
|
||||
public default BetterList<T> where(Function<T, Boolean> predicate) {
|
||||
BetterList<T> out = new BetterArrayList<T>();
|
||||
BetterList<T> out = new BetterArrayList<>();
|
||||
for (T element : this)
|
||||
if (predicate.apply(element))
|
||||
out.add(element);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.klemek.betterlists;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
@@ -45,7 +44,7 @@ public class BetterStack<T> extends Stack<T> implements BetterList<T> {
|
||||
*/
|
||||
@Override
|
||||
public BetterStack<T> subList(int fromIndex, int toIndex) {
|
||||
return (BetterStack<T>) ((List<T>) this).subList(fromIndex, toIndex);
|
||||
return (BetterStack<T>) this.subList(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.klemek.betterlists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
@@ -24,7 +23,7 @@ public class BetterVector<T> extends Vector<T> implements BetterList<T> {
|
||||
* - the collection whose elements are to be placed into this vector
|
||||
*/
|
||||
public static <T> BetterVector<T> fromList(Collection<T> c) {
|
||||
return new BetterVector<T>(c);
|
||||
return new BetterVector<>(c);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +93,7 @@ public class BetterVector<T> extends Vector<T> implements BetterList<T> {
|
||||
*/
|
||||
@Override
|
||||
public BetterVector<T> subList(int fromIndex, int toIndex) {
|
||||
return (BetterVector<T>) ((List<T>) this).subList(fromIndex, toIndex);
|
||||
return (BetterVector<T>) this.subList(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user