Example usage for java.util SortedMap get

List of usage examples for java.util SortedMap get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.jahia.services.templates.JahiaTemplateManagerService.java

public boolean differentModuleWithSameIdExists(String symbolicName, String groupId) {
    SortedMap<ModuleVersion, JahiaTemplatesPackage> moduleVersions = templatePackageRegistry
            .getAllModuleVersions().get(symbolicName);
    return moduleVersions != null && !moduleVersions.isEmpty()
            && !moduleVersions.get(moduleVersions.firstKey()).getGroupId().equals(groupId);
}

From source file:org.wrml.runtime.rest.DefaultApiLoader.java

protected Object decipherDocumentSurrogateKeyValue(final URI uri, final Prototype prototype) {

    final ApiNavigator apiNavigator = getParentApiNavigator(uri);

    if (apiNavigator == null) {
        return null;
    }/*from ww w. j a va  2  s  .  com*/

    final SortedSet<Parameter> surrogateKeyComponents = apiNavigator.getSurrogateKeyComponents(uri, prototype);
    if (surrogateKeyComponents == null || surrogateKeyComponents.isEmpty()) {
        return null;
    }

    final Set<String> allKeySlotNames = prototype.getAllKeySlotNames();

    final Object surrogateKeyValue;
    if (surrogateKeyComponents.size() == 1) {
        final Parameter surrogateKeyPair = surrogateKeyComponents.first();

        final String slotName = surrogateKeyPair.getName();
        if (!allKeySlotNames.contains(slotName)) {
            return null;
        }

        final String slotTextValue = surrogateKeyPair.getValue();
        final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue);

        surrogateKeyValue = slotValue;
    } else {

        final SortedMap<String, Object> keySlots = new TreeMap<String, Object>();

        for (final Parameter surrogateKeyPair : surrogateKeyComponents) {

            final String slotName = surrogateKeyPair.getName();
            if (!allKeySlotNames.contains(slotName)) {
                continue;
            }

            final String slotTextValue = surrogateKeyPair.getValue();
            final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue);

            if (slotValue == null) {
                continue;
            }

            keySlots.put(slotName, slotValue);

        }

        if (keySlots.size() == 1) {
            surrogateKeyValue = keySlots.get(keySlots.firstKey());
        } else {
            surrogateKeyValue = new CompositeKey(keySlots);
        }
    }

    return surrogateKeyValue;

}

From source file:org.omnaest.utils.table.impl.join.TableSelectImpl.java

@Override
public SortedMap<E, Set<Row<E>>> sortedMap() {
    // /* ww  w .j  a v a  2 s.co  m*/
    final SortedMap<E, Set<Row<E>>> retmap = new TreeMap<E, Set<Row<E>>>();

    Table<E> table = this.table();
    for (Row<E> row : table.rows()) {
        //
        final E key = row.getElement(0);

        Set<Row<E>> set = retmap.get(key);
        if (set == null) {
            set = new LinkedHashSet<Row<E>>();
            retmap.put(key, set);
        }
        set.add(row);
    }

    return retmap;
}

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

License:asdf

public int addValue(Row.Key rowKey, ColumnValue columnValue, int numOfVersion) throws IOException {
    int saveSize = 0;
    int rowKeyLength = rowKey.getLength();
    int rowKeyAllocLen = rowKey.getAllocatedSize();

    SortedMap<Cell.Key, ValueCollection> columnValues = null;
    mapLock.readLock().lock();/*w  w  w.  jav  a 2  s . c o m*/
    try {
        columnValues = columnCollectionMap.get(rowKey);
    } finally {
        mapLock.readLock().unlock();
    }

    if (columnValues == null) {
        mapLock.writeLock().lock();
        try {
            if ((columnValues = columnCollectionMap.get(rowKey)) == null) {
                columnValues = new TreeMap<Cell.Key, ValueCollection>();
                columnCollectionMap.put(rowKey, columnValues);
                saveSize += (rowKeyAllocLen + 80);
            }
        } finally {
            mapLock.writeLock().unlock();
        }
    }

    synchronized (columnValues) {
        ValueCollection valueCollection = columnValues.get(columnValue.getCellKey());
        if (valueCollection == null) {
            valueCollection = new ValueCollection();
            Cell.Key cellKey = columnValue.getCellKey();
            columnValues.put(cellKey, valueCollection);

            saveSize += (144 + ((cellKey.getLength() + 3) / 8) * 8); //valueCollection ?
        }

        //saveSize += columnValue.size();
        int duplicatedLength = ((rowKeyLength + 3) / 8) * 8;
        saveSize += (columnValue.getAllocatedSize() - duplicatedLength);

        valueCollection.add(columnValue, numOfVersion);
    }

    memorySize += saveSize;

    return saveSize;
}

