Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Added resolving streams from arrays
  • Loading branch information
Damtev committed Sep 4, 2022
commit f3612cd2d59eb39ec7d8a8609047fb306daa4ee2
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import org.utbot.engine.overrides.collections.UtArrayList;

import java.util.List;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

@UtClassMock(target = java.util.Arrays.class, internalUsage = true)
public class Arrays {
// from docs - array is assumed to be umnodified during use
public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusive) {
int size = array.length;

Expand All @@ -18,7 +22,54 @@ public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusi
return new UtStream<>(array, startInclusive, endExclusive);
}

@SuppressWarnings({"unused", "varargs"})
// from docs - array is assumed to be umnodified during use
public static IntStream stream(int[] array, int startInclusive, int endExclusive) {
int size = array.length;

if (startInclusive < 0 || endExclusive < startInclusive || endExclusive > size) {
throw new ArrayIndexOutOfBoundsException();
}

Integer[] data = new Integer[size];
for (int i = 0; i < size; i++) {
data[i] = array[i];
}

return new UtIntStream(data, startInclusive, endExclusive);
}

// from docs - array is assumed to be umnodified during use
public static LongStream stream(long[] array, int startInclusive, int endExclusive) {
int size = array.length;

if (startInclusive < 0 || endExclusive < startInclusive || endExclusive > size) {
throw new ArrayIndexOutOfBoundsException();
}

Long[] data = new Long[size];
for (int i = 0; i < size; i++) {
data[i] = array[i];
}

return new UtLongStream(data, startInclusive, endExclusive);
}

// from docs - array is assumed to be umnodified during use
public static DoubleStream stream(double[] array, int startInclusive, int endExclusive) {
int size = array.length;

if (startInclusive < 0 || endExclusive < startInclusive || endExclusive > size) {
throw new ArrayIndexOutOfBoundsException();
}

Double[] data = new Double[size];
for (int i = 0; i < size; i++) {
data[i] = array[i];
}

return new UtDoubleStream(data, startInclusive, endExclusive);
}

