List of usage examples for java.util SortedMap put
V put(K key, V value);
From source file:eu.ggnet.dwoss.redtape.entity.Document.java
/** * Returns all Positions with supplied Type. * * @param type the type//from w w w . j ava2 s . c om * @return all Positions with supplied Type. */ public SortedMap<Integer, Position> getPositions(PositionType type) { SortedMap<Integer, Position> result = new TreeMap<>(); for (int pos : positions.keySet()) { if (positions.get(pos).getType() == type) result.put(pos, positions.get(pos)); } return result; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamVoicemailConfTable.java
public void createVoicemailConf(CFAstAuthorization Authorization, CFAstVoicemailConfBuff Buff) { schema.getTableConfigurationFile().createConfigurationFile(Authorization, Buff); CFAstConfigurationFilePKey pkey = schema.getFactoryConfigurationFile().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredId(Buff.getRequiredId()); CFAstVoicemailConfByVMClusterIdxKey keyVMClusterIdx = schema.getFactoryVoicemailConf().newVMClusterIdxKey(); keyVMClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createVoicemailConf", pkey);//from w ww.ja va2s. c om } // Validate foreign keys { boolean allNull = true; allNull = false; allNull = false; if (!allNull) { if (null == schema.getTableConfigurationFile().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId(), Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createVoicemailConf", "Superclass", "SuperClass", "ConfigurationFile", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAstConfigurationFilePKey, CFAstVoicemailConfBuff> subdictVMClusterIdx; if (dictByVMClusterIdx.containsKey(keyVMClusterIdx)) { subdictVMClusterIdx = dictByVMClusterIdx.get(keyVMClusterIdx); } else { subdictVMClusterIdx = new TreeMap<CFAstConfigurationFilePKey, CFAstVoicemailConfBuff>(); dictByVMClusterIdx.put(keyVMClusterIdx, subdictVMClusterIdx); } subdictVMClusterIdx.put(pkey, Buff); }
From source file:com.aurel.track.fieldType.runtime.matchers.converter.CompositSelectMatcherConverter.java
/** * Convert a string from displayStringMap to object value * Called after submitting the filter's form * @param displayStringMap/* w ww .j a v a 2 s . co m*/ * @param fieldID * @param locale * @param matcherRelation * @return */ @Override public Object fromDisplayString(Map<String, String> displayStringMap, Integer fieldID, Locale locale, Integer matcherRelation) { if (displayStringMap == null) { return null; } if (matcherRelation != null) { switch (matcherRelation.intValue()) { case MatchRelations.EQUAL: case MatchRelations.NOT_EQUAL: case MatchRelations.PARTIAL_MATCH: case MatchRelations.PARTIAL_NOTMATCH: //it should be sorted map because of toXMLString(), //in xml the values should be serialized in the right order SortedMap<Integer, Integer[]> actualValuesMap = new TreeMap<Integer, Integer[]>(); Iterator<String> iterator = displayStringMap.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); Integer[] parts = MergeUtil.getParts(key); if (parts != null && parts.length > 1) { Integer fieldOrIndex = parts[0]; Integer parametertCode = parts[1]; if (fieldOrIndex != null && fieldOrIndex.equals(fieldID) && parametertCode != null) { String partStringValue = displayStringMap.get(key); if (partStringValue != null) { try { actualValuesMap.put(parametertCode, new Integer[] { Integer.valueOf(partStringValue) }); } catch (Exception e) { LOGGER.warn("Converting the " + partStringValue + " to Integer from display string failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } } } return actualValuesMap; } } return null; }
From source file:com.opengamma.web.server.push.ViewportDefinition.java
/** Helper method to get the row numbers and timestamps from JSON */ private static SortedMap<Integer, Long> getRows(JSONObject jsonObject, String viewportId) throws JSONException { JSONObject viewportJson = jsonObject.optJSONObject(viewportId); SortedMap<Integer, Long> rows = new TreeMap<Integer, Long>(); if (viewportJson == null) { return rows; }/*from w ww .j a va 2 s . c o m*/ JSONArray rowIds = viewportJson.getJSONArray(ROW_IDS); if (rowIds.length() < 1) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, a viewport must contain at least one row"); } JSONArray lastTimestamps = viewportJson.getJSONArray(LAST_TIMESTAMPS); if (rowIds.length() != lastTimestamps.length()) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, the viewport definition must specify the same number " + "of rows and timestamps"); } for (int i = 0; i < rowIds.length(); i++) { int rowId = rowIds.getInt(i); if (rowId < 0) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, row numbers must not be negative"); } if (rows.containsKey(rowId)) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, duplicate row number: " + rowId); } Long timestamp = lastTimestamps.optLong(i); if (timestamp < 0) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, timestamps must not be negative: " + timestamp); } else if (timestamp == 0) { timestamp = null; } rows.put(rowId, timestamp); } return rows; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamSecSessionTable.java
public void createSecSession(CFAccAuthorization Authorization, CFAccSecSessionBuff Buff) { CFAccSecSessionPKey pkey = schema.getFactorySecSession().newPKey(); pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen()); Buff.setRequiredSecSessionId(pkey.getRequiredSecSessionId()); CFAccSecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey(); keySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); CFAccSecSessionByStartIdxKey keyStartIdx = schema.getFactorySecSession().newStartIdxKey(); keyStartIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); keyStartIdx.setRequiredStart(Buff.getRequiredStart()); CFAccSecSessionByFinishIdxKey keyFinishIdx = schema.getFactorySecSession().newFinishIdxKey(); keyFinishIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); keyFinishIdx.setOptionalFinish(Buff.getOptionalFinish()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createSecSession", pkey);/*w w w . j a va 2 s .c om*/ } if (dictByStartIdx.containsKey(keyStartIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createSecSession", "SessionStartIdx", keyStartIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableSecUser().readDerivedByIdIdx(Authorization, Buff.getRequiredSecUserId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createSecSession", "Container", "SecSessionUser", "SecUser", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAccSecSessionPKey, CFAccSecSessionBuff> subdictSecUserIdx; if (dictBySecUserIdx.containsKey(keySecUserIdx)) { subdictSecUserIdx = dictBySecUserIdx.get(keySecUserIdx); } else { subdictSecUserIdx = new TreeMap<CFAccSecSessionPKey, CFAccSecSessionBuff>(); dictBySecUserIdx.put(keySecUserIdx, subdictSecUserIdx); } subdictSecUserIdx.put(pkey, Buff); dictByStartIdx.put(keyStartIdx, Buff); SortedMap<CFAccSecSessionPKey, CFAccSecSessionBuff> subdictFinishIdx; if (dictByFinishIdx.containsKey(keyFinishIdx)) { subdictFinishIdx = dictByFinishIdx.get(keyFinishIdx); } else { subdictFinishIdx = new TreeMap<CFAccSecSessionPKey, CFAccSecSessionBuff>(); dictByFinishIdx.put(keyFinishIdx, subdictFinishIdx); } subdictFinishIdx.put(pkey, Buff); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamSecSessionTable.java
public void createSecSession(CFAstAuthorization Authorization, CFAstSecSessionBuff Buff) { CFAstSecSessionPKey pkey = schema.getFactorySecSession().newPKey(); pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen()); Buff.setRequiredSecSessionId(pkey.getRequiredSecSessionId()); CFAstSecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey(); keySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); CFAstSecSessionByStartIdxKey keyStartIdx = schema.getFactorySecSession().newStartIdxKey(); keyStartIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); keyStartIdx.setRequiredStart(Buff.getRequiredStart()); CFAstSecSessionByFinishIdxKey keyFinishIdx = schema.getFactorySecSession().newFinishIdxKey(); keyFinishIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); keyFinishIdx.setOptionalFinish(Buff.getOptionalFinish()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createSecSession", pkey);// w w w . j a v a 2 s . c om } if (dictByStartIdx.containsKey(keyStartIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createSecSession", "SessionStartIdx", keyStartIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableSecUser().readDerivedByIdIdx(Authorization, Buff.getRequiredSecUserId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createSecSession", "Container", "SecSessionUser", "SecUser", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdictSecUserIdx; if (dictBySecUserIdx.containsKey(keySecUserIdx)) { subdictSecUserIdx = dictBySecUserIdx.get(keySecUserIdx); } else { subdictSecUserIdx = new TreeMap<CFAstSecSessionPKey, CFAstSecSessionBuff>(); dictBySecUserIdx.put(keySecUserIdx, subdictSecUserIdx); } subdictSecUserIdx.put(pkey, Buff); dictByStartIdx.put(keyStartIdx, Buff); SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdictFinishIdx; if (dictByFinishIdx.containsKey(keyFinishIdx)) { subdictFinishIdx = dictByFinishIdx.get(keyFinishIdx); } else { subdictFinishIdx = new TreeMap<CFAstSecSessionPKey, CFAstSecSessionBuff>(); dictByFinishIdx.put(keyFinishIdx, subdictFinishIdx); } subdictFinishIdx.put(pkey, Buff); }
From source file:net.sourceforge.msscodefactory.cfcore.v1_11.GenKbRam.GenKbRamSecGroupTable.java
public void updateSecGroup(GenKbAuthorization Authorization, GenKbSecGroupBuff Buff) { GenKbSecGroupPKey pkey = schema.getFactorySecGroup().newPKey(); pkey.setRequiredSecGroupId(Buff.getRequiredSecGroupId()); GenKbSecGroupBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateSecGroup", "Existing record not found", "SecGroup", pkey); }// w ww. j a va 2s . co m if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateSecGroup", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); GenKbSecGroupByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecGroup().newClusterIdxKey(); existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId()); GenKbSecGroupByClusterIdxKey newKeyClusterIdx = schema.getFactorySecGroup().newClusterIdxKey(); newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); GenKbSecGroupByUNameIdxKey existingKeyUNameIdx = schema.getFactorySecGroup().newUNameIdxKey(); existingKeyUNameIdx.setRequiredClusterId(existing.getRequiredClusterId()); existingKeyUNameIdx.setRequiredName(existing.getRequiredName()); GenKbSecGroupByUNameIdxKey newKeyUNameIdx = schema.getFactorySecGroup().newUNameIdxKey(); newKeyUNameIdx.setRequiredClusterId(Buff.getRequiredClusterId()); newKeyUNameIdx.setRequiredName(Buff.getRequiredName()); // Check unique indexes if (!existingKeyUNameIdx.equals(newKeyUNameIdx)) { if (dictByUNameIdx.containsKey(newKeyUNameIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateSecGroup", "SecGroupUNameIdx", newKeyUNameIdx); } } // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableCluster().readDerivedByPIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateSecGroup", "Container", "SecGroupCluster", "Cluster", null); } } } // Update is valid SortedMap<GenKbSecGroupPKey, GenKbSecGroupBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByClusterIdx.get(existingKeyClusterIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByClusterIdx.containsKey(newKeyClusterIdx)) { subdict = dictByClusterIdx.get(newKeyClusterIdx); } else { subdict = new TreeMap<GenKbSecGroupPKey, GenKbSecGroupBuff>(); dictByClusterIdx.put(newKeyClusterIdx, subdict); } subdict.put(pkey, Buff); dictByUNameIdx.remove(existingKeyUNameIdx); dictByUNameIdx.put(newKeyUNameIdx, Buff); }
From source file:at.illecker.hama.rootbeer.examples.matrixmultiplication.compositeinput.cpu.MatrixMultiplicationBSPCpu.java
@Override public void cleanup(BSPPeer<IntWritable, TupleWritable, IntWritable, VectorWritable, MatrixRowMessage> peer) throws IOException { // MasterTask accumulates result if (peer.getPeerName().equals(masterTask)) { // SortedMap because the final matrix rows should be in order SortedMap<Integer, Vector> accumlatedRows = new TreeMap<Integer, Vector>(); MatrixRowMessage currentMatrixRowMessage = null; // Collect messages while ((currentMatrixRowMessage = peer.getCurrentMessage()) != null) { int rowIndex = currentMatrixRowMessage.getRowIndex(); Vector rowValues = currentMatrixRowMessage.getRowValues().get(); if (isDebuggingEnabled) { logger.writeChars("bsp,gotMsg,key=" + rowIndex + ",value=" + rowValues.toString() + "\n"); }//from w w w.ja va2 s. co m if (accumlatedRows.containsKey(rowIndex)) { accumlatedRows.get(rowIndex).assign(rowValues, Functions.PLUS); } else { accumlatedRows.put(rowIndex, new RandomAccessSparseVector(rowValues)); } } // Write accumulated results for (Map.Entry<Integer, Vector> row : accumlatedRows.entrySet()) { if (isDebuggingEnabled) { logger.writeChars( "bsp,write,key=" + row.getKey() + ",value=" + row.getValue().toString() + "\n"); } peer.write(new IntWritable(row.getKey()), new VectorWritable(row.getValue())); } } }
From source file:io.wcm.handler.url.suffix.SuffixBuilder.java
/** * Build complete suffix.//from w w w . j a v a 2 s.c o m * @return the suffix */ public String build() { SortedMap<String, Object> sortedParameterMap = new TreeMap<>(parameterMap); // gather resource paths in a treeset (having them in a defined order helps with caching) SortedSet<String> resourcePathsSet = new TreeSet<>(); // iterate over all parts that should be kept from the current request for (String nextPart : initialSuffixParts) { // if this is a key-value-part: if (nextPart.indexOf(KEY_VALUE_DELIMITER) > 0) { String key = decodeKey(nextPart); // decode and keep the part if it is not overridden in the given parameter-map if (!sortedParameterMap.containsKey(key)) { String value = decodeValue(nextPart); sortedParameterMap.put(key, value); } } else { // decode and keep the resource paths (unless they are specified again in resourcePaths) String path = decodeResourcePathPart(nextPart); if (!resourcePaths.contains(path)) { resourcePathsSet.add(path); } } } // copy the resources specified as parameters to the sorted set of paths if (resourcePaths != null) { resourcePathsSet.addAll(ImmutableList.copyOf(resourcePaths)); } // gather all suffix parts in this list List<String> suffixParts = new ArrayList<>(); // now encode all resource paths for (String path : resourcePathsSet) { suffixParts.add(encodeResourcePathPart(path)); } // now encode all entries from the parameter map for (Entry<String, Object> entry : sortedParameterMap.entrySet()) { Object value = entry.getValue(); if (value == null) { // don't add suffix part if value is null continue; } String encodedKey = encodeKeyValuePart(entry.getKey()); String encodedValue = encodeKeyValuePart(value.toString()); suffixParts.add(encodedKey + KEY_VALUE_DELIMITER + encodedValue); } // finally join these parts to a single string return StringUtils.join(suffixParts, SUFFIX_PART_DELIMITER); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamExtConfigConfTable.java
public void createExtConfigConf(CFAstAuthorization Authorization, CFAstExtConfigConfBuff Buff) { schema.getTableConfigurationFile().createConfigurationFile(Authorization, Buff); CFAstConfigurationFilePKey pkey = schema.getFactoryConfigurationFile().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredId(Buff.getRequiredId()); CFAstExtConfigConfByExtCnfClusIdxKey keyExtCnfClusIdx = schema.getFactoryExtConfigConf() .newExtCnfClusIdxKey();//ww w. ja va 2 s . c o m keyExtCnfClusIdx.setRequiredClusterId(Buff.getRequiredClusterId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createExtConfigConf", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; allNull = false; if (!allNull) { if (null == schema.getTableConfigurationFile().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId(), Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createExtConfigConf", "Superclass", "SuperClass", "ConfigurationFile", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAstConfigurationFilePKey, CFAstExtConfigConfBuff> subdictExtCnfClusIdx; if (dictByExtCnfClusIdx.containsKey(keyExtCnfClusIdx)) { subdictExtCnfClusIdx = dictByExtCnfClusIdx.get(keyExtCnfClusIdx); } else { subdictExtCnfClusIdx = new TreeMap<CFAstConfigurationFilePKey, CFAstExtConfigConfBuff>(); dictByExtCnfClusIdx.put(keyExtCnfClusIdx, subdictExtCnfClusIdx); } subdictExtCnfClusIdx.put(pkey, Buff); }