Skip to content
Merged
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
Next Next commit
Fixed array casts
  • Loading branch information
Damtev committed Sep 28, 2022
commit 58c15a2c8d4096ea0618d3c57c1c2dcc5eb6b43f
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.utbot.engine.overrides.collections;

import org.utbot.api.annotation.UtClassMock;
import org.utbot.api.mock.UtMock;
import org.utbot.engine.overrides.stream.UtStream;

import java.util.stream.Stream;
Expand All @@ -11,6 +12,8 @@ public interface Collection<E> extends java.util.Collection<E> {
@Override
default Stream<E> stream() {
Object[] data = toArray();
UtMock.disableClassCastExceptionCheck(data);

int size = data.length;

return new UtStream<>((E[]) data, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
public interface Stream<E> extends BaseStream<E, Stream<E>> {
@SuppressWarnings("unchecked")
static <E> java.util.stream.Stream<E> of(E element) {
Object[] data = new Object[1];
E[] data = (E[]) new Object[1];
data[0] = element;

return new UtStream<>((E[]) data, 1);
return new UtStream<>(data, 1);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Stream<E> filter(Predicate<? super E> predicate) {
preconditionCheckWithClosingStream();

int size = elementData.end;
Object[] filtered = new Object[size];
E[] filtered = (E[]) new Object[size];
int j = 0;
for (int i = 0; i < size; i++) {
E element = elementData.get(i);
Expand All @@ -126,7 +126,7 @@ public Stream<E> filter(Predicate<? super E> predicate) {
}
}

return new UtStream<>((E[]) filtered, j);
return new UtStream<>(filtered, j);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -230,7 +230,7 @@ public Stream<E> distinct() {
preconditionCheckWithClosingStream();

int size = elementData.end;
Object[] distinctElements = new Object[size];
E[] distinctElements = (E[]) new Object[size];
int distinctSize = 0;
for (int i = 0; i < size; i++) {
E element = elementData.get(i);
Expand Down Expand Up @@ -259,7 +259,7 @@ public Stream<E> distinct() {
}
}

return new UtStream<>((E[]) distinctElements, distinctSize);
return new UtStream<>(distinctElements, distinctSize);
}

// TODO choose the best sorting https://github.com/UnitTestBot/UTBotJava/issues/188
Expand Down