Search in sources :

Example 61 with SortedMap

use of java.util.SortedMap in project geode by apache.

the class TableConverter method toNonNullOpenValue.

Object toNonNullOpenValue(Object value) throws OpenDataException {
    final Map<Object, Object> valueMap = (Map<Object, Object>) value;
    if (valueMap instanceof SortedMap) {
        Comparator comparator = ((SortedMap) valueMap).comparator();
        if (comparator != null) {
            final String msg = "Cannot convert SortedMap with non-null comparator: " + comparator;
            IllegalArgumentException iae = new IllegalArgumentException(msg);
            OpenDataException ode = new OpenDataException(msg);
            ode.initCause(iae);
            throw ode;
        }
    }
    final TabularType tabularType = (TabularType) getOpenType();
    final TabularData table = new TabularDataSupport(tabularType);
    final CompositeType rowType = tabularType.getRowType();
    for (Map.Entry entry : valueMap.entrySet()) {
        final Object openKey = keyConverter.toOpenValue(entry.getKey());
        final Object openValue = valueConverter.toOpenValue(entry.getValue());
        final CompositeData row;
        row = new CompositeDataSupport(rowType, keyValueArray, new Object[] { openKey, openValue });
        table.put(row);
    }
    return table;
}
Also used : TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Comparator(java.util.Comparator) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) SortedMap(java.util.SortedMap) Map(java.util.Map) SortedMap(java.util.SortedMap) CompositeType(javax.management.openmbean.CompositeType)

Example 62 with SortedMap

use of java.util.SortedMap in project sling by apache.

the class SlingTldLocationsCache method printConfiguration.

