Example usage for java.util SortedMap isEmpty

List of usage examples for java.util SortedMap isEmpty

Introduction

In this page you can find the example usage for java.util SortedMap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:Main.java

public static <T, U> U firstElement(SortedMap<T, U> m) {
    if (m == null || m.isEmpty()) {
        return null;
    }/*from ww  w. j  a  va2 s  .  c om*/
    return m.get(m.firstKey());
}

From source file:eu.ggnet.dwoss.redtape.ShippingCostHelper.java

/**
 * Method to update/refresh the shipping cost of a {@link Document}.
 * <p>//w ww . j a  va 2s.  co  m
 * @param doc               the {@link Document} entity.
 * @param shippingCondition the condition on which the shipping cost is calculated
 */
public static void modifyOrAddShippingCost(Document doc, ShippingCondition shippingCondition) {
    int amountOfPositions = doc.getPositions(PositionType.UNIT).size();
    for (Position position : doc.getPositions(PositionType.PRODUCT_BATCH).values()) {
        //just quick for the warranty extension. sucks a bit if we ever wouldhave a refurbished id on another product batch
        if (!StringUtils.isBlank(position.getRefurbishedId()))
            continue;
        amountOfPositions += position.getAmount();
    }
    double costs = 0;
    if (Client.hasFound(ShippingCostService.class))
        costs = Client.lookup(ShippingCostService.class).calculate(amountOfPositions,
                doc.getDossier().getPaymentMethod(), shippingCondition);
    SortedMap<Integer, Position> positions = doc.getPositions(PositionType.SHIPPING_COST);
    if (positions.isEmpty()) {
        PositionBuilder pb = new PositionBuilder().setType(PositionType.SHIPPING_COST).setName("Versandkosten")
                .setDescription("Versandkosten zu Vorgang: " + doc.getDossier().getIdentifier()).setPrice(costs)
                .setTax(GlobalConfig.TAX).setAfterTaxPrice(costs + (costs * GlobalConfig.TAX))
                .setBookingAccount(Client.lookup(MandatorSupporter.class).loadPostLedger()
                        .get(PositionType.SHIPPING_COST).orElse(-1));
        doc.append(pb.createPosition());
    } else {
        Position next = positions.values().iterator().next();
        next.setPrice(costs);
        next.setAfterTaxPrice(costs + (costs * GlobalConfig.TAX));
    }
}

From source file:com.kku.apps.pricesearch.util.SignedHelper.java

private static String canonicalize(SortedMap<String, String> sortedParamMap) {
    if (sortedParamMap.isEmpty()) {
        return "";
    }//  w  w  w.  ja va 2  s  .co  m

    StringBuffer buffer = new StringBuffer();
    Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry<String, String> kvpair = iter.next();
        buffer.append(percentEncodeRfc3986(kvpair.getKey()));
        buffer.append("=");
        buffer.append(percentEncodeRfc3986(kvpair.getValue()));
        if (iter.hasNext()) {
            buffer.append("&");
        }
    }
    String cannoical = buffer.toString();
    return cannoical;
}

From source file:org.archive.util.PrefixFinder.java

private static String last(SortedMap<String, ?> map) {
    // TODO Auto-generated method stub
    return map.isEmpty() ? null : map.lastKey();
}

From source file:org.orekit.models.earth.GeoMagneticFieldFactory.java

/** Gets a geomagnetic field model for the given year. In case the specified
 * year does not match an existing model epoch, the resulting field is
 * generated by either time-transforming an existing model using its secular
 * variation coefficients, or by linear interpolating two existing models.
 * @param type the type of the field (e.g. WMM or IGRF)
 * @param models all loaded field models, sorted by their epoch
 * @param year the epoch of the resulting field model
 * @return a {@link GeoMagneticField} model for the given year
 * @throws OrekitException if the specified year is out of range of the available models
 */// ww  w  .  j  a va  2 s .c o  m
private static GeoMagneticField getModel(final FieldModel type, final TreeMap<Integer, GeoMagneticField> models,
        final double year) throws OrekitException {

    final int epochKey = (int) (year * 100d);
    final SortedMap<Integer, GeoMagneticField> head = models.headMap(epochKey, true);

    if (head.isEmpty()) {
        throw new OrekitException(OrekitMessages.NON_EXISTENT_GEOMAGNETIC_MODEL, type.name(), year);
    }

    GeoMagneticField model = models.get(head.lastKey());
    if (model.getEpoch() < year) {
        if (model.supportsTimeTransform()) {
            model = model.transformModel(year);
        } else {
            final SortedMap<Integer, GeoMagneticField> tail = models.tailMap(epochKey, false);
            if (tail.isEmpty()) {
                throw new OrekitException(OrekitMessages.NON_EXISTENT_GEOMAGNETIC_MODEL, type.name(), year);
            }
            final GeoMagneticField secondModel = models.get(tail.firstKey());
            if (secondModel != model) {
                model = model.transformModel(secondModel, year);
            }
        }
    }
    return model;
}

From source file:edu.uci.ics.crawler4j.url.URLCanonicalizer.java

/**
 * Canonicalize the query string.//w  ww.j  a v a 2 s .c  o m
 * 
 * @param sortedParamMap
 *            Parameter name-value pairs in lexicographical order.
 * @return Canonical form of query string.
 */
