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:com.jnj.b2b.core.search.solrfacetsearch.provider.impl.FirstVariantCategoryNameListValueProvider.java

@Override
public Object getFieldValue(final ProductModel product) {
    String categoryNameList = null;
    if (isVariantBaseProduct(product)) {
        final Collection<VariantProductModel> variants = product.getVariants();
        if (CollectionUtils.isNotEmpty(variants)) {
            final SortedMap<VariantValueCategoryModel, GenericVariantProductModel> categoryValues = new TreeMap<>(
                    variantValueCategoryModelSequenceComparator);
            for (final VariantProductModel variant : variants) {
                if (variant instanceof GenericVariantProductModel) {
                    addCategories(categoryValues, (GenericVariantProductModel) variant);
                }//from w ww.  ja v a  2 s.c om
            }
            if (!categoryValues.isEmpty()) {
                categoryNameList = categoryManager.buildSolrPropertyFromCategoryVariantPairs(categoryValues);
            }
        }

    }
    return categoryNameList;
}

From source file:de.appsolve.padelcampus.controller.events.EventsController.java

@RequestMapping("event/{eventId}/knockoutgames")
public ModelAndView getEventKnockoutGames(@PathVariable("eventId") Long eventId) {
    Event event = eventDAO.findByIdFetchWithGames(eventId);
    if (event == null) {
        throw new ResourceNotFoundException();
    }/*from  w w  w .  j  a  v a2  s. c o m*/
    SortedMap<Integer, List<Game>> groupGameMap = eventsUtil.getGroupGameMap(event);
    SortedMap<Integer, List<Game>> roundGameMap = eventsUtil.getRoundGameMap(event);
    if (roundGameMap.isEmpty()) {
        return new ModelAndView("events/groupknockout/groupgamesendinfo", "Model", event);
    }
    ModelAndView mav = getKnockoutView(event, roundGameMap);
    mav.addObject("GroupGameMap", groupGameMap);
    return mav;
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcMultiRowRecordWriter.java

@SuppressWarnings("unchecked")
private void processPartition(Connection connection, Multimap<Long, Record> partitions, Long partitionKey,
        List<OnRecordErrorException> errorRecords) throws SQLException, OnRecordErrorException {
    Collection<Record> partition = partitions.get(partitionKey);
    // Fetch the base insert query for this partition.
    SortedMap<String, String> columnsToParameters = getFilteredColumnsToParameters(getColumnsToParameters(),
            partition.iterator().next());

    // put all the records in a queue for consumption
    LinkedList<Record> queue = new LinkedList<>(partition);

    // compute number of rows per batch
    if (columnsToParameters.isEmpty()) {
        throw new OnRecordErrorException(Errors.JDBCDEST_22);
    }//w ww .  j a  v  a 2  s.c om
    int maxRowsPerBatch = maxPrepStmtParameters / columnsToParameters.size();

    PreparedStatement statement = null;

    // parameters are indexed starting with 1
    int paramIdx = 1;
    int rowCount = 0;
    while (!queue.isEmpty()) {
        // we're at the start of a batch.
        if (statement == null) {
            // instantiate the new statement
            statement = generatePreparedStatement(columnsToParameters,
                    // the next batch will have either the max number of records, or however many are left.
                    Math.min(maxRowsPerBatch, queue.size()), getTableName(), connection);
        }

        // process the next record into the current statement
        Record record = queue.removeFirst();
        for (String column : columnsToParameters.keySet()) {
            Field field = record.get(getColumnsToFields().get(column));
            Field.Type fieldType = field.getType();
            Object value = field.getValue();

            try {
                switch (fieldType) {
                case LIST:
                    List<Object> unpackedList = unpackList((List<Field>) value);
                    Array array = connection.createArrayOf(getSQLTypeName(fieldType), unpackedList.toArray());
                    statement.setArray(paramIdx, array);
                    break;
                case DATE:
                case DATETIME:
                    // Java Date types are not accepted by JDBC drivers, so we need to convert to java.sql.Date
                    java.util.Date date = field.getValueAsDatetime();
                    statement.setObject(paramIdx, new java.sql.Date(date.getTime()));
                    break;
                default:
                    statement.setObject(paramIdx, value, getColumnType(column));
                    break;
                }
            } catch (SQLException e) {
                LOG.error(Errors.JDBCDEST_23.getMessage(), column, fieldType.toString(), e);
                throw new OnRecordErrorException(record, Errors.JDBCDEST_23, column, fieldType.toString());
            }
            ++paramIdx;
        }

        rowCount++;

        // check if we've filled up the current batch
        if (rowCount == maxRowsPerBatch) {
            // time to execute the current batch
            statement.addBatch();
            statement.executeBatch();
            statement.close();
            statement = null;

            // reset our counters
            rowCount = 0;
            paramIdx = 1;
        }
    }

    // check if there are any records left. this should occur whenever there isn't *exactly* maxRowsPerBatch records in
    // this partition.
    if (statement != null) {
        statement.addBatch();
        statement.executeBatch();
        statement.close();
    }
}

From source file:org.cloudata.core.tabletserver.ColumnCollection.java

License:asdf

/**
 * MEAT, ROOT tablet?  ?./*  w  w w  . j a va  2  s. c o m*/
 * ? rowkey? ? ??  ?, ? ? ??   ? .
 * @param rowKey
 * @return
 */
public ColumnValue findNearestValue(Row.Key rowKey) {
    mapLock.readLock().lock();
    try {
        SortedMap<Row.Key, SortedMap<Cell.Key, ValueCollection>> tailMap = columnCollectionMap.tailMap(rowKey);

        if (!tailMap.isEmpty()) {
            for (Map.Entry<Row.Key, SortedMap<Cell.Key, ValueCollection>> entry : tailMap.entrySet()) {
                SortedMap<Cell.Key, ValueCollection> columnValues = entry.getValue();
                synchronized (columnValues) {
                    for (ValueCollection eachValueCollection : columnValues.values()) {

                        if (eachValueCollection.get() != null) {
                            return eachValueCollection.get();
                        }
                    }
                }
            }
            return null;
        } else {
            return null;
        }
    } finally {
        mapLock.readLock().unlock();
    }
}

From source file:org.eclipse.gyrex.jobs.internal.externalprocess.ExternalProcessJobParameter.java

public static ExternalProcessJobParameter fromParameter(final Map<String, String> params,
        final boolean resolveInheritedEnvironmentVariables) {
    final ExternalProcessJobParameter p = new ExternalProcessJobParameter();

    // collect arguments into a sorting map
    final SortedMap<String, String> arguments = new TreeMap<>(new ArgumentsParameterKeyComparator());

    // walk through all possible parameter
    final Map<String, String> environment = new HashMap<>();
    for (final Entry<String, String> e : params.entrySet()) {
        String value = e.getValue();
        switch (e.getKey()) {
        case PARAM_COMMAND:
            p.setCommand(value);//from   w w w.ja v  a2  s.co m
            break;
        case PARAM_CLEAR_ENVIRONMENT:
            p.setClearEnvironment(BooleanUtils.toBooleanObject(value));
            break;
        case PARAM_EXPECTED_RETURN_CODE:
            p.setExpectedReturnCode(NumberUtils.toInt(value));
            break;
        case PARAM_WORKING_DIR:
            p.setWorkingDir(value);
            break;

        default:
            if (e.getKey().startsWith(PARAM_PREFIX_ENV)) {
                final String name = e.getKey().substring(PARAM_PREFIX_ENV.length());
                if (resolveInheritedEnvironmentVariables && StringUtils.equals(ENV_VALUE_INHERIT, value)) {
                    value = System.getenv(name);
                }
                environment.put(name, value);
            } else if (e.getKey().startsWith(PARAM_PREFIX_ARG)) {
                arguments.put(e.getKey().substring(PARAM_PREFIX_ARG.length()), value);
            }
            break;
        }
    }

    if (!arguments.isEmpty()) {
        p.setArguments(new ArrayList<>(arguments.values()));
    }

    if (!environment.isEmpty()) {
        p.setEnvironment(environment);
    }
    return p;
}

From source file:org.eclipse.skalli.core.persistence.XStreamPersistenceTest.java

@Test
public void testGetExtensionsNoMatchingAliases() throws Exception {
    XStreamPersistence xp = new TestXStreamPersistence();
    Document doc = XMLUtils.documentFromString(XML_WITH_EXTENSIONS);
    Map<String, Class<?>> notMatchingAliases = getNotMatchingAliases();
    SortedMap<String, Element> extensions = xp.getExtensionsByAlias(doc, notMatchingAliases);
    assertNotNull(extensions);//from   www  .  ja  v a  2 s .co  m
    assertTrue(extensions.isEmpty());
    extensions = xp.getExtensionsByClassName(doc, notMatchingAliases);
    assertNotNull(extensions);
    assertTrue(extensions.isEmpty());
}

From source file:org.rm3l.ddwrt.tiles.status.wan.WANMonthlyTrafficTile.java

private Intent renderTraffDateForMonth(@NotNull final String monthFormatted) {

    Log.d(LOG_TAG, "renderTraffDateForMonth: " + monthFormatted);

    if (traffData == null) {
        return null;
    }//from   w  w  w. j  av a 2 s.c  om

    final ImmutableMap<Integer, ArrayList<Double>> row = traffData.row(monthFormatted);
    if (row == null) {
        return null;
    }

    final SortedMap<Integer, ArrayList<Double>> dailyTraffMap = new TreeMap<>(row);

    if (dailyTraffMap.isEmpty()) {
        return null;
    }

    Log.d(LOG_TAG, "renderTraffDateForMonth: " + monthFormatted + " / dailyTraffMap=" + dailyTraffMap);

    final int size = dailyTraffMap.size();
    final int[] days = new int[size];
    final double[] inData = new double[size];
    final double[] outData = new double[size];

    int i = 0;
    for (final Map.Entry<Integer, ArrayList<Double>> dailyTraffMapEntry : dailyTraffMap.entrySet()) {
        final ArrayList<Double> dailyTraffMapEntryValue = dailyTraffMapEntry.getValue();
        if (dailyTraffMapEntryValue == null || dailyTraffMapEntryValue.size() < 2) {
            continue;
        }
        final Double in = dailyTraffMapEntryValue.get(0);
        final Double out = dailyTraffMapEntryValue.get(1);
        if (in == null || out == null) {
            continue;
        }
        days[i] = dailyTraffMapEntry.getKey();
        inData[i] = in;
        outData[i] = out;
        i++;
    }

    // Creating an  XYSeries for Inbound
    final XYSeries inboundSeries = new XYSeries("Inbound");
    // Creating an  XYSeries for Outbound
    final XYSeries outboundSeries = new XYSeries("Outbound");
    // Adding data to In and Out Series
    for (int j = 0; j < i; j++) {
        inboundSeries.add(j, inData[j]);
        outboundSeries.add(j, outData[j]);
    }

    // Creating a dataset to hold each series
    final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    // Adding inbound Series to the dataset
    dataset.addSeries(inboundSeries);
    // Adding outbound Series to dataset
    dataset.addSeries(outboundSeries);

    // Creating XYSeriesRenderer to customize inboundSeries
    final XYSeriesRenderer inboundRenderer = new XYSeriesRenderer();
    inboundRenderer.setColor(Color.rgb(130, 130, 230));
    inboundRenderer.setFillPoints(true);
    inboundRenderer.setLineWidth(2);
    inboundRenderer.setDisplayChartValues(true);

    // Creating XYSeriesRenderer to customize outboundSeries
    final XYSeriesRenderer outboundRenderer = new XYSeriesRenderer();
    outboundRenderer.setColor(Color.rgb(220, 80, 80));
    outboundRenderer.setFillPoints(true);
    outboundRenderer.setLineWidth(2);
    outboundRenderer.setDisplayChartValues(true);

    // Creating a XYMultipleSeriesRenderer to customize the whole chart
    final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
    multiRenderer.setXLabels(i);
    multiRenderer.setChartTitle("Traffic Data for '" + monthFormatted + "'");
    multiRenderer.setXTitle("Days");
    multiRenderer.setYTitle("Traffic (MB)");
    multiRenderer.setZoomButtonsVisible(true);
    for (int k = 0; k < i; k++) {
        multiRenderer.addXTextLabel(k, String.valueOf(days[k]));
    }
    //        for(int k = 0; k < days.length; k++) {
    //            multiRenderer.addXTextLabel(k, String.valueOf(k));
    //        }

    // Adding inboundRenderer and outboundRenderer to multipleRenderer
    // Note: The order of adding dataseries to dataset and renderers to multipleRenderer
    // should be same
    multiRenderer.addSeriesRenderer(inboundRenderer);
    multiRenderer.addSeriesRenderer(outboundRenderer);

    return ChartFactory.getBarChartIntent(this.mParentFragmentActivity, dataset, multiRenderer,
            BarChart.Type.DEFAULT);

}

From source file:org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender.java

private List<Map<String, Element>> getElementsAndCounts(Map<String, SortedMap<Long, Integer>> map,
        List<Long> cutoffs, SortedSet<PurgeElement> purgeInformation) {
    if (purgeInformation.size() > maxUniqueMessages) {
        ErrorAndWarningsCleanup cleanup = new ErrorAndWarningsCleanup();
        long cutoff = Time.now() - (messageAgeLimitSeconds * 1000);
        cutoff = (cutoff / 1000);/*w w w .  j  a v a  2s . c om*/
        cleanup.cleanupMessages(map, purgeInformation, cutoff, maxUniqueMessages);
    }
    List<Map<String, Element>> ret = new ArrayList<>(cutoffs.size());
    for (int i = 0; i < cutoffs.size(); ++i) {
        ret.add(new HashMap<String, Element>());
    }
    synchronized (lock) {
        for (Map.Entry<String, SortedMap<Long, Integer>> element : map.entrySet()) {
            for (int i = 0; i < cutoffs.size(); ++i) {
                Map<String, Element> retMap = ret.get(i);
                SortedMap<Long, Integer> qualifyingTimes = element.getValue().tailMap(cutoffs.get(i));
                long count = 0;
                for (Map.Entry<Long, Integer> entry : qualifyingTimes.entrySet()) {
                    count += entry.getValue();
                }
                if (!qualifyingTimes.isEmpty()) {
                    retMap.put(element.getKey(), new Element(count, qualifyingTimes.lastKey()));
                }
            }
        }
    }
    return ret;
}

From source file:com.aurel.track.item.link.ItemLinkBL.java

/**
 * Gets the links for a workItem//from   ww  w .  j  av  a 2  s . c  o m
 * @return
 */
static List<ItemLinkListEntry> getLinks(SortedMap<Integer, TWorkItemLinkBean> successorsForMeAsPredecessorMap,
        SortedMap<Integer, TWorkItemLinkBean> predecessorsForMeAsSuccessorMap, boolean editable, Locale locale,
        boolean newItem) {
    Map<Integer, TLinkTypeBean> linkTypeMap = GeneralUtils.createMapFromList(LinkTypeBL.loadAll());
    List<ItemLinkListEntry> itemLinkList = new ArrayList<ItemLinkListEntry>();
    //links from me as predecessor to successors
    if (successorsForMeAsPredecessorMap != null && !successorsForMeAsPredecessorMap.isEmpty()) {
        Set<Integer> successorItemIDs = new HashSet<Integer>();
        for (TWorkItemLinkBean workItemLinkBean : successorsForMeAsPredecessorMap.values()) {
            successorItemIDs.add(workItemLinkBean.getLinkSucc());
        }
        List<TWorkItemBean> successorItems = ItemBL
                .loadByWorkItemKeys(GeneralUtils.createIntArrFromSet(successorItemIDs));
        Map<Integer, TWorkItemBean> workItemsMap = GeneralUtils.createMapFromList(successorItems);
        for (Map.Entry<Integer, TWorkItemLinkBean> entry : successorsForMeAsPredecessorMap.entrySet()) {
            TWorkItemLinkBean workItemLinkBean = entry.getValue();
            Integer linkID = null;
            if (newItem) {
                //the sort order from the map
                linkID = entry.getKey();
            } else {
                //the saved linkID
                linkID = workItemLinkBean.getObjectID();
            }
            Integer linkType = workItemLinkBean.getLinkType();
            TLinkTypeBean linkTypeBean = linkTypeMap.get(linkType);
            Integer linkTypeDirection = linkTypeBean.getLinkDirection();
            if (linkTypeBean == null || linkTypeDirection == null
                    || linkTypeDirection.intValue() == LINK_DIRECTION.RIGHT_TO_LEFT) {
                //remove the links of type "right to left". Bidirectional and "left to right" (pred to succ) relations remain
                //for right to left link types the links are visible only from successor item
                continue;
            }
            Integer succesorItemID = workItemLinkBean.getLinkSucc();
            TWorkItemBean workItemBean = workItemsMap.get(succesorItemID);
            ItemLinkListEntry itemLinkListEntry = new ItemLinkListEntry();
            itemLinkListEntry.setSortOrder(workItemLinkBean.getSortorder());
            itemLinkListEntry.setLinkType(linkType);
            itemLinkListEntry.setLinkDirection(linkTypeDirection);
            itemLinkListEntry.setLinkedWorkItemID(succesorItemID);
            if (workItemLinkBean != null) {
                itemLinkListEntry.setLinkedWorkItemTitle(workItemBean.getSynopsis());
            }
            itemLinkListEntry.setDescription(workItemLinkBean.getDescription());
            itemLinkListEntry.setLinkID(linkID);
            itemLinkListEntry.setLinkTypeName(
                    LinkTypeBL.getLinkTypeName(linkTypeBean, workItemLinkBean.getLinkDirection(), locale));
            TStateBean stateBean = LookupContainer.getStatusBean(workItemBean.getStateID(), locale);
            if (stateBean != null) {
                itemLinkListEntry.setStateLabel(stateBean.getLabel());
            }
            ILabelBean responsiblePerson = LookupContainer.getPersonBean(workItemBean.getResponsibleID());
            if (responsiblePerson != null) {
                itemLinkListEntry.setResponsibleLabel(responsiblePerson.getLabel());
            }
            itemLinkListEntry.setLastEdit(workItemLinkBean.getLastEdit());
            boolean isInline = false;
            ILinkType linkTypeInstance = LinkTypeBL.getLinkTypePluginInstanceByLinkTypeKey(linkType);
            if (linkTypeInstance != null) {
                itemLinkListEntry.setParameters(linkTypeInstance.prepareParametersOnLinkTab(workItemLinkBean,
                        linkTypeDirection, locale));
                itemLinkListEntry.setParameterMap(linkTypeInstance.prepareParametersMap(workItemLinkBean));
                isInline = linkTypeInstance.isInline();
            }
            itemLinkListEntry.setEditable(editable && !isInline);
            itemLinkList.add(itemLinkListEntry);
        }
    }
    //links from me as successor to predecessors
    if (predecessorsForMeAsSuccessorMap != null && !predecessorsForMeAsSuccessorMap.isEmpty()) {
        Set<Integer> predecessorItemIDs = new HashSet<Integer>();
        for (TWorkItemLinkBean workItemLinkBean : predecessorsForMeAsSuccessorMap.values()) {
            predecessorItemIDs.add(workItemLinkBean.getLinkPred());
        }
        List<TWorkItemBean> predecessorItems = ItemBL
                .loadByWorkItemKeys(GeneralUtils.createIntArrFromSet(predecessorItemIDs));
        Map<Integer, TWorkItemBean> workItemsMap = GeneralUtils.createMapFromList(predecessorItems);
        for (Map.Entry<Integer, TWorkItemLinkBean> entry : predecessorsForMeAsSuccessorMap.entrySet()) {
            TWorkItemLinkBean workItemLinkBean = entry.getValue();
            Integer linkID = null;
            if (newItem) {
                //the sort order from the map
                linkID = entry.getKey();
            } else {
                //the saved linkID
                linkID = workItemLinkBean.getObjectID();
            }
            Integer linkType = workItemLinkBean.getLinkType();
            TLinkTypeBean linkTypeBean = linkTypeMap.get(linkType);
            Integer linkTypeDirection = linkTypeBean.getLinkDirection();
            if (linkTypeBean == null || linkTypeDirection == null
                    || linkTypeDirection.intValue() == LINK_DIRECTION.LEFT_TO_RIGHT) {
                //remove the links of type "left to right". Bidirectional and "right to left" (pred to succ) relations remain
                //for left to right link types the links are visible only from predecessor item
                continue;
            }
            if (linkTypeDirection.intValue() == LINK_DIRECTION.BIDIRECTIONAL) {
                linkTypeDirection = LinkTypeBL.getReverseDirection(workItemLinkBean.getLinkDirection());
            }
            Integer predecessorItemID = workItemLinkBean.getLinkPred();
            TWorkItemBean workItemBean = workItemsMap.get(predecessorItemID);
            ItemLinkListEntry itemLinkListEntry = new ItemLinkListEntry();
            itemLinkListEntry.setSortOrder(workItemLinkBean.getSortorder());
            itemLinkListEntry.setLinkType(linkType);
            itemLinkListEntry.setLinkDirection(linkTypeDirection);
            itemLinkListEntry.setLinkedWorkItemID(predecessorItemID);
            if (workItemLinkBean != null) {
                itemLinkListEntry.setLinkedWorkItemTitle(workItemBean.getSynopsis());
            }
            itemLinkListEntry.setDescription(workItemLinkBean.getDescription());
            itemLinkListEntry.setLinkID(linkID);
            itemLinkListEntry
                    .setLinkTypeName(LinkTypeBL.getLinkTypeName(linkTypeBean, linkTypeDirection, locale));
            TStateBean stateBean = LookupContainer.getStatusBean(workItemBean.getStateID(), locale);
            if (stateBean != null) {
                itemLinkListEntry.setStateLabel(stateBean.getLabel());
            }
            ILabelBean responsiblePerson = LookupContainer.getPersonBean(workItemBean.getResponsibleID());
            if (responsiblePerson != null) {
                itemLinkListEntry.setResponsibleLabel(responsiblePerson.getLabel());
            }
            itemLinkListEntry.setLastEdit(workItemLinkBean.getLastEdit());
            ILinkType linkTypeInstance = LinkTypeBL.getLinkTypePluginInstanceByLinkTypeKey(linkType);
            boolean isInline = false;
            if (linkTypeInstance != null) {
                itemLinkListEntry.setParameters(linkTypeInstance.prepareParametersOnLinkTab(workItemLinkBean,
                        linkTypeDirection, locale));
                itemLinkListEntry.setParameterMap(linkTypeInstance.prepareParametersMap(workItemLinkBean));
                isInline = linkTypeInstance.isInline();
            }
            itemLinkListEntry.setEditable(editable && !isInline);
            itemLinkList.add(itemLinkListEntry);
        }
    }
    Collections.sort(itemLinkList);
    return itemLinkList;
}

From source file:viper.api.time.TimeEncodedList.java

/**
 * {@inheritDoc}//from   w w  w.j a  va2 s  .  c om
 */
public Comparable firstBefore(Comparable c) {
    SortedMap head = values.headMap(c);
    if (!head.isEmpty()) {
        return (Comparable) head.lastKey();
    }
    return null;
}