public void printConfiguration(final PrintWriter pw) {
    pw.println("Currently available JSP Taglibs:");
    final SortedMap<String, String> taglibs = new TreeMap<String, String>();
    for (final Map.Entry<String, TldLocationEntry> entry : tldLocations.entrySet()) {
        final long bundleId = entry.getValue().getBundleId();
        final Bundle bundle = bundleContext.getBundle(bundleId);
        if (bundle != null) {
            taglibs.put(entry.getKey(), String.format("%s (%s)", bundle.getSymbolicName(), bundleId));
        } else {
            // really shouldn't happen
            taglibs.put(entry.getKey(), String.format("INVALID BUNDLE ID: %s", bundleId));
        }
    }
    for (final Map.Entry<String, String> entry : taglibs.entrySet()) {
        pw.printf("  %s - %s\n", entry.getKey(), entry.getValue());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 63 with SortedMap

use of java.util.SortedMap in project sling by apache.

the class MetricWebConsolePlugin method addMeterDetails.

private void addMeterDetails(PrintWriter pw, SortedMap<String, Meter> meters) {
    if (meters.isEmpty()) {
        return;
    }
    pw.println("<br>");
    pw.println("<div class='table'>");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Meters</div>");
    pw.println("<table class='nicetable' id='data-meters'>");
    pw.println("<thead>");
    pw.println("<tr>");
    pw.println("<th class='header'>Name</th>");
    pw.println("<th class='header'>Count</th>");
    pw.println("<th class='header'>Mean Rate</th>");
    pw.println("<th class='header'>OneMinuteRate</th>");
    pw.println("<th class='header'>FiveMinuteRate</th>");
    pw.println("<th class='header'>FifteenMinuteRate</ th>");
    pw.println("<th>RateUnit</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody>");
    String rowClass = "odd";
    for (Map.Entry<String, Meter> e : meters.entrySet()) {
        Meter m = e.getValue();
        String name = e.getKey();
        double rateFactor = timeUnit.rateFor(name).toSeconds(1);
        String rateUnit = "events/" + calculateRateUnit(timeUnit.rateFor(name));
        pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
        pw.printf("<td>%s</td>", name);
        pw.printf("<td>%d</td>", m.getCount());
        pw.printf("<td>%f</td>", m.getMeanRate() * rateFactor);
        pw.printf("<td>%f</td>", m.getOneMinuteRate() * rateFactor);
        pw.printf("<td>%f</td>", m.getFiveMinuteRate() * rateFactor);
        pw.printf("<td>%f</td>", m.getFifteenMinuteRate() * rateFactor);
        pw.printf("<td>%s</td>", rateUnit);
        pw.println("</tr>");
        rowClass = "odd".equals(rowClass) ? "even" : "odd";
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("</div>");
}
Also used : Meter(com.codahale.metrics.Meter) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap)

Example 64 with SortedMap

use of java.util.SortedMap in project sling by apache.

the class MetricWebConsolePlugin method addTimerDetails.

private void addTimerDetails(PrintWriter pw, SortedMap<String, Timer> timers) {
    if (timers.isEmpty()) {
        return;
    }
    pw.println("<br>");
    pw.println("<div class='table'>");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Timers</div>");
    pw.println("<table class='nicetable' id='data-timers'>");
    pw.println("<thead>");
    pw.println("<tr>");
    pw.println("<th class='header'>Name</th>");
    pw.println("<th class='header'>Count</th>");
    pw.println("<th class='header'>Mean Rate</th>");
    pw.println("<th class='header'>1 min rate</th>");
    pw.println("<th class='header'>5 mins rate</th>");
    pw.println("<th class='header'>15 mins rate</th>");
    pw.println("<th class='header'>50%</th>");
    pw.println("<th class='header'>Min</th>");
    pw.println("<th class='header'>Max</th>");
    pw.println("<th class='header'>Mean</th>");
    pw.println("<th class='header'>StdDev</th>");
    pw.println("<th class='header'>75%</th>");
    pw.println("<th class='header'>95%</th>");
    pw.println("<th class='header'>98%</th>");
    pw.println("<th class='header'>99%</th>");
    pw.println("<th class='header'>999%</th>");
    pw.println("<th>Rate Unit</th>");
    pw.println("<th>Duration Unit</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody>");
    String rowClass = "odd";
    for (Map.Entry<String, Timer> e : timers.entrySet()) {
        Timer t = e.getValue();
        Snapshot s = t.getSnapshot();
        String name = e.getKey();
        double rateFactor = timeUnit.rateFor(name).toSeconds(1);
        String rateUnit = "events/" + calculateRateUnit(timeUnit.rateFor(name));
        double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1);
        String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US);
        pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
        pw.printf("<td>%s</td>", name);
        pw.printf("<td>%d</td>", t.getCount());
        pw.printf("<td>%f</td>", t.getMeanRate() * rateFactor);
        pw.printf("<td>%f</td>", t.getOneMinuteRate() * rateFactor);
        pw.printf("<td>%f</td>", t.getFiveMinuteRate() * rateFactor);
        pw.printf("<td>%f</td>", t.getFifteenMinuteRate() * rateFactor);
        pw.printf("<td>%f</td>", s.getMedian() * durationFactor);
        pw.printf("<td>%f</td>", s.getMin() * durationFactor);
        pw.printf("<td>%f</td>", s.getMax() * durationFactor);
        pw.printf("<td>%f</td>", s.getMean() * durationFactor);
        pw.printf("<td>%f</td>", s.getStdDev() * durationFactor);
        pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor);
        pw.printf("<td>%s</td>", rateUnit);
        pw.printf("<td>%s</td>", durationUnit);
        pw.println("</tr>");
        rowClass = "odd".equals(rowClass) ? "even" : "odd";
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("</div>");
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Timer(com.codahale.metrics.Timer) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap)

Example 65 with SortedMap

use of java.util.SortedMap in project poi by apache.

the class XSSFSheet method shiftRows.

/**
     * Shifts rows between startRow and endRow n number of rows.
     * If you use a negative number, it will shift rows up.
     * Code ensures that rows don't wrap around
     *
     * <p>
     * Additionally shifts merged regions that are completely defined in these
     * rows (ie. merged 2 cells on a row to be shifted). All merged regions that are
     * completely overlaid by shifting will be deleted.
     * <p>
     * @param startRow the row to start shifting
     * @param endRow the row to end shifting
     * @param n the number of rows to shift
     * @param copyRowHeight whether to copy the row height during the shift
     * @param resetOriginalRowHeight whether to set the original row's height to the default
     */
