Skip to main content
Sign in
Snippets Groups Projects
Commit e3d79bcd authored by Matthijs Brouwer's avatar Matthijs Brouwer
Browse files

replace ArrayUtils with java8 streams solutions

parent a9c5a8e9
Branches
No related tags found
No related merge requests found
Showing
with 48 additions and 39 deletions
...@@ -4,7 +4,6 @@ import java.util.Arrays; ...@@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import org.apache.commons.lang.ArrayUtils;
/** /**
* The Class MtasPosition. * The Class MtasPosition.
...@@ -74,8 +73,7 @@ public class MtasPosition { ...@@ -74,8 +73,7 @@ public class MtasPosition {
mtasPositionStart = list.first(); mtasPositionStart = list.first();
} else { } else {
mtasPositionType = POSITION_SET; mtasPositionType = POSITION_SET;
mtasPositionList = ArrayUtils mtasPositionList = list.stream().mapToInt(Number::intValue).toArray();
.toPrimitive(list.toArray(new Integer[list.size()]));
mtasPositionStart = list.first(); mtasPositionStart = list.first();
mtasPositionEnd = list.last(); mtasPositionEnd = list.last();
if (mtasPositionList.length == (1 + mtasPositionEnd if (mtasPositionList.length == (1 + mtasPositionEnd
...@@ -174,8 +172,7 @@ public class MtasPosition { ...@@ -174,8 +172,7 @@ public class MtasPosition {
list.add(p); list.add(p);
} }
} }
mtasPositionList = ArrayUtils mtasPositionList = list.stream().mapToInt(Number::intValue).toArray();
.toPrimitive(list.toArray(new Integer[list.size()]));
mtasPositionStart = list.first(); mtasPositionStart = list.first();
mtasPositionEnd = list.last(); mtasPositionEnd = list.last();
if (list.size() == 1) { if (list.size() == 1) {
...@@ -207,8 +204,7 @@ public class MtasPosition { ...@@ -207,8 +204,7 @@ public class MtasPosition {
SortedSet<Integer> list = new TreeSet<>(); SortedSet<Integer> list = new TreeSet<>();
list.add(position); list.add(position);
list.add(mtasPositionStart); list.add(mtasPositionStart);
mtasPositionList = ArrayUtils mtasPositionList = list.stream().mapToInt(Number::intValue).toArray();
.toPrimitive(list.toArray(new Integer[list.size()]));
mtasPositionStart = list.first(); mtasPositionStart = list.first();
mtasPositionEnd = list.last(); mtasPositionEnd = list.last();
} }
...@@ -227,8 +223,7 @@ public class MtasPosition { ...@@ -227,8 +223,7 @@ public class MtasPosition {
} }
list.add(position); list.add(position);
} }
mtasPositionList = ArrayUtils mtasPositionList = list.stream().mapToInt(Number::intValue).toArray();
.toPrimitive(list.toArray(new Integer[list.size()]));
mtasPositionStart = list.first(); mtasPositionStart = list.first();
mtasPositionEnd = list.last(); mtasPositionEnd = list.last();
if (list.size() == (1 + mtasPositionEnd - mtasPositionStart)) { if (list.size() == (1 + mtasPositionEnd - mtasPositionStart)) {
... ...
......
...@@ -13,7 +13,6 @@ import java.util.Set; ...@@ -13,7 +13,6 @@ import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.payloads.PayloadHelper; import org.apache.lucene.analysis.payloads.PayloadHelper;
...@@ -323,8 +322,7 @@ public abstract class MtasToken { ...@@ -323,8 +322,7 @@ public abstract class MtasToken {
* @param list the list * @param list the list
*/ */
final public void addPositions(Set<Integer> list) { final public void addPositions(Set<Integer> list) {
int[] positions = ArrayUtils int[] positions = list.stream().mapToInt(Number::intValue).toArray();
.toPrimitive(list.toArray(new Integer[list.size()]));
addPositions(positions); addPositions(positions);
} }
... ...
......
...@@ -46,7 +46,6 @@ import mtas.parser.function.util.MtasFunctionParserFunction; ...@@ -46,7 +46,6 @@ import mtas.parser.function.util.MtasFunctionParserFunction;
import mtas.parser.function.util.MtasFunctionParserFunctionDefault; import mtas.parser.function.util.MtasFunctionParserFunctionDefault;
import mtas.search.spans.util.MtasSpanQuery; import mtas.search.spans.util.MtasSpanQuery;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.lucene.spatial.prefix.PrefixTreeStrategy; import org.apache.lucene.spatial.prefix.PrefixTreeStrategy;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.locationtech.spatial4j.shape.Shape; import org.locationtech.spatial4j.shape.Shape;
...@@ -1406,7 +1405,7 @@ public class CodecComponent { ...@@ -1406,7 +1405,7 @@ public class CodecComponent {
String[] subBaseSortTypes = Arrays.copyOfRange(baseSortTypes, 1, baseSortTypes.length); String[] subBaseSortTypes = Arrays.copyOfRange(baseSortTypes, 1, baseSortTypes.length);
String[] subBaseSortDirections = Arrays.copyOfRange(baseSortDirections, 1, baseSortDirections.length); String[] subBaseSortDirections = Arrays.copyOfRange(baseSortDirections, 1, baseSortDirections.length);
Integer[] subNumbers = Arrays.copyOfRange(baseNumbers, 1, baseNumbers.length); Integer[] subNumbers = Arrays.copyOfRange(baseNumbers, 1, baseNumbers.length);
Integer[] subStarts = ArrayUtils.toObject(new int[subNumbers.length]); Integer[] subStarts = Arrays.stream(new int[subNumbers.length]).boxed().toArray(Integer[]::new);
dataCollector = DataCollector.getCollector(this.baseCollectorTypes[0], this.baseDataTypes[0], dataCollector = DataCollector.getCollector(this.baseCollectorTypes[0], this.baseDataTypes[0],
this.baseStatsTypes[0], this.baseStatsItems[0], this.baseSortTypes[0], this.baseSortDirections[0], 0, this.baseStatsTypes[0], this.baseStatsItems[0], this.baseSortTypes[0], this.baseSortDirections[0], 0,
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.SortedSet; import java.util.SortedSet;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -116,7 +116,8 @@ public class MtasDataDoubleAdvanced extends MtasDataAdvanced<Double, Double> { ...@@ -116,7 +116,8 @@ public class MtasDataDoubleAdvanced extends MtasDataAdvanced<Double, Double> {
public MtasDataCollector<?, ?> add(double[] values, int number) public MtasDataCollector<?, ?> add(double[] values, int number)
throws IOException { throws IOException {
MtasDataCollector<?, ?> dataCollector = add(false); MtasDataCollector<?, ?> dataCollector = add(false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Double[] objectValues = Arrays.stream(values).boxed().toArray(Double[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return dataCollector; return dataCollector;
} }
...@@ -181,7 +182,8 @@ public class MtasDataDoubleAdvanced extends MtasDataAdvanced<Double, Double> { ...@@ -181,7 +182,8 @@ public class MtasDataDoubleAdvanced extends MtasDataAdvanced<Double, Double> {
throws IOException { throws IOException {
if (key != null) { if (key != null) {
MtasDataCollector<?, ?> subCollector = add(key, false); MtasDataCollector<?, ?> subCollector = add(key, false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Double[] objectValues = Arrays.stream(values).boxed().toArray(Double[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return subCollector; return subCollector;
} else { } else {
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.SortedSet; import java.util.SortedSet;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -118,7 +118,8 @@ public class MtasDataDoubleBasic extends MtasDataBasic<Double, Double> { ...@@ -118,7 +118,8 @@ public class MtasDataDoubleBasic extends MtasDataBasic<Double, Double> {
public MtasDataCollector<?, ?> add(double[] values, int number) public MtasDataCollector<?, ?> add(double[] values, int number)
throws IOException { throws IOException {
MtasDataCollector<?, ?> dataCollector = add(false); MtasDataCollector<?, ?> dataCollector = add(false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Double[] objectValues = Arrays.stream(values).boxed().toArray(Double[]::new);
setValue(newCurrentPosition,objectValues, number,
newCurrentExisting); newCurrentExisting);
return dataCollector; return dataCollector;
} }
...@@ -196,7 +197,8 @@ public class MtasDataDoubleBasic extends MtasDataBasic<Double, Double> { ...@@ -196,7 +197,8 @@ public class MtasDataDoubleBasic extends MtasDataBasic<Double, Double> {
throws IOException { throws IOException {
if (key != null) { if (key != null) {
MtasDataCollector<?, ?> subCollector = add(key, false); MtasDataCollector<?, ?> subCollector = add(key, false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Double[] objectValues = Arrays.stream(values).boxed().toArray(Double[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return subCollector; return subCollector;
} else { } else {
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.SortedSet; import java.util.SortedSet;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -56,9 +56,11 @@ public class MtasDataDoubleFull extends MtasDataFull<Double, Double> { ...@@ -56,9 +56,11 @@ public class MtasDataDoubleFull extends MtasDataFull<Double, Double> {
*/ */
@Override @Override
protected MtasDataItemDoubleFull getItem(int i) { protected MtasDataItemDoubleFull getItem(int i) {
double[] primitiveList;
if (i >= 0 && i < size) { if (i >= 0 && i < size) {
primitiveList = Arrays.stream(fullValueList[i]).mapToDouble(Double::doubleValue).toArray();
return new MtasDataItemDoubleFull( return new MtasDataItemDoubleFull(
ArrayUtils.toPrimitive(fullValueList[i]), primitiveList,
hasSub() ? subCollectorListNextLevel[i] : null, getStatsItems(), hasSub() ? subCollectorListNextLevel[i] : null, getStatsItems(),
sortType, sortDirection, errorNumber[i], errorList[i], sortType, sortDirection, errorNumber[i], errorList[i],
sourceNumberList[i]); sourceNumberList[i]);
...@@ -114,7 +116,8 @@ public class MtasDataDoubleFull extends MtasDataFull<Double, Double> { ...@@ -114,7 +116,8 @@ public class MtasDataDoubleFull extends MtasDataFull<Double, Double> {
public MtasDataCollector<?, ?> add(double[] values, int number) public MtasDataCollector<?, ?> add(double[] values, int number)
throws IOException { throws IOException {
MtasDataCollector<?, ?> dataCollector = add(false); MtasDataCollector<?, ?> dataCollector = add(false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Double[] objectValues = Arrays.stream(values).boxed().toArray(Double[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return dataCollector; return dataCollector;
} }
...@@ -179,7 +182,8 @@ public class MtasDataDoubleFull extends MtasDataFull<Double, Double> { ...@@ -179,7 +182,8 @@ public class MtasDataDoubleFull extends MtasDataFull<Double, Double> {
throws IOException { throws IOException {
if (key != null) { if (key != null) {
MtasDataCollector<?, ?> subCollector = add(key, false); MtasDataCollector<?, ?> subCollector = add(key, false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Double[] objectValues = Arrays.stream(values).boxed().toArray(Double[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return subCollector; return subCollector;
} else { } else {
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
...@@ -7,7 +8,6 @@ import java.util.Objects; ...@@ -7,7 +8,6 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -36,7 +36,7 @@ public class MtasDataItemDoubleFull extends MtasDataItemFull<Double, Double> { ...@@ -36,7 +36,7 @@ public class MtasDataItemDoubleFull extends MtasDataItemFull<Double, Double> {
public MtasDataItemDoubleFull(double[] value, MtasDataCollector<?, ?> sub, public MtasDataItemDoubleFull(double[] value, MtasDataCollector<?, ?> sub,
Set<String> statsItems, String sortType, String sortDirection, Set<String> statsItems, String sortType, String sortDirection,
int errorNumber, Map<String, Integer> errorList, int sourceNumber) { int errorNumber, Map<String, Integer> errorList, int sourceNumber) {
super(ArrayUtils.toObject(value), sub, statsItems, sortType, sortDirection, super(Arrays.stream(value).boxed().toArray(Double[]::new), sub, statsItems, sortType, sortDirection,
errorNumber, errorList, new MtasDataDoubleOperations(), sourceNumber); errorNumber, errorList, new MtasDataDoubleOperations(), sourceNumber);
} }
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
...@@ -7,7 +8,6 @@ import java.util.Objects; ...@@ -7,7 +8,6 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -36,7 +36,7 @@ class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> { ...@@ -36,7 +36,7 @@ class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> {
public MtasDataItemLongFull(long[] value, MtasDataCollector<?, ?> sub, public MtasDataItemLongFull(long[] value, MtasDataCollector<?, ?> sub,
Set<String> statsItems, String sortType, String sortDirection, Set<String> statsItems, String sortType, String sortDirection,
int errorNumber, Map<String, Integer> errorList, int sourceNumber) { int errorNumber, Map<String, Integer> errorList, int sourceNumber) {
super(ArrayUtils.toObject(value), sub, statsItems, sortType, sortDirection, super(Arrays.stream(value).boxed().toArray(Long[]::new), sub, statsItems, sortType, sortDirection,
errorNumber, errorList, new MtasDataLongOperations(), sourceNumber); errorNumber, errorList, new MtasDataLongOperations(), sourceNumber);
} }
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.SortedSet; import java.util.SortedSet;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -88,7 +88,8 @@ public class MtasDataLongAdvanced extends MtasDataAdvanced<Long, Double> { ...@@ -88,7 +88,8 @@ public class MtasDataLongAdvanced extends MtasDataAdvanced<Long, Double> {
public MtasDataCollector<?, ?> add(long[] values, int number) public MtasDataCollector<?, ?> add(long[] values, int number)
throws IOException { throws IOException {
MtasDataCollector<?, ?> dataCollector = add(false); MtasDataCollector<?, ?> dataCollector = add(false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Long[] objectValues = Arrays.stream(values).boxed().toArray(Long[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return dataCollector; return dataCollector;
} }
...@@ -145,7 +146,8 @@ public class MtasDataLongAdvanced extends MtasDataAdvanced<Long, Double> { ...@@ -145,7 +146,8 @@ public class MtasDataLongAdvanced extends MtasDataAdvanced<Long, Double> {
throws IOException { throws IOException {
if (key != null) { if (key != null) {
MtasDataCollector<?, ?> subCollector = add(key, false); MtasDataCollector<?, ?> subCollector = add(key, false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Long[] objectValues = Arrays.stream(values).boxed().toArray(Long[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return subCollector; return subCollector;
} else { } else {
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.SortedSet; import java.util.SortedSet;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -87,7 +87,8 @@ public class MtasDataLongBasic extends MtasDataBasic<Long, Double> { ...@@ -87,7 +87,8 @@ public class MtasDataLongBasic extends MtasDataBasic<Long, Double> {
public MtasDataCollector<?, ?> add(long[] values, int number) public MtasDataCollector<?, ?> add(long[] values, int number)
throws IOException { throws IOException {
MtasDataCollector<?, ?> dataCollector = add(false); MtasDataCollector<?, ?> dataCollector = add(false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Long[] objectValues = Arrays.stream(values).boxed().toArray(Long[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return dataCollector; return dataCollector;
} }
...@@ -153,7 +154,8 @@ public class MtasDataLongBasic extends MtasDataBasic<Long, Double> { ...@@ -153,7 +154,8 @@ public class MtasDataLongBasic extends MtasDataBasic<Long, Double> {
throws IOException { throws IOException {
if (key != null) { if (key != null) {
MtasDataCollector<?, ?> subCollector = add(key, false); MtasDataCollector<?, ?> subCollector = add(key, false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Long[] objectValues = Arrays.stream(values).boxed().toArray(Long[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return subCollector; return subCollector;
} else { } else {
... ...
......
package mtas.codec.util.collector; package mtas.codec.util.collector;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.stream.Collectors;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil; import mtas.codec.util.CodecUtil;
/** /**
...@@ -55,8 +56,10 @@ public class MtasDataLongFull extends MtasDataFull<Long, Double> { ...@@ -55,8 +56,10 @@ public class MtasDataLongFull extends MtasDataFull<Long, Double> {
*/ */
@Override @Override
protected MtasDataItemLongFull getItem(int i) { protected MtasDataItemLongFull getItem(int i) {
long[] primitiveList;
if (i >= 0 && i < size) { if (i >= 0 && i < size) {
return new MtasDataItemLongFull(ArrayUtils.toPrimitive(fullValueList[i]), primitiveList = Arrays.stream(fullValueList[i]).mapToLong(Long::longValue).toArray();
return new MtasDataItemLongFull(primitiveList,
hasSub() ? subCollectorListNextLevel[i] : null, getStatsItems(), hasSub() ? subCollectorListNextLevel[i] : null, getStatsItems(),
sortType, sortDirection, errorNumber[i], errorList[i], sortType, sortDirection, errorNumber[i], errorList[i],
sourceNumberList[i]); sourceNumberList[i]);
...@@ -85,7 +88,8 @@ public class MtasDataLongFull extends MtasDataFull<Long, Double> { ...@@ -85,7 +88,8 @@ public class MtasDataLongFull extends MtasDataFull<Long, Double> {
public MtasDataCollector<?, ?> add(long[] values, int number) public MtasDataCollector<?, ?> add(long[] values, int number)
throws IOException { throws IOException {
MtasDataCollector<?, ?> dataCollector = add(false); MtasDataCollector<?, ?> dataCollector = add(false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Long[] objectValues = Arrays.stream(values).boxed().toArray(Long[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return dataCollector; return dataCollector;
} }
...@@ -142,7 +146,8 @@ public class MtasDataLongFull extends MtasDataFull<Long, Double> { ...@@ -142,7 +146,8 @@ public class MtasDataLongFull extends MtasDataFull<Long, Double> {
throws IOException { throws IOException {
if (key != null) { if (key != null) {
MtasDataCollector<?, ?> subCollector = add(key, false); MtasDataCollector<?, ?> subCollector = add(key, false);
setValue(newCurrentPosition, ArrayUtils.toObject(values), number, Long[] objectValues = Arrays.stream(values).boxed().toArray(Long[]::new);
setValue(newCurrentPosition, objectValues, number,
newCurrentExisting); newCurrentExisting);
return subCollector; return subCollector;
} else { } else {
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment