Skip to content

Commit

Permalink
more trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarcaur committed Nov 22, 2024
1 parent 4efb2d2 commit d70b176
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ public static List<Double> newNonNullDoubleList(Iterable<Double> iterable) {

// This method modifies a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set
public static void addAllToDoubleList(Collection<Double> addTo, double[] elementsToAdd) {
if (addTo instanceof ConjureDoubleList) {
((ConjureDoubleList) addTo).addAll(elementsToAdd);
} else {
addAll(addTo, () -> Arrays.stream(elementsToAdd).iterator());
}
addAll(addTo, () -> Arrays.stream(elementsToAdd).iterator());
}

// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set
Expand All @@ -198,11 +194,7 @@ public static List<Integer> newNonNullIntegerList(Iterable<Integer> iterable) {

// This method modifies a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set
public static void addAllToIntegerList(Collection<Integer> addTo, int[] elementsToAdd) {
if (addTo instanceof ConjureIntegerList) {
((ConjureIntegerList) addTo).addAll(elementsToAdd);
} else {
addAll(addTo, () -> Arrays.stream(elementsToAdd).iterator());
}
addAll(addTo, () -> Arrays.stream(elementsToAdd).iterator());
}

/**
Expand Down Expand Up @@ -240,10 +232,6 @@ public static List<SafeLong> newNonNullSafeLongList(Iterable<SafeLong> iterable)

// This method modifies a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set
public static void addAllToSafeLongList(Collection<SafeLong> addTo, long[] elementsToAdd) {
if (addTo instanceof ConjureSafeLongList) {
((ConjureSafeLongList) addTo).addAll(elementsToAdd);
} else {
addAll(addTo, Arrays.stream(elementsToAdd).boxed().map(SafeLong::of).toList());
}
addAll(addTo, Arrays.stream(elementsToAdd).boxed().map(SafeLong::of).toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@

package com.palantir.conjure.java.lib.internal;

import com.fasterxml.jackson.annotation.JsonValue;
import java.util.AbstractList;
import java.util.Collection;
import java.util.RandomAccess;
import org.eclipse.collections.api.list.primitive.MutableDoubleList;
import org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList;
import org.eclipse.collections.impl.utility.Iterate;

/**
* ConjureDoubleList is a boxed list wrapper for the eclipse-collections DoubleArrayList. In eclipse-collections 12,
* a BoxedMutableDoubleList will be released. Once available, ConjureDoubleList should be replaced with that.
*/
final class ConjureDoubleList extends AbstractList<Double> implements RandomAccess {
private final MutableDoubleList delegate;
private final DoubleArrayList delegate;

ConjureDoubleList(MutableDoubleList delegate) {
ConjureDoubleList(DoubleArrayList delegate) {
this.delegate = delegate;
}

Expand All @@ -56,10 +55,6 @@ public boolean addAll(int index, Collection<? extends Double> collection) {
return delegate.addAllAtIndex(index, target);
}

public void addAll(double... source) {
this.delegate.addAll(source);
}

@Override
public Double remove(int index) {
return delegate.removeAtIndex(index);
Expand All @@ -74,15 +69,4 @@ public void clear() {
public Double set(int index, Double element) {
return delegate.set(index, element);
}

public ConjureDoubleList asUnmodifiable() {
return new ConjureDoubleList(delegate.asUnmodifiable());
}

// Cannot be named 'toArray' as that conflicts with the #toArray in AbstractList
// This is a serialization optimization that avoids boxing, but does copy
@JsonValue
double[] jacksonSerialize() {
return delegate.toArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@

package com.palantir.conjure.java.lib.internal;

import com.fasterxml.jackson.annotation.JsonValue;
import java.util.AbstractList;
import java.util.Collection;
import java.util.RandomAccess;
import org.eclipse.collections.api.list.primitive.MutableIntList;
import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList;
import org.eclipse.collections.impl.utility.Iterate;

/**
* ConjureIntegerList is a boxed list wrapper for the eclipse-collections IntArrayList. In eclipse-collections 12,
* a BoxedMutableIntList will be released. Once available, ConjureIntegerList should be replaced with that.
*/
final class ConjureIntegerList extends AbstractList<Integer> implements RandomAccess {
private final MutableIntList delegate;
private final IntArrayList delegate;

ConjureIntegerList(MutableIntList delegate) {
ConjureIntegerList(IntArrayList delegate) {
this.delegate = delegate;
}

Expand All @@ -56,10 +55,6 @@ public boolean addAll(int index, Collection<? extends Integer> collection) {
return delegate.addAllAtIndex(index, target);
}

public void addAll(int... source) {
this.delegate.addAll(source);
}

@Override
public Integer remove(int index) {
return delegate.removeAtIndex(index);
Expand All @@ -74,15 +69,4 @@ public void clear() {
public Integer set(int index, Integer element) {
return delegate.set(index, element);
}

public ConjureIntegerList asUnmodifiable() {
return new ConjureIntegerList(delegate.asUnmodifiable());
}

// Cannot be named 'toArray' as that conflicts with the #toArray in AbstractList
// This is a serialization optimization that avoids boxing, but does copy
@JsonValue
int[] jacksonSerialize() {
return delegate.toArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@

package com.palantir.conjure.java.lib.internal;

import com.fasterxml.jackson.annotation.JsonValue;
import com.palantir.conjure.java.lib.SafeLong;
import com.palantir.logsafe.Preconditions;
import java.util.AbstractList;
import java.util.Collection;
import java.util.RandomAccess;
import org.eclipse.collections.api.list.primitive.MutableLongList;
import org.eclipse.collections.impl.list.mutable.primitive.LongArrayList;
import org.eclipse.collections.impl.utility.Iterate;

/**
* ConjureSafeLongList is a boxed list wrapper for the eclipse-collections LongArrayList. This handles boxing/unboxing
* with SafeLongs.
*/
final class ConjureSafeLongList extends AbstractList<SafeLong> implements RandomAccess {
private final MutableLongList delegate;
private final LongArrayList delegate;

ConjureSafeLongList(MutableLongList delegate) {
ConjureSafeLongList(LongArrayList delegate) {
this.delegate = delegate;
}

Expand All @@ -58,18 +56,6 @@ public boolean addAll(int index, Collection<? extends SafeLong> collection) {
return delegate.addAllAtIndex(index, target);
}

public void addAll(long... source) {
for (long value : source) {
// Doesn't use SafeLong creation because this causes unnecessary boxing
// Mostly copied from SafeLong
Preconditions.checkArgument(
SafeLong.MIN_VALUE.longValue() <= value && value <= SafeLong.MAX_VALUE.longValue(),
"number must be safely representable in javascript i.e. "
+ "lie between -9007199254740991 and 9007199254740991");
}
this.delegate.addAll(source);
}

@Override
public SafeLong remove(int index) {
return SafeLong.of(delegate.removeAtIndex(index));
Expand All @@ -84,15 +70,4 @@ public void clear() {
public SafeLong set(int index, SafeLong element) {
return SafeLong.of(delegate.set(index, element.longValue()));
}

public ConjureSafeLongList asUnmodifiable() {
return new ConjureSafeLongList(delegate.asUnmodifiable());
}

// Cannot be named 'toArray' as that conflicts with the #toArray in AbstractList
// This is a serialization optimization that avoids boxing, but does copy
@JsonValue
long[] jacksonSerialize() {
return delegate.toArray();
}
}

0 comments on commit d70b176

Please sign in to comment.