@Override
public void shiftRows(int startRow, int endRow, final int n, boolean copyRowHeight, boolean resetOriginalRowHeight) {
    XSSFVMLDrawing vml = getVMLDrawing(false);
    // first remove all rows which will be overwritten
    for (Iterator<Row> it = rowIterator(); it.hasNext(); ) {
        XSSFRow row = (XSSFRow) it.next();
        int rownum = row.getRowNum();
        // check if we should remove this row as it will be overwritten by the data later
        if (shouldRemoveRow(startRow, endRow, n, rownum)) {
            // remove row from worksheet.getSheetData row array
            // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
            // NOSONAR
            final Integer rownumI = new Integer(row.getRowNum());
            int idx = _rows.headMap(rownumI).size();
            worksheet.getSheetData().removeRow(idx);
            // remove row from _rows
            it.remove();
            // also remove any comments associated with this row
            if (sheetComments != null) {
                CTCommentList lst = sheetComments.getCTComments().getCommentList();
                for (CTComment comment : lst.getCommentArray()) {
                    String strRef = comment.getRef();
                    CellAddress ref = new CellAddress(strRef);
                    // is this comment part of the current row?
                    if (ref.getRow() == rownum) {
                        sheetComments.removeComment(ref);
                        vml.removeCommentShape(ref.getRow(), ref.getColumn());
                    }
                }
            }
            // also remove any hyperlinks associated with this row
            if (hyperlinks != null) {
                for (XSSFHyperlink link : new ArrayList<XSSFHyperlink>(hyperlinks)) {
                    CellReference ref = new CellReference(link.getCellRef());
                    if (ref.getRow() == rownum) {
                        hyperlinks.remove(link);
                    }
                }
            }
        }
    }
    // then do the actual moving and also adjust comments/rowHeight
    // we need to sort it in a way so the shifting does not mess up the structures, 
    // i.e. when shifting down, start from down and go up, when shifting up, vice-versa
    SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<XSSFComment, Integer>(new Comparator<XSSFComment>() {

        @Override
        public int compare(XSSFComment o1, XSSFComment o2) {
            int row1 = o1.getRow();
            int row2 = o2.getRow();
            if (row1 == row2) {
                // get multiple comments per row into the map
                return o1.hashCode() - o2.hashCode();
            }
            // when shifting down, sort higher row-values first
            if (n > 0) {
                return row1 < row2 ? 1 : -1;
            } else {
                // sort lower-row values first when shifting up
                return row1 > row2 ? 1 : -1;
            }
        }
    });
    for (Iterator<Row> it = rowIterator(); it.hasNext(); ) {
        XSSFRow row = (XSSFRow) it.next();
        int rownum = row.getRowNum();
        if (sheetComments != null) {
            // calculate the new rownum
            int newrownum = shiftedRowNum(startRow, endRow, n, rownum);
            // is there a change necessary for the current row?
            if (newrownum != rownum) {
                CTCommentList lst = sheetComments.getCTComments().getCommentList();
                for (CTComment comment : lst.getCommentArray()) {
                    String oldRef = comment.getRef();
                    CellReference ref = new CellReference(oldRef);
                    // is this comment part of the current row?
                    if (ref.getRow() == rownum) {
                        XSSFComment xssfComment = new XSSFComment(sheetComments, comment, vml == null ? null : vml.findCommentShape(rownum, ref.getCol()));
                        // we should not perform the shifting right here as we would then find
                        // already shifted comments and would shift them again...
                        commentsToShift.put(xssfComment, newrownum);
                    }
                }
            }
        }
        if (rownum < startRow || rownum > endRow) {
            continue;
        }
        if (!copyRowHeight) {
            row.setHeight((short) -1);
        }
        row.shift(n);
    }
    // i.e. from down to up if shifting down, vice-versa otherwise
    for (Map.Entry<XSSFComment, Integer> entry : commentsToShift.entrySet()) {
        entry.getKey().setRow(entry.getValue());
    }
    XSSFRowShifter rowShifter = new XSSFRowShifter(this);
    int sheetIndex = getWorkbook().getSheetIndex(this);
    String sheetName = getWorkbook().getSheetName(sheetIndex);
    FormulaShifter shifter = FormulaShifter.createForRowShift(sheetIndex, sheetName, startRow, endRow, n, SpreadsheetVersion.EXCEL2007);
    rowShifter.updateNamedRanges(shifter);
    rowShifter.updateFormulas(shifter);
    rowShifter.shiftMergedRegions(startRow, endRow, n);
    rowShifter.updateConditionalFormatting(shifter);
    rowShifter.updateHyperlinks(shifter);
    //rebuild the _rows map
    Map<Integer, XSSFRow> map = new HashMap<Integer, XSSFRow>();
    for (XSSFRow r : _rows.values()) {
        // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
        // NOSONAR
        final Integer rownumI = new Integer(r.getRowNum());
        map.put(rownumI, r);
    }
    _rows.clear();
    _rows.putAll(map);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CellReference(org.apache.poi.ss.util.CellReference) TreeMap(java.util.TreeMap) XSSFRowShifter(org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter) FormulaShifter(org.apache.poi.ss.formula.FormulaShifter) CellAddress(org.apache.poi.ss.util.CellAddress) Row(org.apache.poi.ss.usermodel.Row) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

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