Example usage for java.util SortedMap tailMap

List of usage examples for java.util SortedMap tailMap

Introduction

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

Prototype

SortedMap<K, V> tailMap(K fromKey);

Source Link

Document

Returns a view of the portion of this map whose keys are greater than or equal to fromKey .

Usage

From source file:org.formix.dsx.serialization.XmlSerializer.java

private boolean isSetter(SortedMap<String, Method> parentMethods, String elemName) {
    String methodName = "set" + this.capitalize(elemName);
    String signature = parentMethods.tailMap(methodName).firstKey();
    return signature.startsWith(methodName + "-");
}

From source file:org.formix.dsx.serialization.XmlSerializer.java

@SuppressWarnings("unchecked")
private Collection<Object> getCollectionValue(XmlElement elem, Class<?> paramType,
        SortedMap<String, Method> parentMethods, Object parent) throws XmlException {

    Collection<Object> col = null;
    if ((parentMethods != null) && (parent != null)) {

        String methodName = "get" + this.capitalize(elem.getName());
        String signature = parentMethods.tailMap(methodName).firstKey();
        Method colGetterMethod = parentMethods.get(signature);

        try {//from   w w w  . jav a 2s  .c o m
            col = (Collection<Object>) colGetterMethod.invoke(parent, (Object[]) null);

        } catch (Exception e) {
            throw new XmlException("Unable to invoke collection getter: " + colGetterMethod.getName(), e);
        }
    }

    try {
        if (col == null)
            col = this.createCollection(paramType);
    } catch (Exception e) {
        throw new XmlException("Unable to create collection type: " + paramType.getName(), e);
    }

    for (XmlContent colContent : elem.getChilds()) {
        if (colContent instanceof XmlElement) {
            XmlElement colElem = (XmlElement) colContent;

            Object objToAdd = null;
            Class<?> colElemType = null;
            String colElemTypeName = this.capitalize(colElem.getName());
            try {
                colElemType = this.getType(colElemTypeName);
            } catch (ClassNotFoundException e) {
                throw new XmlException(
                        "Unable to find the collection's internal element type: " + colElemTypeName, e);
            }

            objToAdd = this.deserialize(colElem, colElemType);

            col.add(objToAdd);
        }
    }

    return col;
}

From source file:org.jactr.core.module.declarative.four.associative.ProceduralModuleListener.java

public void updateStatistics(SortedMap<String, IChunk> matchedChunks) {
    FastList<ISlot> slots = FastList.newInstance();
    for (Map.Entry<String, IChunk> matchedEntry : matchedChunks.entrySet()) {
        IChunk matchedChunk = matchedEntry.getValue();
        /*/*from w w w.  j a  va2  s.  c o m*/
         * all chunks that were matched were needed..
         */
        ISubsymbolicChunk4 sscMatched = matchedChunk.getAdapter(ISubsymbolicChunk4.class);

        sscMatched.incrementTimesNeeded(1);

        /**
         * and in 4.0 the goal defines the context
         */
        if (matchedEntry.getKey().equalsIgnoreCase(BOUND_GOAL)) {
            /*
             * the contents of the chunk define the context. Ideally we'd only use
             * those slots that were matched in the production. but for now, we'll
             * use everybody
             */
            slots.clear();
            for (ISlot slot : matchedChunk.getSymbolicChunk().getSlots(slots))
                if (slot.getValue() instanceof IChunk) {
                    IChunk jChunk = (IChunk) slot.getValue();
                    ISubsymbolicChunk4 sscJ = jChunk.getAdapter(ISubsymbolicChunk4.class);
                    sscJ.incrementTimesInContext(1);

                    /*
                     * if J is in the context and there is a link between J and another
                     * matched Chunk (i), then we need to strengthen that association
                     * directly.
                     */
                    for (Map.Entry<String, IChunk> iEntry : matchedChunks.tailMap(matchedEntry.getKey())
                            .entrySet()) {
                        IChunk iChunk = iEntry.getValue();
                        // skip ourselves
                        if (iChunk.equals(matchedChunk))
                            continue;

                        // Link4 link = (Link4) sscJ.getIAssociation(iChunk);
                        Link4 link = (Link4) ChunkListener.getAssociativeLink(jChunk, iChunk, true);

                        /*
                         * the link exists. It might not.. should we create one here?
                         */
                        if (link != null) {
                            if (LOGGER.isDebugEnabled())
                                LOGGER.debug(String.format("Incrementing F(Ni|Cj) for %s", link));

                            link.incrementFNICJ();
                        }
                    }
                }
        }

    }

    FastList.recycle(slots);
}

From source file:org.jahia.services.render.scripting.bundle.BundleScriptResolver.java

/**
 * Returns view scripts for the specified module bundle which match the specified path.
 *
 * @param module     the module bundle to perform lookup in
 * @param pathPrefix the resource path prefix to match
 * @return a set of matching view scripts ordered by the extension (script type)
 *//*from w ww  .  ja v a2s .  c o  m*/