@SafeVarargs
public static <T> List<T> asList(T... a) {
// TODO immutable collection https://github.com/UnitTestBot/UTBotJava/issues/398
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,11 @@
import org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray;
import org.utbot.engine.overrides.collections.UtArrayList;
import org.utbot.engine.overrides.collections.UtGenericStorage;
import org.utbot.engine.overrides.stream.actions.DistinctAction;
import org.utbot.engine.overrides.stream.actions.LimitAction;
import org.utbot.engine.overrides.stream.actions.NaturalSortingAction;
import org.utbot.engine.overrides.stream.actions.SkipAction;
import org.utbot.engine.overrides.stream.actions.StreamAction;
import org.utbot.engine.overrides.stream.actions.primitives.doubles.DoubleConsumerAction;
import org.utbot.engine.overrides.stream.actions.primitives.doubles.DoubleFilterAction;
import org.utbot.engine.overrides.stream.actions.primitives.doubles.DoubleMapAction;
import org.utbot.engine.overrides.stream.actions.primitives.doubles.DoubleToIntMapAction;
import org.utbot.engine.overrides.stream.actions.primitives.doubles.DoubleToLongMapAction;
import org.utbot.engine.overrides.stream.actions.primitives.doubles.DoubleToObjMapAction;

import java.util.Collection;
import java.util.DoubleSummaryStatistics;
import java.util.OptionalDouble;
import java.util.PrimitiveIterator;
import java.util.Spliterator;
import java.util.function.BiConsumer;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleConsumer;
import java.util.function.DoubleFunction;
import java.util.function.DoublePredicate;
import java.util.function.DoubleToIntFunction;
import java.util.function.DoubleToLongFunction;
import java.util.function.DoubleUnaryOperator;
import java.util.function.ObjDoubleConsumer;
import java.util.function.Supplier;
import org.utbot.engine.overrides.stream.actions.*;
import org.utbot.engine.overrides.stream.actions.primitives.doubles.*;

import java.util.*;
import java.util.function.*;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
Expand Down Expand Up @@ -62,6 +40,21 @@ public class UtDoubleStream implements DoubleStream, UtGenericStorage<Double> {
*/
private boolean isClosed = false;

/**
* Stores original array if this stream was created using
* {@link java.util.Arrays#stream)} or {@code of} or @code empty}
* method invocations (not from collection or another stream), and {@code null} otherwise.
* <p>
* Used only during resolving for creating stream assemble model.
*/
@SuppressWarnings("unused")
Object[] originArray;

/**
* {@code true} if this stream was created from primitive array, and false otherwise.
*/
boolean isCreatedFromPrimitiveArray;

public UtDoubleStream() {
this(new Double[]{}, 0, 0);
}
Expand All @@ -77,6 +70,9 @@ public UtDoubleStream(Double[] data, int length) {

public UtDoubleStream(Double[] data, int startInclusive, int endExclusive) {
this(new UtArrayList<>(data, startInclusive, endExclusive));

originArray = data;
isCreatedFromPrimitiveArray = true;
}

public UtDoubleStream(UtDoubleStream other) {
Expand All @@ -89,6 +85,9 @@ public UtDoubleStream(UtDoubleStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

@SuppressWarnings({"rawtypes", "unchecked"})
Expand All @@ -102,6 +101,9 @@ public UtDoubleStream(UtStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

public UtDoubleStream(UtIntStream other) {
Expand All @@ -114,6 +116,9 @@ public UtDoubleStream(UtIntStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

public UtDoubleStream(UtLongStream other) {
Expand All @@ -126,6 +131,9 @@ public UtDoubleStream(UtLongStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

@SuppressWarnings("rawtypes")
Expand All @@ -136,6 +144,9 @@ private UtDoubleStream(Collection collection) {
closeHandlers = new RangeModifiableUnlimitedArray<>();

origin = collection;

originArray = null;
isCreatedFromPrimitiveArray = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,25 @@ public class UtIntStream implements IntStream, UtGenericStorage<Integer> {
*/
private boolean isClosed = false;

/**
* Stores original array if this stream was created using
* {@link java.util.Arrays#stream)} or {@code of} or @code empty}
* method invocations (not from collection or another stream), and {@code null} otherwise.
*
* Used only during resolving for creating stream assemble model.
*/
@SuppressWarnings("unused")
Object[] originArray;

/**
* {@code true} if this stream was created from primitive array, and false otherwise.
*/
boolean isCreatedFromPrimitiveArray;

public UtIntStream() {
this(new Integer[]{}, 0, 0);

isCreatedFromPrimitiveArray = false;
}

@SuppressWarnings("unused")
Expand All @@ -79,6 +96,9 @@ public UtIntStream(Integer[] data, int length) {

public UtIntStream(Integer[] data, int startInclusive, int endExclusive) {
this(new UtArrayList<>(data, startInclusive, endExclusive));

originArray = data;
isCreatedFromPrimitiveArray = true;
}

public UtIntStream(UtIntStream other) {
Expand All @@ -91,6 +111,9 @@ public UtIntStream(UtIntStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

@SuppressWarnings({"rawtypes", "unchecked"})
Expand All @@ -104,6 +127,9 @@ public UtIntStream(UtStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

public UtIntStream(UtLongStream other) {
Expand All @@ -116,6 +142,9 @@ public UtIntStream(UtLongStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

public UtIntStream(UtDoubleStream other) {
Expand All @@ -128,6 +157,9 @@ public UtIntStream(UtDoubleStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

@SuppressWarnings("rawtypes")
Expand All @@ -138,6 +170,9 @@ private UtIntStream(Collection collection) {
closeHandlers = new RangeModifiableUnlimitedArray<>();

origin = collection;

originArray = null;
isCreatedFromPrimitiveArray = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,11 @@
import org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray;
import org.utbot.engine.overrides.collections.UtArrayList;
import org.utbot.engine.overrides.collections.UtGenericStorage;
import org.utbot.engine.overrides.stream.actions.DistinctAction;
import org.utbot.engine.overrides.stream.actions.LimitAction;
import org.utbot.engine.overrides.stream.actions.NaturalSortingAction;
import org.utbot.engine.overrides.stream.actions.SkipAction;
import org.utbot.engine.overrides.stream.actions.StreamAction;
import org.utbot.engine.overrides.stream.actions.primitives.longs.LongConsumerAction;
import org.utbot.engine.overrides.stream.actions.primitives.longs.LongFilterAction;
import org.utbot.engine.overrides.stream.actions.primitives.longs.LongMapAction;
import org.utbot.engine.overrides.stream.actions.primitives.longs.LongToDoubleMapAction;
import org.utbot.engine.overrides.stream.actions.primitives.longs.LongToIntMapAction;
import org.utbot.engine.overrides.stream.actions.primitives.longs.LongToObjMapAction;

import java.util.Collection;
import java.util.LongSummaryStatistics;
import java.util.OptionalDouble;
import java.util.OptionalLong;
import java.util.PrimitiveIterator;
import java.util.Spliterator;
import java.util.function.BiConsumer;
import java.util.function.LongBinaryOperator;
import java.util.function.LongConsumer;
import java.util.function.LongFunction;
import java.util.function.LongPredicate;
import java.util.function.LongToDoubleFunction;
import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator;
import java.util.function.ObjLongConsumer;
import java.util.function.Supplier;
import org.utbot.engine.overrides.stream.actions.*;
import org.utbot.engine.overrides.stream.actions.primitives.longs.*;

import java.util.*;
import java.util.function.*;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
Expand Down Expand Up @@ -64,6 +41,21 @@ public class UtLongStream implements LongStream, UtGenericStorage<Long> {
*/
private boolean isClosed = false;

/**
* Stores original array if this stream was created using
* {@link java.util.Arrays#stream)} or {@code of} or @code empty}
* method invocations (not from collection or another stream), and {@code null} otherwise.
* <p>
* Used only during resolving for creating stream assemble model.
*/
@SuppressWarnings("unused")
Object[] originArray;

/**
* {@code true} if this stream was created from primitive array, and false otherwise.
*/
boolean isCreatedFromPrimitiveArray;

public UtLongStream() {
this(new Long[]{}, 0, 0);
}
Expand All @@ -79,6 +71,9 @@ public UtLongStream(Long[] data, int length) {

public UtLongStream(Long[] data, int startInclusive, int endExclusive) {
this(new UtArrayList<>(data, startInclusive, endExclusive));

originArray = data;
isCreatedFromPrimitiveArray = true;
}

public UtLongStream(UtLongStream other) {
Expand All @@ -91,6 +86,9 @@ public UtLongStream(UtLongStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

@SuppressWarnings({"rawtypes", "unchecked"})
Expand All @@ -104,6 +102,9 @@ public UtLongStream(UtStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

public UtLongStream(UtIntStream other) {
Expand All @@ -116,6 +117,9 @@ public UtLongStream(UtIntStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

public UtLongStream(UtDoubleStream other) {
Expand All @@ -128,6 +132,9 @@ public UtLongStream(UtDoubleStream other) {

// new stream should be opened
isClosed = false;

originArray = other.originArray;
isCreatedFromPrimitiveArray = other.isCreatedFromPrimitiveArray;
}

@SuppressWarnings("rawtypes")
Expand All @@ -138,6 +145,9 @@ private UtLongStream(Collection collection) {
closeHandlers = new RangeModifiableUnlimitedArray<>();

origin = collection;

originArray = null;
isCreatedFromPrimitiveArray = false;
}

/**
Expand Down
Loading