From source file:ocr.sapphire.image.EdgeBasedImagePreprocessor.java

private Point[][] findEdgePoints(int[] edgeData) {
    List<Deque<Point>> components = new ArrayList<Deque<Point>>();
    // find close paths
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (edgeData[x + y * width] == BLACK && isBridge(edgeData, x, y)) {
                edgeData[x + y * width] = WHITE;
                Deque<Point> firstPart = null, secondPart = null;
                for (int k = 0; k < DX.length; k++) {
                    int x2 = x + DX[k];
                    int y2 = y + DY[k];
                    if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) {
                        continue;
                    }//  ww w  .j  av  a2s. c o m
                    if (edgeData[x2 + y2 * width] == BLACK) {
                        Deque<Point> points = findConnectedComponent(edgeData, x2, y2);
                        if (firstPart == null) {
                            firstPart = points;
                        } else {
                            secondPart = points;
                        }
                    }
                }
                firstPart.addFirst(new Point(x, y));
                if (secondPart != null) { // the path is not closed
                    join(firstPart, true, secondPart, true);
                }
                components.add(firstPart);
            }
        }
    }

    // remove contained components
    for (int i = 0; i < components.size() - 1; i++) {
        Rectangle r1 = getBounds(components.get(i));
        for (int j = i + 1; j < components.size();) {
            Rectangle r2 = getBounds(components.get(j));
            if (r1.contains(r2)) {
                components.remove(j);
            } else if (r2.contains(r1)) {
                components.set(i, components.get(j));
                components.remove(j);
            } else {
                j++;
            }
        }
    }

    // try to connect some paths
    int connectedCount;
    do {
        connectedCount = 0;
        for (int i = 0; i < components.size() - 1; i++) {
            for (int j = i + 1; j < components.size(); j++) {
                Deque<Point> a = components.get(i);
                Deque<Point> b = components.get(j);

                double d0 = d(a.getFirst(), a.getLast()) + d(b.getFirst(), b.getLast());
                double d1 = d(a.getFirst(), b.getFirst()) + d(a.getLast(), b.getLast());
                double d2 = d(a.getFirst(), b.getLast()) + d(a.getLast(), b.getFirst());
                double d3 = d(a.getFirst(), b.getFirst());
                double d4 = d(a.getFirst(), b.getLast());
                double d5 = d(a.getLast(), b.getFirst());
                double d6 = d(a.getLast(), b.getLast());

                if (d3 <= CLOSE_THRESHOLD && d3 <= d4) {
                    join(a, true, b, true);
                    components.remove(j);
                    connectedCount++;
                } else if (d4 <= CLOSE_THRESHOLD && d4 <= d3) {
                    join(a, true, b, false);
                    components.remove(j);
                    connectedCount++;
                } else if (d5 <= CLOSE_THRESHOLD && d5 <= d6) {
                    join(a, false, b, true);
                    components.remove(j);
                    connectedCount++;
                } else if (d6 <= CLOSE_THRESHOLD && d6 <= d5) {
                    join(a, false, b, false);
                    components.remove(j);
                    connectedCount++;
                } else if (d1 <= d0 && d1 <= d2) {
                    if (d3 < d6) {
                        join(a, true, b, true);
                    } else {
                        join(a, false, b, false);
                    }
                    components.remove(j);
                    connectedCount++;
                } else if (d2 <= d0 && d2 <= d1) {
                    if (d4 < d5) {
                        join(a, true, b, false);
                    } else {
                        join(a, false, b, true);
                    }
                    components.remove(j);
                    connectedCount++;
                }
            } // end of for j
        } // end of for i
    } while (connectedCount > 0);

    // choose (componentCount) biggest components
    SortedMap<Integer, Deque<Point>> componentMap = new TreeMap<Integer, Deque<Point>>();
    for (Deque<Point> c : components) {
        componentMap.put(-c.size(), c);
    }

    // remove noise
    boolean firstPoint = true;
    for (Iterator<Entry<Integer, Deque<Point>>> iterator = componentMap.entrySet().iterator(); iterator
            .hasNext();) {
        Entry<Integer, Deque<Point>> entry = iterator.next();
        Rectangle r = getBounds(entry.getValue());
        if (r.width <= 10 && r.height <= 10) {
            if (firstPoint) {
                firstPoint = false;
            } else {
                iterator.remove();
            }
        }
    }

    // convert components: normalize points, to array
    int foundComponentCount = Math.min(componentCount, componentMap.size());
    componentArr = new Point[foundComponentCount][];
    Rectangle r = getBounds(componentMap.get(componentMap.firstKey()));
    for (int c = 0; c < foundComponentCount; c++) {
        int key = componentMap.firstKey();
        componentArr[c] = new Point[componentMap.get(key).size()];
        normalize(componentMap.get(key)).toArray(componentArr[c]);
        componentMap.remove(key);

        for (int i = 0; i < componentArr[c].length; i++) {
            componentArr[c][i].x = (componentArr[c][i].x - r.x) / r.width;
            componentArr[c][i].y = (componentArr[c][i].y - r.y) / r.height;
        }
    }
    return componentArr;
}

