if (a instanceof PArray) {
((UpdatablePArray) work1).fill(1.0);
} else if (a.elementType() == String.class) {
((UpdatableObjectArray<?>) work1).cast(String.class).fill("1");
} else {
((UpdatableObjectArray<?>) work1).cast(Circle.class).fill(new Circle(0, 0, 1));
}
if (desiredIndex != -1) {
if (a instanceof PArray) {
((UpdatablePArray) work1).setDouble(srcPos + desiredIndex, value);
} else if (a.elementType() == String.class) {
work1.setElement(srcPos + desiredIndex, "0");
} else {
work1.setElement(srcPos + desiredIndex, new Circle(0, 0, (int) value & 0xFFF));
// (int) & 0xFFF is necessary for MyCombinerPacked: it cannot support even large shorts
}
}
if (rnd.nextInt(3) == 0) {
sa = Arrays.asShifted(sa, 3); // checking AbstractXxxArray
if (desiredIndex != -1 && count > 0) {
desiredLastIndex = desiredIndex = (desiredIndex + 3) % count;
}
}
} else { // checking nXxxCopies
notFound = rnd.nextBoolean();
if (a instanceof PArray) {
sa = Arrays.nPCopies(count, a.elementType(), notFound ? 1.0 : value);
} else if (a.elementType() == String.class) {
sa = Arrays.nObjectCopies(count, notFound ? "1" : "0");
value = 0;
} else {
sa = Arrays.nObjectCopies(count,
notFound ? new Circle(1, 1, 1) : new Circle(0, 0, (int) value & 0xFFF));
// (int) & 0xFFF is necessary for MyCombinerPacked: it cannot support even large shorts
}
}
long index, indexSub, lastIndex, lastIndexSub, indexFixed, lastIndexFixed;
long indexReq = desiredIndex, lastIndexReq = desiredLastIndex;
long indexFixedReq = desiredIndex, lastIndexFixedReq = desiredLastIndex;
long low = -100, high = Long.MAX_VALUE;
if (rnd.nextBoolean()) {
low = -2 + rnd.nextInt((int) sa.length() + 4);
high = -2 + rnd.nextInt((int) sa.length() + 4);
} else if (rnd.nextInt(3) == 0) {
low = rnd.nextLong();
high = Long.MIN_VALUE; // dangerous case!
}
long corLow = Math.max(low, 0);
long corHigh = Math.min(high, sa.length());
if (Arrays.isNCopies(sa)) {
if (low >= high || low >= sa.length() || high <= 0 || sa.length() == 0) {
notFound = true;
}
indexReq = indexFixedReq = desiredIndex = notFound ? -1 :
Math.max(0, (int) low);
lastIndexReq = lastIndexFixedReq = desiredLastIndex = notFound ? -1 :
(int) Math.min(sa.length(), high) - 1;
} else {
if (desiredIndex < low || desiredIndex >= high) {
indexReq = indexFixedReq = -1;
}
if (desiredLastIndex < low || desiredLastIndex >= high) {
lastIndexReq = lastIndexFixedReq = -1;
}
}
if (a instanceof PArray) {
// desired index may differ from actual index due to rounding
index = ((PArray) sa).indexOf(low, high, value);
indexSub = corLow >= corHigh ? -1 :
((PArray) sa.subArray(corLow, corHigh)).indexOf(0, corHigh - corLow, value);
if (indexSub != -1)
indexSub += corLow;
indexReq = -1;
for (long k = corLow, n = corHigh; k < n; k++) {
if (((PArray) sa).getDouble(k) == value) {
indexReq = k;
break;
}
}
lastIndex = ((PArray) sa).lastIndexOf(low, high, value);
lastIndexSub = corLow >= corHigh ? -1 :
((PArray) sa.subArray(corLow, corHigh)).lastIndexOf(0, corHigh - corLow, value);
if (lastIndexSub != -1)
lastIndexSub += corLow;
lastIndexReq = -1;
for (long k = corHigh; k > corLow; ) {
if (((PArray) sa).getDouble(--k) == value) {
lastIndexReq = k;
break;
}
}
indexFixed = index;
lastIndexFixed = lastIndex;
indexFixedReq = indexReq;
lastIndexFixedReq = lastIndexReq;
if (a instanceof PFixedArray) {
indexFixed = ((PFixedArray) sa).indexOf(low, high, (long) value);
lastIndexFixed = ((PFixedArray) sa).lastIndexOf(low, high, (long) value);
indexFixedReq = -1;
for (long k = Math.max(low, 0), n = Math.min(high, sa.length()); k < n; k++) {
if (((PFixedArray) sa).getLong(k) == (long) value) {
indexFixedReq = k;
break;
}
}
lastIndexFixedReq = -1;
for (long k = Math.min(sa.length(), high); k > Math.max(low, 0); ) {
if (((PFixedArray) sa).getLong(--k) == (long) value) {
lastIndexFixedReq = k;
break;
}
}
}
} else if (a.elementType() == String.class) {
index = ((ObjectArray<?>) sa).cast(String.class).indexOf(low, high, "0");
indexSub = corLow >= corHigh ? -1 :
((ObjectArray<?>) sa.subArray(corLow, corHigh)).cast(String.class)
.indexOf(0, corHigh - corLow, "0");
if (indexSub != -1)
indexSub += corLow;
lastIndex = ((ObjectArray<?>) sa).cast(String.class).lastIndexOf(low, high, "0");
lastIndexSub = corLow >= corHigh ? -1 :
((ObjectArray<?>) sa.subArray(corLow, corHigh)).cast(String.class)
.lastIndexOf(0, corHigh - corLow, "0");
if (lastIndexSub != -1)
lastIndexSub += corLow;
indexFixed = index;
lastIndexFixed = lastIndex;
} else {
Circle zero = new Circle(0, 0, (int) value & 0xFFF);
index = ((ObjectArray<?>) sa).cast(Circle.class).indexOf(low, high, zero);
indexSub = corLow >= corHigh ? -1 :
((ObjectArray<?>) sa.subArray(corLow, corHigh)).cast(Circle.class)
.indexOf(0, Long.MAX_VALUE, zero);
if (indexSub != -1)