Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions docs/ops/doc/WritingYourOwnOpPackage.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ In this example, the two `OpDependency` Ops already exist within the SciJava Ops
class DoubleSumOp implements Function<double[], Double> {
public Double apply(final double[] inArray) {
double sum = 0;
for (double v : inArray) {
for (var v : inArray) {
sum += v;
}
return i;
Expand Down Expand Up @@ -318,7 +318,7 @@ class DoubleSumOp implements Function<double[], Double> {
// define total progress size
Progress.defineTotal(inArray.length);
double sum = 0;
for (double v : inArray) {
for (var v : inArray) {
sum += v;
// increment progress
Progress.update();
Expand Down Expand Up @@ -356,11 +356,10 @@ class DoubleMeanOp implements Function<double[], Double> {
public Double apply(final double[] inArray) {
// There's no significant work here, but we do have 2 subtasks.
Progress.defineTotal(0, 2);
final Double sum = sumOp.apply(inArray);
final var sum = sumOp.apply(inArray);
final Double size = sizeOp.apply(inArray);
return sum / size;
}
}

```

For best results, ensure your Op records Progress updates at a reasonable frequency. If too frequent, progress updates can detract from algorithm performance, and if too infrequent, they will be of little help to the user!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,25 @@ public ArrayType copyArray() {
/** Gets the current capacity of the backing array. */
@Override
public int capacity() {
final ArrayType array = getArray();
final var array = getArray();
return array == null ? 0 : Array.getLength(array);
}

@Override
public void ensureCapacity(final int minCapacity) {
final int oldCapacity = capacity();
final var oldCapacity = capacity();
if (minCapacity <= oldCapacity) return; // no need to grow

// grow the array by up to 50% (plus a small constant)
final int growth = Math.min(oldCapacity / 2 + 16, maximumGrowth);
final var growth = Math.min(oldCapacity / 2 + 16, maximumGrowth);
final int newCapacity;
if (growth > Integer.MAX_VALUE - oldCapacity) {
// growth would push array over the maximum array size
newCapacity = Integer.MAX_VALUE;
}
else newCapacity = oldCapacity + growth;
// ensure the array grows by at least the requested minimum capacity
final int newLength = Math.max(minCapacity, newCapacity);
final var newLength = Math.max(minCapacity, newCapacity);

// copy the data into a new array
setArray(copyArray(newLength));
Expand All @@ -158,7 +158,7 @@ public void ensureCapacity(final int minCapacity) {
*/
@Override
public void insert(final int index, final int count) {
int oldSize = size();
var oldSize = size();
if (index < 0 || index > oldSize) {
throw new ArrayIndexOutOfBoundsException("Invalid index value");
}
Expand All @@ -171,7 +171,7 @@ public void insert(final int index, final int count) {
}
setSize(oldSize + count);
if (index < oldSize) {
final ArrayType array = getArray();
final var array = getArray();
System.arraycopy(array, index, array, index + count, oldSize - index);
}
}
Expand All @@ -184,7 +184,7 @@ public void insert(final int index, final int count) {
*/
@Override
public void delete(final int index, final int count) {
int oldSize = size();
var oldSize = size();
if (index < 0 || index > oldSize) {
throw new ArrayIndexOutOfBoundsException("Invalid index value");
}
Expand All @@ -194,7 +194,7 @@ public void delete(final int index, final int count) {
}
setSize(oldSize - count);
if (index + count < oldSize) {
final ArrayType array = getArray();
final var array = getArray();
System.arraycopy(array, index + count, array, index, oldSize - index -
count);
}
Expand All @@ -212,7 +212,7 @@ public void delete(final int index, final int count) {

@Override
public BaseType remove(final int index) {
final BaseType removed = get(index);
final var removed = get(index);
delete(index, 1);
return removed;
}
Expand Down Expand Up @@ -251,8 +251,8 @@ protected void checkBounds(final int index) {

private ArrayType copyArray(final int newLength) {
@SuppressWarnings("unchecked")
final ArrayType copy = (ArrayType) Array.newInstance(type, newLength);
final ArrayType oldArray = getArray();
final var copy = (ArrayType) Array.newInstance(type, newLength);
final var oldArray = getArray();
if (oldArray != null) System.arraycopy(oldArray, 0, copy, 0, size());
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void addValue(final boolean value) {
}

public boolean removeValue(final boolean value) {
final int index = indexOf(value);
final var index = indexOf(value);
if (index < 0) return false;
delete(index, 1);
return true;
Expand All @@ -89,7 +89,7 @@ public boolean getValue(final int index) {

public boolean setValue(final int index, final boolean value) {
checkBounds(index);
final boolean oldValue = getValue(index);
final var oldValue = getValue(index);
array[index] = value;
return oldValue;
}
Expand All @@ -100,14 +100,14 @@ public void addValue(final int index, final boolean value) {
}

public int indexOf(final boolean value) {
for (int i = 0; i < size(); i++) {
for (var i = 0; i < size(); i++) {
if (array[i] == value) return i;
}
return -1;
}

public int lastIndexOf(final boolean value) {
for (int i = size() - 1; i >= 0; i--) {
for (var i = size() - 1; i >= 0; i--) {
if (array[i] == value) return i;
}
return -1;
Expand Down Expand Up @@ -186,7 +186,7 @@ public boolean remove(final Object o) {
// NB: Overridden for performance.
@Override
public boolean containsAll(final Collection<?> c) {
for (final Object o : c) {
for (final var o : c) {
if (!(o instanceof Boolean)) return false;
final boolean value = (Boolean) o;
if (indexOf(value) < 0) return false;
Expand All @@ -201,7 +201,7 @@ public boolean addAll(final int index,
{
if (c.isEmpty()) return false;
insert(index, c.size());
int i = index;
var i = index;
for (final boolean e : c) {
setValue(i++, e);
}
Expand All @@ -211,11 +211,11 @@ public boolean addAll(final int index,
// NB: Overridden for performance.
@Override
public boolean removeAll(final Collection<?> c) {
boolean changed = false;
for (final Object o : c) {
var changed = false;
for (final var o : c) {
if (!(o instanceof Boolean)) continue;
final boolean value = (Boolean) o;
final boolean result = removeValue(value);
final var result = removeValue(value);
if (result) changed = true;
}
return changed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void addValue(final byte value) {
}

public boolean removeValue(final byte value) {
final int index = indexOf(value);
final var index = indexOf(value);
if (index < 0) return false;
delete(index, 1);
return true;
Expand All @@ -88,7 +88,7 @@ public byte getValue(final int index) {

public byte setValue(final int index, final byte value) {
checkBounds(index);
final byte oldValue = getValue(index);
final var oldValue = getValue(index);
array[index] = value;
return oldValue;
}
Expand All @@ -99,14 +99,14 @@ public void addValue(final int index, final byte value) {
}

public int indexOf(final byte value) {
for (int i = 0; i < size(); i++) {
for (var i = 0; i < size(); i++) {
if (array[i] == value) return i;
}
return -1;
}

public int lastIndexOf(final byte value) {
for (int i = size() - 1; i >= 0; i--) {
for (var i = size() - 1; i >= 0; i--) {
if (array[i] == value) return i;
}
return -1;
Expand Down Expand Up @@ -185,7 +185,7 @@ public boolean remove(final Object o) {
// NB: Overridden for performance.
@Override
public boolean containsAll(final Collection<?> c) {
for (final Object o : c) {
for (final var o : c) {
if (!(o instanceof Byte)) return false;
final byte value = (Byte) o;
if (indexOf(value) < 0) return false;
Expand All @@ -198,7 +198,7 @@ public boolean containsAll(final Collection<?> c) {
public boolean addAll(final int index, final Collection<? extends Byte> c) {
if (c.isEmpty()) return false;
insert(index, c.size());
int i = index;
var i = index;
for (final byte e : c) {
setValue(i++, e);
}
Expand All @@ -208,11 +208,11 @@ public boolean addAll(final int index, final Collection<? extends Byte> c) {
// NB: Overridden for performance.
@Override
public boolean removeAll(final Collection<?> c) {
boolean changed = false;
for (final Object o : c) {
var changed = false;
for (final var o : c) {
if (!(o instanceof Byte)) continue;
final byte value = (Byte) o;
final boolean result = removeValue(value);
final var result = removeValue(value);
if (result) changed = true;
}
return changed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void addValue(final char value) {
}

public boolean removeValue(final char value) {
final int index = indexOf(value);
final var index = indexOf(value);
if (index < 0) return false;
delete(index, 1);
return true;
Expand All @@ -89,7 +89,7 @@ public char getValue(final int index) {

public char setValue(final int index, final char value) {
checkBounds(index);
final char oldValue = getValue(index);
final var oldValue = getValue(index);
array[index] = value;
return oldValue;
}
Expand All @@ -100,14 +100,14 @@ public void addValue(final int index, final char value) {
}

public int indexOf(final char value) {
for (int i = 0; i < size(); i++) {
for (var i = 0; i < size(); i++) {
if (array[i] == value) return i;
}
return -1;
}

public int lastIndexOf(final char value) {
for (int i = size() - 1; i >= 0; i--) {
for (var i = size() - 1; i >= 0; i--) {
if (array[i] == value) return i;
}
return -1;
Expand Down Expand Up @@ -186,7 +186,7 @@ public boolean remove(final Object o) {
// NB: Overridden for performance.
@Override
public boolean containsAll(final Collection<?> c) {
for (final Object o : c) {
for (final var o : c) {
if (!(o instanceof Character)) return false;
final char value = (Character) o;
if (indexOf(value) < 0) return false;
Expand All @@ -201,7 +201,7 @@ public boolean addAll(final int index,
{
if (c.isEmpty()) return false;
insert(index, c.size());
int i = index;
var i = index;
for (final char e : c) {
setValue(i++, e);
}
Expand All @@ -211,11 +211,11 @@ public boolean addAll(final int index,
// NB: Overridden for performance.
@Override
public boolean removeAll(final Collection<?> c) {
boolean changed = false;
for (final Object o : c) {
var changed = false;
for (final var o : c) {
if (!(o instanceof Character)) continue;
final char value = (Character) o;
final boolean result = removeValue(value);
final var result = removeValue(value);
if (result) changed = true;
}
return changed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void addValue(final double value) {
}

public boolean removeValue(final double value) {
final int index = indexOf(value);
final var index = indexOf(value);
if (index < 0) return false;
delete(index, 1);
return true;
Expand All @@ -88,7 +88,7 @@ public double getValue(final int index) {

public double setValue(final int index, final double value) {
checkBounds(index);
final double oldValue = getValue(index);
final var oldValue = getValue(index);
array[index] = value;
return oldValue;
}
Expand All @@ -99,14 +99,14 @@ public void addValue(final int index, final double value) {
}

public int indexOf(final double value) {
for (int i = 0; i < size(); i++) {
for (var i = 0; i < size(); i++) {
if (array[i] == value) return i;
}
return -1;
}

public int lastIndexOf(final double value) {
for (int i = size() - 1; i >= 0; i--) {
for (var i = size() - 1; i >= 0; i--) {
if (array[i] == value) return i;
}
return -1;
Expand Down Expand Up @@ -185,7 +185,7 @@ public boolean remove(final Object o) {
// NB: Overridden for performance.
@Override
public boolean containsAll(final Collection<?> c) {
for (final Object o : c) {
for (final var o : c) {
if (!(o instanceof Double)) return false;
final double value = (Double) o;
if (indexOf(value) < 0) return false;
Expand All @@ -198,7 +198,7 @@ public boolean containsAll(final Collection<?> c) {
public boolean addAll(final int index, final Collection<? extends Double> c) {
if (c.isEmpty()) return false;
insert(index, c.size());
int i = index;
var i = index;
for (final double e : c) {
setValue(i++, e);
}
Expand All @@ -208,11 +208,11 @@ public boolean addAll(final int index, final Collection<? extends Double> c) {
// NB: Overridden for performance.
@Override
public boolean removeAll(final Collection<?> c) {
boolean changed = false;
for (final Object o : c) {
var changed = false;
for (final var o : c) {
if (!(o instanceof Double)) continue;
final double value = (Double) o;
final boolean result = removeValue(value);
final var result = removeValue(value);
if (result) changed = true;
}
return changed;
Expand Down
Loading