Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.2 to 3.2.3 #85

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1c55d16
Bump maven-compiler-plugin from 3.8.1 to 3.11.0
dependabot[bot] Jun 7, 2023
ffba30f
Bump maven-surefire-plugin from 2.22.2 to 3.2.2
dependabot[bot] Jun 7, 2023
ac26d87
Bump junit-jupiter from 5.7.0 to 5.10.1
timandy Nov 28, 2023
4689e79
Bump jacoco-maven-plugin from 0.8.6 to 0.8.11
timandy Nov 28, 2023
42be49e
Add Index
timandy May 31, 2023
27f72c4
Add Range
timandy May 31, 2023
3c24f7f
Add constructor for Set
timandy Jun 1, 2023
67247bd
Add new feature
timandy Jun 2, 2023
694bdea
Remove unused method of Set
timandy Jun 2, 2023
9528afc
TestBase support array equals on sequenceEqual
timandy Jun 5, 2023
435233e
ChunkTest
timandy Jun 5, 2023
aafbe21
TestBase InfiniteRepeatEnumerator
timandy Jun 7, 2023
1504d8b
CountTest
timandy Jun 5, 2023
0fb89a2
DistinctByTest
timandy Jun 5, 2023
5f98768
TestBase add Repeat method
timandy Jun 7, 2023
2af259a
ElementAtOrDefaultTest
timandy Jun 7, 2023
1490806
ElementAtTest
timandy Jun 7, 2023
5046895
ExceptTest
timandy Jun 7, 2023
679cbdb
ExceptByTest
timandy Jun 7, 2023
3b23e61
IntersectByTest
timandy Jun 7, 2023
bd59993
UnionByTest
timandy Jun 7, 2023
86c8b50
FirstOrDefaultTest
timandy Jul 4, 2023
03033aa
LastOrDefaultTest
timandy Jul 4, 2023
4287278
SingleOrDefaultTest
timandy Jul 4, 2023
5755e53
Add default comparer for Float and Double
timandy Oct 8, 2023
dd3a480
MaxTest and MaxByTest
timandy Oct 8, 2023
90cb040
MinTest and MinByTest
timandy Oct 8, 2023
c28186e
SequenceEqualTest
timandy Oct 8, 2023
bde25ec
```SequenceEqualTest```
timandy Oct 8, 2023
e045c3d
添加 queue
timandy Oct 10, 2023
db22b96
替换 queue
timandy Oct 10, 2023
cdd4fec
优化 TakeRangeFromEndIterator
timandy Oct 10, 2023
544f521
takeTest
timandy Oct 10, 2023
e3dfcce
Fix testcase skip take support mutable source
timandy Nov 24, 2023
9685528
添加 toMap 重载, 重复 value 合并
timandy Mar 9, 2022
c855b7e
Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.2 to 3.2.3
dependabot[bot] Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -55,7 +55,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -64,12 +64,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.2.3</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<version>0.8.11</version>
<executions>
<execution>
<goals>
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/com/bestvike/Index.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.bestvike;

import com.bestvike.linq.exception.ExceptionArgument;
import com.bestvike.linq.exception.ThrowHelper;

/**
* Represent a type can be used to index a collection either from the start or the end.
* <p>
* <pre>
* {@code
* List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
* Integer lastElement = Linq.of(list).elementAt(Index.fromEnd(1)); // lastElement = 5
* }
* </pre>
* <p>
* Created by 许崇雷 on 2023-05-31.
*/
public final class Index {
public static final Index Start = new Index(0);
public static final Index End = new Index(~0);
private final int value;

// The following private constructors mainly created for perf reason to avoid the checks
private Index(int value) {
this.value = value;
}

public Index(int value, boolean fromEnd) {
if (value < 0)
ThrowHelper.throwArgumentOutOfRangeException(ExceptionArgument.value);
if (fromEnd) {
this.value = ~value;
} else {
this.value = value;
}
}

public static Index fromStart(int value) {
if (value < 0)
ThrowHelper.throwArgumentOutOfRangeException(ExceptionArgument.value);
return new Index(value);
}

public static Index fromEnd(int value) {
if (value < 0)
ThrowHelper.throwArgumentOutOfRangeException(ExceptionArgument.value);
return new Index(~value);
}

public int getValue() {
if (this.value < 0)
return ~this.value;
else
return this.value;
}

public boolean isFromEnd() {
return this.value < 0;
}

public int getOffset(int length) {
int offset = this.value;
if (this.isFromEnd()) {
offset += length + 1;
}
return offset;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Index) {
return this.value == ((Index) obj).value;
}
return false;
}

@Override
public int hashCode() {
return this.value;
}

@Override
@SuppressWarnings("MethodDoesntCallSuperMethod")
protected Index clone() {
return new Index(this.value);
}

@Override
public String toString() {
if (this.isFromEnd()) {
return this.toStringFromEnd();
}
return String.valueOf(this.value);
}