private static String canonicalize(final SortedMap<String, String> sortedParamMap) {
    if (sortedParamMap == null || sortedParamMap.isEmpty()) {
        return "";
    }

    final StringBuilder sb = new StringBuilder(100);
    for (Map.Entry<String, String> pair : sortedParamMap.entrySet()) {
        final String key = pair.getKey().toLowerCase();
        if (key.equals("jsessionid") || key.equals("phpsessid") || key.equals("aspsessionid")) {
            continue;
        }
        if (sb.length() > 0) {
            sb.append('&');
        }
        sb.append(percentEncodeRfc3986(pair.getKey()));
        if (!pair.getValue().isEmpty()) {
            sb.append('=');
            sb.append(percentEncodeRfc3986(pair.getValue()));
        }
    }
    return sb.toString();
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.java

public static <S> S forStationAdjacent(final SortedMap<BigDecimal, S> stationIndex, final BigDecimal station,
        final boolean upstream) {
    final BigDecimal pred = NumberUtils.decrement(station);
    final BigDecimal succ = NumberUtils.increment(station);

    if (upstream) {
        final SortedMap<BigDecimal, ? extends Object> successors = stationIndex.tailMap(succ);
        if (!successors.isEmpty())
            return stationIndex.get(successors.firstKey());
    } else {/*from  w  w w  . ja  v a  2  s  .  co  m*/

        final SortedMap<BigDecimal, ? extends Object> predecessors = stationIndex.headMap(pred);
        if (!predecessors.isEmpty())
            return stationIndex.get(predecessors.lastKey());
    }

    return null;
}

From source file:org.kalypso.model.wspm.tuhh.core.wspwin.WspWinExporter.java

private static void write1DTuhhRunOff(final IRunOffEvent runOffEvent, final File qwtFile,
        final TuhhStationRange stationRange) throws IOException, CoreException {
    final SortedMap<BigDecimal, BigDecimal> values = runOffEvent.getDischargeTable();

    if (values.isEmpty()) {
        final String message = String.format(Messages.getString("WspWinExporter.3"), //$NON-NLS-1$
                FeatureHelper.getAnnotationValue(runOffEvent, IAnnotation.ANNO_LABEL));
        final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmTuhhCorePlugin.PLUGIN_ID, message);
        throw new CoreException(status);
    }/* w  w w.j  a  va 2s.  c  o m*/

    PrintWriter pw = null;
    try {
        qwtFile.getParentFile().mkdirs();

        pw = new PrintWriter(new BufferedWriter(new FileWriter(qwtFile)));

        final int exportSign = stationRange.getExportSign();
        final String runoffName = runOffEvent.getName();
        final String cleanRunoffName = cleanupRunoffName(runoffName);
        pw.print(cleanRunoffName);
        pw.print(" "); //$NON-NLS-1$
        pw.println(values.size());

        // write it sorted into the file
        for (final Map.Entry<BigDecimal, BigDecimal> entry : values.entrySet()) {
            final BigDecimal station = entry.getKey();
            final BigDecimal runOff = entry.getValue();

            pw.print(station.doubleValue() * exportSign);
            pw.print(" "); //$NON-NLS-1$
            pw.print(runOff.doubleValue());
            pw.println();
        }
    } finally {
        IOUtils.closeQuietly(pw);
    }
}

From source file:nu.yona.app.api.service.ActivityMonitorService.java

private static String printForegroundTask(Context context) {
    currentApp = "NULL";
    try {//from   w w w .j ava  2s .co  m
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
            long time = System.currentTimeMillis();
            List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,
                    time - AppConstant.ONE_SECOND * AppConstant.ONE_SECOND, time);
            if (appList != null && appList.size() > 0) {
                SortedMap<Long, UsageStats> mySortedMap = new TreeMap<>();
                for (UsageStats usageStats : appList) {
                    mySortedMap.put(usageStats.getLastTimeUsed(), usageStats);
                }
                if (!mySortedMap.isEmpty()) {
                    currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
                }
            }
        } else {
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            currentApp = am.getRunningAppProcesses().get(0).processName;
        }
    } catch (Exception e) {
        AppUtils.reportException(ActivityMonitorService.class.getSimpleName(), e, Thread.currentThread());
    }
    return currentApp;
}

From source file:org.zaproxy.zap.spider.URLCanonicalizer.java

/**
 * Canonicalize the query string.//from ww w  .ja v  a2s . co m
 * 
 * @param sortedParamMap Parameter name-value pairs in lexicographical order.
 * @return Canonical form of query string.
 */
private static String canonicalize(final SortedMap<String, String> sortedParamMap) {
    if (sortedParamMap == null || sortedParamMap.isEmpty()) {
        return "";
    }

    final StringBuilder sb = new StringBuilder(100);
    for (Map.Entry<String, String> pair : sortedParamMap.entrySet()) {
        final String key = pair.getKey().toLowerCase();
        // Ignore irrelevant parameters
        if (IRRELEVANT_PARAMETERS.contains(key) || key.startsWith("utm_")) {
            continue;
        }
        if (sb.length() > 0) {
            sb.append('&');
        }
        sb.append(pair.getKey());
        if (!pair.getValue().isEmpty()) {
            sb.append('=');
            sb.append(pair.getValue());
        }
    }
    return sb.toString();
}