use of java.util.SortedMap in project processdash by dtuma.
the class TimeLogEditor method collectTime.
private long collectTime(Object node, SortedMap timesIn, Map timesOut) {
// time for this node
long t = 0;
// child and add total time for this node.
for (int i = 0; i < treeModel.getChildCount(node); i++) {
t += collectTime(treeModel.getChild(node, i), timesIn, timesOut);
}
// fetch and add time spent in this node
Object[] treePath = treeModel.getPathToRoot((TreeNode) node);
PropertyKey key = treeModel.getPropKey(useProps, treePath);
if (key != null) {
String pathPrefix = key.path();
// For efficiency, we only search through the portion of the
// SortedMap which could contain paths matching our prefix.
// "Matching our prefix" means that it exactly equals our
// prefix, or it begins with our prefix followed by a slash.
// The character after the slash character is the zero '0'.
// So any string that is greater than that prefix can't match.
String endPrefix = pathPrefix + '0';
for (Iterator i = timesIn.subMap(pathPrefix, endPrefix).entrySet().iterator(); i.hasNext(); ) {
Map.Entry e = (Map.Entry) i.next();
String onePath = (String) e.getKey();
if (Filter.pathMatches(onePath, pathPrefix)) {
long[] l = (long[]) e.getValue();
if (l != null)
t += l[0];
i.remove();
}
}
}
timesOut.put(node, new Long(t));
return t;
}
use of java.util.SortedMap in project processdash by dtuma.
the class SizePerItemTable method getDefinedTables.
public static SortedMap<String, SizePerItemTable> getDefinedTables(DataRepository data, String sizeUnits) {
if (sizeUnits != null)
sizeUnits = sizeUnits.trim();
if (!StringUtils.hasValue(sizeUnits))
return new TreeMap();
SortedMap<String, SizePerItemTable> result = getDefinedTables(data);
for (Iterator i = result.entrySet().iterator(); i.hasNext(); ) {
Map.Entry e = (Map.Entry) i.next();
SizePerItemTable oneTable = (SizePerItemTable) e.getValue();
if (!oneTable.getSizeUnits().equalsIgnoreCase(sizeUnits))
i.remove();
}
return result;
}
use of java.util.SortedMap in project symja_android_library by axkr.
the class Algebra method factorComplex.
public static IAST factorComplex(GenPolynomial<BigRational> polyRat, JASConvert<BigRational> jas, List<IExpr> varList, ISymbol head, boolean noGCDLCM) {
TermOrder termOrder = TermOrderByName.Lexicographic;
// Object[] objects = jas.factorTerms(polyRat);
String[] vars = new String[varList.size()];
for (int i = 0; i < varList.size(); i++) {
vars[i] = varList.get(i).toString();
}
Object[] objects = JASConvert.rationalFromRationalCoefficientsFactor(new GenPolynomialRing<BigRational>(BigRational.ZERO, varList.size(), termOrder, vars), polyRat);
java.math.BigInteger gcd = (java.math.BigInteger) objects[0];
java.math.BigInteger lcm = (java.math.BigInteger) objects[1];
GenPolynomial<BigRational> poly = (GenPolynomial<BigRational>) objects[2];
ComplexRing<BigRational> cfac = new ComplexRing<BigRational>(BigRational.ZERO);
GenPolynomialRing<Complex<BigRational>> cpfac = new GenPolynomialRing<Complex<BigRational>>(cfac, 1, termOrder);
GenPolynomial<Complex<BigRational>> a = PolyUtil.complexFromAny(cpfac, poly);
FactorComplex<BigRational> factorAbstract = new FactorComplex<BigRational>(cfac);
SortedMap<GenPolynomial<Complex<BigRational>>, Long> map = factorAbstract.factors(a);
IAST result = F.ast(head);
if (!noGCDLCM) {
if (!gcd.equals(java.math.BigInteger.ONE) || !lcm.equals(java.math.BigInteger.ONE)) {
result.append(F.fraction(gcd, lcm));
}
}
GenPolynomial<Complex<BigRational>> temp;
for (SortedMap.Entry<GenPolynomial<Complex<BigRational>>, Long> entry : map.entrySet()) {
if (entry.getKey().isONE() && entry.getValue().equals(1L)) {
continue;
}
temp = entry.getKey();
result.append(F.Power(jas.complexPoly2Expr(entry.getKey()), F.integer(entry.getValue())));
}
return result;
}
use of java.util.SortedMap in project symja_android_library by axkr.
the class ExprPolynomial method subtractMultiple.
/**
* GenPolynomial subtract a multiple.
*
* @param a
* coefficient.
* @param S
* GenPolynomial.
* @return this - a S.
*/
public ExprPolynomial subtractMultiple(IExpr a, ExprPolynomial S) {
if (a == null || a.isZero()) {
return this;
}
if (S == null || S.isZero()) {
return this;
}
if (this.isZero()) {
return S.multiply(a.negate());
}
assert (ring.nvar == S.ring.nvar);
ExprPolynomial n = this.copy();
SortedMap<ExpVectorLong, IExpr> nv = n.val;
SortedMap<ExpVectorLong, IExpr> sv = S.val;
for (Map.Entry<ExpVectorLong, IExpr> me : sv.entrySet()) {
ExpVectorLong f = me.getKey();
// assert y != null
IExpr y = me.getValue();
y = a.multiply(y);
IExpr x = nv.get(f);
if (x != null) {
x = x.subtract(y);
if (!x.isZero()) {
nv.put(f, x);
} else {
nv.remove(f);
}
} else if (!y.isZero()) {
nv.put(f, y.negate());
}
}
return n;
}
use of java.util.SortedMap in project symja_android_library by axkr.
the class ExprPolynomial method subtract.
/**
* GenPolynomial subtraction.
*
* @param S
* GenPolynomial.
* @return this-S.
*/
public ExprPolynomial subtract(ExprPolynomial S) {
if (S == null) {
return this;
}
if (S.isZero()) {
return this;
}
if (this.isZero()) {
return S.negate();
}
assert (ring.nvar == S.ring.nvar);
// new GenPolynomial(ring, val);
ExprPolynomial n = this.copy();
SortedMap<ExpVectorLong, IExpr> nv = n.val;
SortedMap<ExpVectorLong, IExpr> sv = S.val;
for (Map.Entry<ExpVectorLong, IExpr> me : sv.entrySet()) {
ExpVectorLong e = me.getKey();
// sv.get(e); // assert y != null
IExpr y = me.getValue();
IExpr x = nv.get(e);
if (x != null) {
x = x.subtract(y);
if (!x.isZero()) {
nv.put(e, x);
} else {
nv.remove(e);
}
} else {
nv.put(e, y.negate());
}
}
return n;
}
Aggregations