private String toStringFromEnd() {
return '^' + String.valueOf(this.getValue());
}
}
106 changes: 106 additions & 0 deletions src/main/java/com/bestvike/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.bestvike;

import com.bestvike.linq.exception.ExceptionArgument;
import com.bestvike.linq.exception.ThrowHelper;

/**
* Represent a range has start and end indexes.
* <p>
* <pre>
* {@code
* List<Integer> someArray = Arrays.asList(1, 2, 3, 4, 5);
* Integer[] subArray1 = Linq.of(someArray).take(Range.endAt(Index.fromStart(2))).toArray(Integer.class); // { 1, 2 }
* Integer[] subArray2 = Linq.of(someArray).take(Range.startAt(Index.fromStart(1))).toArray(Integer.class); // { 2, 3, 4, 5 }
* }
* </pre>
* <p>
* Created by 许崇雷 on 2023-05-31.
*/
public final class Range {
public static final Range All = new Range(Index.Start, Index.End);
private final Index start;
private final Index end;

public Range(Index start, Index end) {
if (start == null)
ThrowHelper.throwArgumentNullException(ExceptionArgument.start);
if (end == null)
ThrowHelper.throwArgumentNullException(ExceptionArgument.end);
this.start = start;
this.end = end;
}

public static Range startAt(Index start) {
return new Range(start, Index.End);
}

public static Range endAt(Index end) {
return new Range(Index.Start, end);
}

public Index getStart() {
return this.start;
}

public Index getEnd() {
return this.end;
}

public OffsetLength getOffsetAndLength(int length) {
int start;
Index startIndex = this.getStart();
if (startIndex.isFromEnd())
start = length - startIndex.getValue();
else
start = startIndex.getValue();

int end;
Index endIndex = this.getEnd();
if (endIndex.isFromEnd())
end = length - endIndex.getValue();
else
end = endIndex.getValue();

if (Integer.compareUnsigned(end, length) > 0 || Integer.compareUnsigned(start, end) > 0)
ThrowHelper.throwArgumentOutOfRangeException(ExceptionArgument.length);

return new OffsetLength(start, end - start);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Range) {
Range r = (Range) obj;
return this.start.equals(r.start) && this.end.equals(r.end);
}
return false;
}

@Override
public int hashCode() {
int h1 = this.start.hashCode();
int h2 = this.end.hashCode();
return (h1 << 5) + h1 ^ h2;
}

@Override
@SuppressWarnings("MethodDoesntCallSuperMethod")
protected Range clone() {
return new Range(this.start, this.end);
}

@Override
public String toString() {
return this.start.toString() + ".." + this.end.toString();
}

public static final class OffsetLength {
public final int Offset;
public final int Length;

public OffsetLength(int offset, int length) {
this.Offset = offset;
this.Length = length;
}
}
}
70 changes: 70 additions & 0 deletions src/main/java/com/bestvike/collections/generic/Comparer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public final class Comparer<T> implements Comparator<T> {
private static final Comparer<?> DEFAULT = new Comparer<>(null);
private static final Comparer<?> DEFAULT_INVARIANT = new Comparer<>(CultureInfo.getInvariantCulture());
private static final Comparator<Float> FLOAT = new FloatComparer();
private static final Comparator<Double> DOUBLE = new DoubleComparer();

private final Collator collator;

Expand All @@ -31,6 +33,14 @@ public static <T> Comparator<T> DefaultInvariant() {
return (Comparator<T>) DEFAULT_INVARIANT;
}

public static Comparator<Float> Float() {
return FLOAT;
}

public static Comparator<Double> Double() {
return DOUBLE;
}

public static <T> Comparator<T> create(Collator collator) {
if (collator == null)
ThrowHelper.throwArgumentNullException(ExceptionArgument.collator);
Expand Down Expand Up @@ -62,4 +72,64 @@ public int compare(T x, T y) {
ThrowHelper.throwImplementComparableException();
return 0;
}


private static final class FloatComparer implements Comparator<Float> {
@Override
public int compare(Float x, Float y) {
if (x != null) {
if (y != null)
return this.comparePrimitive(x, y);
return 1;
}
if (y != null)
return -1;
return 0;
}

private int comparePrimitive(float x, float y) {
if (x < y)
return -1;
if (x > y)
return 1;
if (x == y)
return 0;

// At least one of the values is NaN.
if (Float.isNaN(x))
return Float.isNaN(y) ? 0 : -1;
else // y is NaN.
return 1;
}
}


private static final class DoubleComparer implements Comparator<Double> {
@Override
public int compare(Double x, Double y) {
if (x != null) {
if (y != null)
return this.comparePrimitive(x, y);
return 1;
}
if (y != null)
return -1;
return 0;
}

private int comparePrimitive(double x, double y) {
if (x < y)
return -1;
if (x > y)
return 1;
if (x == y)
return 0;

// At least one of the values is NaN.
if (Double.isNaN(x))
return Double.isNaN(y) ? 0 : -1;
else // y is NaN.
return 1;
}
}
}
Loading