From source file:cerrla.LocalCrossEntropyDistribution.java

/**
 * Generates a policy from the current distribution.
 * //from  ww w .  j  a  v  a2  s  . co  m
 * @param existingSubGoals
 *            A collection of all existing sub-goals in the parent policy
 *            this policy is to be put into.
 * @return A newly generated policy from the current distribution.
 */
public ModularPolicy generatePolicy(Collection<ModularPolicy> existingSubGoals) {
    // If testing greedy policies
    if (Config.getInstance().getGeneratorFile() != null) {
        if (bestPolicy_ == null || testEpisode_ >= ProgramArgument.TEST_ITERATIONS.intValue()) {
            SortedMap<Integer, RelationalPolicy> greedyPolicies = policyGenerator_.getGreedyPolicyMap();
            SortedMap<Integer, RelationalPolicy> nextKey = greedyPolicies.tailMap(currentEpisode_ + 1);

            if (ProgramArgument.TESTING.booleanValue()) {
                currentEpisode_ = greedyPolicies.lastKey();
                bestPolicy_ = new ModularPolicy(greedyPolicies.get(currentEpisode_), this);
                testEpisode_ = 0;
            } else if (nextKey == null || nextKey.isEmpty()) {
                // End of testing. Exit.
                bestPolicyEpisode_ = ProgramArgument.TEST_ITERATIONS.intValue();
            } else {
                // Next policy and next episode.
                currentEpisode_ = nextKey.firstKey();
                bestPolicy_ = new ModularPolicy(greedyPolicies.get(currentEpisode_), this);
                testEpisode_ = 0;
            }
        }

        bestPolicy_.clearPolicyRewards();
        return bestPolicy_;
    }

    if (frozen_ && state_ == AlgorithmState.BEST_POLICY) {
        bestPolicy_.clearPolicyRewards();
        return bestPolicy_;
    }

    // Initialise undertested
    if (undertestedPolicies_ == null)
        undertestedPolicies_ = new LinkedList<ModularPolicy>();

    // If there remains an undertested policy not already in the parent
    // policy, use that
    for (Iterator<ModularPolicy> iter = undertestedPolicies_.iterator(); iter.hasNext();) {
        ModularPolicy undertested = iter.next();
        if (undertested.shouldRegenerate() || !isValidSample(undertested, false))
            // If the element is fully tested, remove it.
            iter.remove();
        else if (!existingSubGoals.contains(undertested)) {
            // If the parent policy doesn't already contain the undertested
            // policy, return it.
            undertested.clearChildren();
            return undertested;
        }
    }

    // Otherwise generate a new policy
    RelationalPolicy newPol = policyGenerator_.generatePolicy(true, false);
    ModularPolicy newModPol = null;
    if (newPol instanceof ModularPolicy)
        newModPol = new ModularPolicy((ModularPolicy) newPol);
    else
        newModPol = new ModularPolicy(newPol, this);
    undertestedPolicies_.add(newModPol);
    return newModPol;
}

From source file:com.oneops.transistor.service.BomManagerImpl.java

private SortedMap<Integer, SortedMap<Integer, List<CmsCIRelation>>> getOrderedClouds(
        List<CmsCIRelation> cloudRels, boolean reverse) {

    SortedMap<Integer, SortedMap<Integer, List<CmsCIRelation>>> result = reverse
            ? new TreeMap<Integer, SortedMap<Integer, List<CmsCIRelation>>>(Collections.reverseOrder())
            : new TreeMap<Integer, SortedMap<Integer, List<CmsCIRelation>>>();

    for (CmsCIRelation binding : cloudRels) {

        Integer priority = Integer.valueOf(binding.getAttribute("priority").getDjValue());
        Integer order = 1;//w  w  w.ja v  a2 s .  c  o m
        if (binding.getAttributes().containsKey("dpmt_order")) {
            order = Integer.valueOf(binding.getAttribute("dpmt_order").getDjValue());
        }
        if (!result.containsKey(priority)) {
            result.put(priority, new TreeMap<Integer, List<CmsCIRelation>>());
        }
        if (!result.get(priority).containsKey(order)) {
            result.get(priority).put(order, new ArrayList<CmsCIRelation>());
        }
        result.get(priority).get(order).add(binding);
    }

    return result;
}