private Set<ViewResourceInfo> findBundleScripts(String module, String pathPrefix) {
    final SortedMap<String, ViewResourceInfo> allBundleScripts = availableScripts.get(module);
    if (allBundleScripts == null || allBundleScripts.isEmpty()) {
        return Collections.emptySet();
    }

    // get all the ViewResourceInfos which path is greater than or equal to the given prefix
    final SortedMap<String, ViewResourceInfo> viewInfosWithPathGTEThanPrefix = allBundleScripts
            .tailMap(pathPrefix);

    // if the tail map is empty, we won't find the path prefix in the available scripts so return an empty set
    if (viewInfosWithPathGTEThanPrefix.isEmpty()) {
        return Collections.emptySet();
    }

    // check if the first key contains the prefix. If not, the prefix will not match any entries so return an empty set
    if (!viewInfosWithPathGTEThanPrefix.firstKey().startsWith(pathPrefix)) {
        return Collections.emptySet();
    } else {
        SortedSet<ViewResourceInfo> sortedScripts = new TreeSet<ViewResourceInfo>(scriptExtensionComparator);
        for (String path : viewInfosWithPathGTEThanPrefix.keySet()) {
            // we should have only few values to look at
            if (path.startsWith(pathPrefix)) {
                sortedScripts.add(viewInfosWithPathGTEThanPrefix.get(path));
            } else {
                // as soon as the path doesn't start with the given prefix anymore, we won't have a match in the remaining so return
                return sortedScripts;
            }
        }
        return sortedScripts;
    }
}

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 {/* ww w.  j a  v a2 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.omnaest.utils.table.TableTest.java

@Test
public void testIndexOfArbitraryKeyExtractor() {
    Table<String> table = this.filledTable(100, 5);

    KeyExtractor<Integer, RowDataReader<String>> keyExtractor = new KeyExtractor<Integer, RowDataReader<String>>() {
        private static final long serialVersionUID = -4201644938610833630L;

        @Override// ww w  . j av a  2 s  .  c o  m
        public Integer extractKey(RowDataReader<String> rowDataReader) {
            String[] elements = rowDataReader.getElements();
            String[] tokens = elements[1].split(":");
            return Integer.valueOf(tokens[0]);
        }
    };
    SortedMap<Integer, Set<Row<String>>> sortedMap = table.index().of(keyExtractor);
    {
        assertNotNull(sortedMap);
        assertEquals(table.rowSize(), sortedMap.size());
        assertTrue(sortedMap.containsKey(0));
    }

    table.removeRow(0);
    {
        assertFalse(sortedMap.containsKey(0));
        assertTrue(sortedMap.containsKey(1));
        assertFalse(sortedMap.containsKey(101));

        table.setElement(0, 1, "101:88");
        assertTrue(sortedMap.containsKey(101));

        Set<Row<String>> rowSet = sortedMap.get(101);
        assertEquals(1, rowSet.size());
    }
    {
        assertSame(sortedMap, table.index().of(keyExtractor));
    }

    table.setRowElements(1, "0:0", "200:0");
    {
        assertTrue(sortedMap.containsKey(200));
    }
    {
        SortedMap<Integer, Set<Row<String>>> tailMap = sortedMap.tailMap(90);
        assertEquals(100 - 90 + 2, tailMap.size());
        assertEquals(90, tailMap.firstKey().intValue());
        assertEquals(200, tailMap.lastKey().intValue());
    }
    {
        SortedMap<Integer, Set<Row<String>>> headMap = sortedMap.headMap(10);
        assertEquals(9 - 2, headMap.size());
        assertEquals(3, headMap.firstKey().intValue());
        assertEquals(9, headMap.lastKey().intValue());
    }
    {
        table.clear();
        assertTrue(sortedMap.isEmpty());
    }
}

From source file:org.talend.dataprep.schema.xls.XlsSchemaParser.java

/**
 *
 *
 * @param colId the column id./*from   ww w .j  a  va  2 s .c  o  m*/
 * @param columnRows all rows with previously guessed type: key=row number, value= guessed type
 * @param averageHeaderSize
 * @return
 */
private Type guessColumnType(Integer colId, SortedMap<Integer, String> columnRows, int averageHeaderSize) {

    // calculate number per type

    Map<String, Long> perTypeNumber = columnRows.tailMap(averageHeaderSize).values() //
            .stream() //
            .collect(Collectors.groupingBy(w -> w, Collectors.counting()));

    OptionalLong maxOccurrence = perTypeNumber.values().stream().mapToLong(Long::longValue).max();

    if (!maxOccurrence.isPresent()) {
        return ANY;
    }

    List<String> duplicatedMax = new ArrayList<>();

    perTypeNumber.forEach((type1, aLong) -> {
        if (aLong >= maxOccurrence.getAsLong()) {
            duplicatedMax.add(type1);
        }
    });

    String guessedType;
    if (duplicatedMax.size() == 1) {
        guessedType = duplicatedMax.get(0);
    } else {
        // as we have more than one type we guess ANY
        guessedType = ANY.getName();
    }

    LOGGER.debug("guessed type for column #{} is {}", colId, guessedType);
    return Type.get(guessedType);
}

From source file:therian.operator.immutablecheck.DefaultImmutableChecker.java

private static void addTypeTo(final Set<Class<?>> target, final SortedMap<String, ?> sortedMap) {
    addTypeTo(target, (Map<String, ?>) sortedMap);
    addTypeTo(target, (Map<String, ?>) sortedMap.headMap("foo"));
    addTypeTo(target, (Map<String, ?>) sortedMap.tailMap("foo"));
    addTypeTo(target, (Map<String, ?>) sortedMap.subMap("foo", "foo"));
}