Search in sources :

Example 81 with SortedMap

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;
}
Also used : TimeLogEntry(net.sourceforge.processdash.log.time.TimeLogEntry) ChangeFlaggedTimeLogEntry(net.sourceforge.processdash.log.time.ChangeFlaggedTimeLogEntry) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) Iterator(java.util.Iterator) EventObject(java.util.EventObject) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 82 with SortedMap

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;
}
Also used : Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 83 with SortedMap

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;
}
Also used : TermOrder(edu.jas.poly.TermOrder) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) GenPolynomial(edu.jas.poly.GenPolynomial) BigRational(edu.jas.arith.BigRational) IComplex(org.matheclipse.core.interfaces.IComplex) FactorComplex(edu.jas.ufd.FactorComplex) Complex(edu.jas.poly.Complex) IAST(org.matheclipse.core.interfaces.IAST) FactorComplex(edu.jas.ufd.FactorComplex) GenPolynomialRing(edu.jas.poly.GenPolynomialRing) ComplexRing(edu.jas.poly.ComplexRing) SortedMap(java.util.SortedMap) ModLong(edu.jas.arith.ModLong) BigInteger(edu.jas.arith.BigInteger)

Example 84 with SortedMap

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;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 85 with SortedMap

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;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

SortedMap (java.util.SortedMap)228 Map (java.util.Map)174 TreeMap (java.util.TreeMap)115 HashMap (java.util.HashMap)66 NavigableMap (java.util.NavigableMap)33 ArrayList (java.util.ArrayList)31 Iterator (java.util.Iterator)31 Test (org.junit.Test)25 ImmutableMap (com.google.common.collect.ImmutableMap)21 IOException (java.io.IOException)20 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 JASIExpr (org.matheclipse.core.convert.JASIExpr)16 IExpr (org.matheclipse.core.interfaces.IExpr)16 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)14 File (java.io.File)14 Entry (java.util.Map.Entry)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)12 LinkedHashMap (java.util.LinkedHashMap)11