From source file:com.aurel.track.fieldType.runtime.custom.select.CustomSelectSimpleRT.java

/**
 * Loads the datasource and value for configuring the field change
 * @param workflowContext//from   w  w w  .  ja  va2  s  .  c  o m
 * @param fieldChangeValue
 * @param parameterCode
 * @param personBean
 * @param locale
 */
@Override
public void loadFieldChangeDatasourceAndValue(WorkflowContext workflowContext,
        FieldChangeValue fieldChangeValue, Integer parameterCode, TPersonBean personBean, Locale locale) {

    TFieldConfigBean configItem = (TFieldConfigBean) FieldConfigItemFacade.getInstance().getValidConfigDirect(
            workflowContext.getItemTypeID(), workflowContext.getProjectTypeID(), workflowContext.getProjectID(),
            fieldChangeValue.getFieldID());
    if (configItem == null) {
        configItem = (TFieldConfigBean) FieldConfigItemFacade.getInstance().getValidConfigFallback(
                workflowContext.getItemTypeID(), workflowContext.getProjectTypeID(),
                workflowContext.getProjectID(), fieldChangeValue.getFieldID());
    }
    List<ILabelBean> dataSource = null;
    if (configItem != null) {
        dataSource = loadList(configItem.getObjectID(), locale);
    }
    Object actualValue = fieldChangeValue.getValue();
    if (parameterCode == null) {
        //dataSourceMap.put(listID, optionList);
        fieldChangeValue.setPossibleValues(dataSource);
        //not a composite select
        //for multiple select there is no need to preselect some value
        Integer[] actualIntArrValue = (Integer[]) actualValue;
        actualIntArrValue = super.getBulkSelectValue(null, fieldChangeValue.getFieldID(), parameterCode,
                actualIntArrValue, (List) dataSource);
        fieldChangeValue.setValue(actualIntArrValue);
    } else {
        //first part of a composite part
        SortedMap<Integer, List<IBeanID>> listDatasourceMap = (SortedMap<Integer, List<IBeanID>>) fieldChangeValue
                .getPossibleValues();

        //Map<Integer, List<IBeanID>> listDatasourceMap = new TreeMap<Integer, List<IBeanID>>();
        //dataSourceMap.put(listID, listDatasourceMap);
        listDatasourceMap.put(parameterCode, (List) dataSource);
        SortedMap<Integer, Integer[]> actualValueMap = (SortedMap<Integer, Integer[]>) fieldChangeValue
                .getValue();
        Integer[] actualIntArrValue = null;
        if (actualValueMap == null) {
            //no submitted value (by first rendering null anyway) 
            actualValueMap = new TreeMap<Integer, Integer[]>();
            fieldChangeValue.setValue(actualValueMap);
            //valueMap.put(listID, actualValueMap);
        } else {
            //submitted value: get to see whether it is still valid
            actualIntArrValue = actualValueMap.get(parameterCode);
        }
        actualValueMap.put(parameterCode, getBulkSelectValue(null, fieldChangeValue.getFieldID(), parameterCode,
                actualIntArrValue, (List) dataSource));
    }
}

From source file:org.jahia.modules.modulemanager.forge.ForgeService.java

