use of java.util.ListIterator in project Lucee by lucee.
the class GatewayUtil method toCFML.
public static Object toCFML(List list) {
ListIterator it = list.listIterator();
int index;
while (it.hasNext()) {
index = it.nextIndex();
list.set(index, toCFML(it.next()));
}
return list;
}
use of java.util.ListIterator in project jPOS by jpos.
the class ISOMultiFieldPackager method unpack.
/**
* @param m - the ISOComponent to receive the value consumed from ...
* @param b - the byte[] holding the raw message
* @param offset - the current position within b.
*/
public int unpack(ISOComponent m, byte[] b, int offset) throws ISOException {
ListIterator i = possibles.listIterator();
while (i.hasNext()) {
try {
current = (ISOFieldPackager) i.next();
ISOField f = new ISOField();
int consumed = current.unpack(f, b, offset);
m.setValue(f.getValue());
return consumed;
} catch (ISOException eok) {
current = null;
}
}
throw new ISOException("unpack failed in List process!");
}
use of java.util.ListIterator in project jPOS by jpos.
the class ISOMultiFieldPackager method unpack.
/**
* Unpack the passed InputStream into an ISOComponent from our list of possibles.
* The InputStream *must* support mark!
*/
public void unpack(ISOComponent c, InputStream in) throws IOException, ISOException {
if (!in.markSupported()) {
throw new ISOException("InputStream passed to ISOMultFieldPackager *must* support the mark method.");
}
ListIterator i = possibles.listIterator();
// Save our position in the InputStream
in.mark(1024);
while (i.hasNext()) {
in.reset();
try {
// One of our possibles will succeed in it's unpack from this Stream.
current = (ISOFieldPackager) i.next();
current.unpack(c, in);
return;
} catch (ISOException eok) {
// This one failed.
current = null;
} catch (IOException eok) {
// This one failed.
current = null;
}
}
throw new ISOException("unpack failed to find a match in the possible List!");
}
use of java.util.ListIterator in project vcell by virtualcell.
the class ArrayUtils method iteratorBinarySearch.
private static int iteratorBinarySearch(List list, Object key) {
int low = 0;
int high = list.size() - 1;
ListIterator i = list.listIterator();
while (low <= high) {
int mid = (low + high) >> 1;
Object midVal = get(i, mid);
int cmp = ((Comparable) midVal).compareTo(key);
if (cmp < 0)
low = mid + 1;
else if (cmp > 0)
high = mid - 1;
else
// key found
return mid;
}
// key not found
return -(low + 1);
}
use of java.util.ListIterator in project vcell by virtualcell.
the class ListPolynomial method subtract.
public Polynomial subtract(Polynomial polynomial) {
if (polynomial.signum() == 0)
return this;
if (mutable) {
ListPolynomial q = (ListPolynomial) polynomial;
ListIterator it1 = content.listIterator(content.size());
ListIterator it2 = q.content.listIterator(q.content.size());
Term t1 = it1.hasPrevious() ? (Term) it1.previous() : null;
Term t2 = it2.hasPrevious() ? (Term) it2.previous() : null;
while (t2 != null) {
int c = t1 == null ? 1 : (t2 == null ? -1 : -ordering.compare(t1.monomial(), t2.monomial()));
if (c < 0) {
t1 = it1.hasPrevious() ? (Term) it1.previous() : null;
} else {
if (c > 0) {
if (t1 != null)
it1.next();
it1.add(t2.negate());
} else {
Term t = t1.subtract(t2);
if (t.signum() == 0)
it1.remove();
else
it1.set(t);
}
t1 = it1.hasPrevious() ? (Term) it1.previous() : null;
t2 = it2.hasPrevious() ? (Term) it2.previous() : null;
}
}
degree = degree(this);
sugar = Math.max(sugar, q.sugar);
normalized = false;
return this;
} else
return copy().subtract(polynomial);
}
Aggregations