public List<Module> loadModules() {
    if (flushModules || (lastModulesLoad + loadModulesDelay) < new Date().getTime()) {
        modules.clear();/*from  w  w w.j  av a2 s  .  c o  m*/
        for (Forge forge : forges) {
            String url = forge.getUrl() + "/contents/modules-repository.moduleList.json";
            Map<String, String> headers = new HashMap<String, String>();
            if (!StringUtils.isEmpty(forge.getUser())) {
                headers.put("Authorization",
                        "Basic " + Base64.encode((forge.getUser() + ":" + forge.getPassword()).getBytes()));
            }
            headers.put("accept", "application/json");

            String jsonModuleList = httpClientService.executeGet(url, headers);
            try {
                JSONArray modulesRoot = new JSONArray(jsonModuleList);

                JSONArray moduleList = modulesRoot.getJSONObject(0).getJSONArray("modules");
                for (int i = 0; i < moduleList.length(); i++) {
                    boolean add = true;

                    final JSONObject moduleObject = moduleList.getJSONObject(i);
                    for (Module m : modules) {
                        if (StringUtils.equals(m.getId(), moduleObject.getString("name"))
                                && StringUtils.equals(m.getGroupId(), moduleObject.getString("groupId"))) {
                            add = false;
                            break;
                        }
                    }
                    if (add) {
                        final JSONArray moduleVersions = moduleObject.getJSONArray("versions");

                        SortedMap<Version, JSONObject> sortedVersions = new TreeMap<Version, JSONObject>();

                        final Version jahiaVersion = new Version(Jahia.VERSION);

                        for (int j = 0; j < moduleVersions.length(); j++) {
                            JSONObject object = moduleVersions.getJSONObject(j);
                            Version version = new Version(object.getString("version"));
                            Version requiredVersion = new Version(StringUtils
                                    .substringAfter(object.getString("requiredVersion"), "version-"));
                            if (requiredVersion.compareTo(jahiaVersion) <= 0) {
                                sortedVersions.put(version, object);
                            }
                        }
                        if (!sortedVersions.isEmpty()) {
                            Module module = new Module();
                            JSONObject versionObject = sortedVersions.get(sortedVersions.lastKey());
                            module.setRemoteUrl(moduleObject.getString("remoteUrl"));
                            module.setRemotePath(moduleObject.getString("path"));
                            if (moduleObject.has("icon")) {
                                module.setIcon(moduleObject.getString("icon"));
                            }
                            module.setVersion(versionObject.getString("version"));
                            module.setName(moduleObject.getString("title"));
                            module.setId(moduleObject.getString("name"));
                            module.setGroupId(moduleObject.getString("groupId"));
                            module.setDownloadUrl(versionObject.getString("downloadUrl"));
                            module.setForgeId(forge.getId());
                            modules.add(module);
                        }
                    }
                }
            } catch (JSONException e) {
                logger.error("unable to parse JSON return string for " + url);
            } catch (Exception e) {
                logger.error("unable to get store information" + e.getMessage());
            }
        }
        Collections.sort(modules);
        lastModulesLoad = new Date().getTime();
        flushModules = false;
    }

    return modules;
}

From source file:org.web4thejob.studio.controller.impl.PropertyEditorController.java

private void refreshComponentEvents(SortedMap<String, SortedSet<Element>> propsMap) {
    Grid grid = new Grid();
    grid.setParent(events);//from w w  w  . j a v  a2  s  .  c o  m
    grid.setVflex("true");
    grid.setSpan(true);
    new Columns().setParent(grid);
    grid.getColumns().setSizable(true);
    new Column("Name").setParent(grid.getColumns());
    Column colServer = new Column("Server");
    colServer.setParent(grid.getColumns());
    colServer.setAlign("center");
    colServer.setWidth("60px");
    Column colClient = new Column("Client");
    colClient.setParent(grid.getColumns());
    colClient.setAlign("center");
    colClient.setWidth("60px");

    new Rows().setParent(grid);

    for (String group : propsMap.keySet()) {
        for (Element property : propsMap.get(group)) {
            String propertyName = property.getAttributeValue("name");
            if (isEvent(propertyName)) {
                Row row = new Row();
                row.setParent(grid.getRows());

                Label name = new Label(propertyName);
                name.setParent(row);

                Button btn = new Button();
                //                    btn.setMold("bs");
                btn.setParent(row);
                btn.setIconSclass("z-icon-bolt");
                btn.setAttribute("mode", "text/x-java");
                btn.setAttribute("event", propertyName);
                btn.setAttribute("element", selection);
                btn.addEventListener(Events.ON_CLICK, CODE_EDITOR_HANDLER);
                if (getEventCodeNode(selection, propertyName, true) != null) {
                    btn.setZclass("btn btn-xs btn-primary");
                } else {
                    btn.setZclass("btn btn-xs btn-default");
                }
                btn.setWidth("32px");
                btn.setHeight("25px");

                btn = new Button();
                //                    btn.setMold("bs");
                btn.setParent(row);
                btn.setIconSclass("z-icon-bolt");
                btn.setAttribute("mode", "javascript");
                btn.setAttribute("event", propertyName);
                btn.setAttribute("element", selection);
                btn.addEventListener(Events.ON_CLICK, CODE_EDITOR_HANDLER);
                if (getEventCodeNode(selection, propertyName, false) != null) {
                    btn.setZclass("btn btn-xs btn-primary");
                } else {
                    btn.setZclass("btn btn-xs btn-default");
                }
                btn.setWidth("32px");
                btn.setHeight("25px");
            }
        }
    }
}