List of usage examples for java.util SortedMap put
V put(K key, V value);
From source file:jscover.report.MainTest.java
@Test public void shouldRunXMLSummaryReport() throws IOException { given(config.getReportFormat()).willReturn(ReportFormat.XMLSUMMARY); given(config.getVersion()).willReturn("version"); final File jsonDirectory = new File("jsonDir"); given(config.getJsonDirectory()).willReturn(jsonDirectory); String json = "json"; given(ioUtils.loadFromFileSystem(new File(jsonDirectory, "jscoverage.json"))).willReturn(json); SortedMap<String, FileData> list = new TreeMap<String, FileData>(); List<Integer> lines = new ArrayList<Integer>(); for (int i = 0; i <= 42; i++) lines.add(i);/* ww w . j av a 2 s . c o m*/ SortedMap<Integer, List<BranchData>> branches = new TreeMap<Integer, List<BranchData>>(); List<Integer> functions = new ArrayList<Integer>(); list.put("/test.js", new FileData("/test.js", lines, functions, branches)); given(jsonDataMerger.jsonToMap(json)).willReturn(list); main.runMain(new String[] {}); TypeSafeMatcher<File> fileMatcher = new TypeSafeMatcher<File>() { @Override protected boolean matchesSafely(File file) { return file.equals(jsonDirectory); } public void describeTo(Description description) { } }; TypeSafeMatcher<Coverable> coverableMatcher = new TypeSafeMatcher<Coverable>() { @Override protected boolean matchesSafely(Coverable coverable) { return coverable.getCodeLineCount() == 42; } public void describeTo(Description description) { } }; verify(xmlSummary).saveSummary(argThat(coverableMatcher), argThat(fileMatcher), argThat(is("version"))); verifyZeroInteractions(exitHelper); }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnToolSetRecHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {//from w w w . j a va 2s.c om // Common XML Attributes String attrId = null; String attrRevision = null; // ToolSet Attributes String attrName = null; String attrDescr = null; String attrRevisionString = null; String attrIsSupported = null; String attrGenerate = null; String attrToolId0 = null; String attrToolId1 = null; String attrToolId2 = null; String attrToolId3 = null; String attrToolId4 = null; String attrToolId5 = null; String attrToolId6 = null; String attrToolId7 = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("ToolSet"); CFGenKbXMsgRspnHandler xmsgRspnHandler = (CFGenKbXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGenKbSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Name")) { if (attrName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Descr")) { if (attrDescr != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDescr = attrs.getValue(idxAttr); } else if (attrLocalName.equals("RevisionString")) { if (attrRevisionString != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevisionString = attrs.getValue(idxAttr); } else if (attrLocalName.equals("IsSupported")) { if (attrIsSupported != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrIsSupported = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Generate")) { if (attrGenerate != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrGenerate = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId0")) { if (attrToolId0 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId0 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId1")) { if (attrToolId1 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId1 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId2")) { if (attrToolId2 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId2 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId3")) { if (attrToolId3 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId3 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId4")) { if (attrToolId4 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId4 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId5")) { if (attrToolId5 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId5 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId6")) { if (attrToolId6 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId6 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ToolId7")) { if (attrToolId7 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrToolId7 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrId == null) || (attrId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id"); } if (attrName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } if ((attrIsSupported == null) || (attrIsSupported.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "IsSupported"); } if ((attrGenerate == null) || (attrGenerate.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Generate"); } if ((attrToolId0 == null) || (attrToolId0.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ToolId0"); } // Save named attributes to context CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext(); // Convert string attributes to native Java types short natId = Short.parseShort(attrId); String natName = attrName; String natDescr = attrDescr; String natRevisionString = attrRevisionString; boolean natIsSupported; if (attrIsSupported.equals("true") || attrIsSupported.equals("yes") || attrIsSupported.equals("1")) { natIsSupported = true; } else if (attrIsSupported.equals("false") || attrIsSupported.equals("no") || attrIsSupported.equals("0")) { natIsSupported = false; } else { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Unexpected IsSupported value, must be one of true, false, yes, no, 1, or 0, not \"" + attrIsSupported + "\""); } boolean natGenerate; if (attrGenerate.equals("true") || attrGenerate.equals("yes") || attrGenerate.equals("1")) { natGenerate = true; } else if (attrGenerate.equals("false") || attrGenerate.equals("no") || attrGenerate.equals("0")) { natGenerate = false; } else { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Unexpected Generate value, must be one of true, false, yes, no, 1, or 0, not \"" + attrGenerate + "\""); } short natToolId0 = Short.parseShort(attrToolId0); Short natToolId1; if ((attrToolId1 == null) || (attrToolId1.length() <= 0)) { natToolId1 = null; } else { natToolId1 = new Short(Short.parseShort(attrToolId1)); } Short natToolId2; if ((attrToolId2 == null) || (attrToolId2.length() <= 0)) { natToolId2 = null; } else { natToolId2 = new Short(Short.parseShort(attrToolId2)); } Short natToolId3; if ((attrToolId3 == null) || (attrToolId3.length() <= 0)) { natToolId3 = null; } else { natToolId3 = new Short(Short.parseShort(attrToolId3)); } Short natToolId4; if ((attrToolId4 == null) || (attrToolId4.length() <= 0)) { natToolId4 = null; } else { natToolId4 = new Short(Short.parseShort(attrToolId4)); } Short natToolId5; if ((attrToolId5 == null) || (attrToolId5.length() <= 0)) { natToolId5 = null; } else { natToolId5 = new Short(Short.parseShort(attrToolId5)); } Short natToolId6; if ((attrToolId6 == null) || (attrToolId6.length() <= 0)) { natToolId6 = null; } else { natToolId6 = new Short(Short.parseShort(attrToolId6)); } Short natToolId7; if ((attrToolId7 == null) || (attrToolId7.length() <= 0)) { natToolId7 = null; } else { natToolId7 = new Short(Short.parseShort(attrToolId7)); } int natRevision = Integer.parseInt(attrRevision); // Get the parent context CFLibXmlCoreContext parentContext = curContext.getPrevContext(); // Instantiate a buffer for the parsed information ICFGenKbToolSetObj obj = schemaObj.getToolSetTableObj().newInstance(); CFGenKbToolSetBuff dataBuff = obj.getToolSetBuff(); dataBuff.setRequiredId(natId); dataBuff.setRequiredName(natName); dataBuff.setOptionalDescr(natDescr); dataBuff.setOptionalRevisionString(natRevisionString); dataBuff.setRequiredIsSupported(natIsSupported); dataBuff.setRequiredGenerate(natGenerate); dataBuff.setRequiredToolId0(natToolId0); dataBuff.setOptionalToolId1(natToolId1); dataBuff.setOptionalToolId2(natToolId2); dataBuff.setOptionalToolId3(natToolId3); dataBuff.setOptionalToolId4(natToolId4); dataBuff.setOptionalToolId5(natToolId5); dataBuff.setOptionalToolId6(natToolId6); dataBuff.setOptionalToolId7(natToolId7); dataBuff.setRequiredRevision(natRevision); obj.copyBuffToPKey(); SortedMap<CFGenKbToolSetPKey, ICFGenKbToolSetObj> sortedMap = (SortedMap<CFGenKbToolSetPKey, ICFGenKbToolSetObj>) xmsgRspnHandler .getSortedMapOfObjects(); ICFGenKbToolSetObj realized = (ICFGenKbToolSetObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); if (sortedMap != null) { sortedMap.put(realized.getPKey(), realized); } } catch (RuntimeException e) { throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } catch (Error e) { throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } }
From source file:com.emc.vipr.services.s3.ViPRS3Signer.java
/** * Calculate the canonical string for a REST/HTTP request to S3. * <p/>//from w w w.ja va 2 s . c o m * When expires is non-null, it will be used instead of the Date header. */ protected String makeS3CanonicalString(String method, String resource, Request<?> request, String expires) { StringBuilder buf = new StringBuilder(); buf.append(method).append("\n"); // Add all interesting headers to a list, then sort them. "Interesting" // is defined as Content-MD5, Content-Type, Date, and x-amz- and x-emc- Map<String, String> headersMap = request.getHeaders(); SortedMap<String, String> interestingHeaders = new TreeMap<String, String>(); if (headersMap != null && headersMap.size() > 0) { for (Map.Entry<String, String> entry : headersMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key == null) continue; String lk = key.toLowerCase(Locale.getDefault()); // Ignore any headers that are not particularly interesting. if (lk.equals("content-type") || lk.equals("content-md5") || lk.equals("date") || lk.startsWith(Headers.AMAZON_PREFIX) || lk.startsWith(ViPRConstants.EMC_PREFIX)) { interestingHeaders.put(lk, value); } } } // Remove default date timestamp if "x-amz-date" is set. if (interestingHeaders.containsKey(Headers.S3_ALTERNATE_DATE)) { interestingHeaders.put("date", ""); } // Use the expires value as the timestamp if it is available. This trumps both the default // "date" timestamp, and the "x-amz-date" header. if (expires != null) { interestingHeaders.put("date", expires); } // These headers require that we still put a new line in after them, // even if they don't exist. if (!interestingHeaders.containsKey("content-type")) { interestingHeaders.put("content-type", ""); } if (!interestingHeaders.containsKey("content-md5")) { interestingHeaders.put("content-md5", ""); } // Any parameters that are prefixed with "x-amz-" need to be included // in the headers section of the canonical string to sign for (Map.Entry<String, String> parameter : request.getParameters().entrySet()) { if (parameter.getKey().startsWith("x-amz-")) { interestingHeaders.put(parameter.getKey(), parameter.getValue()); } } // Add all the interesting headers (i.e.: all that startwith x-amz- or x-emc- ;-)) for (Map.Entry<String, String> entry : interestingHeaders.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (key.startsWith(Headers.AMAZON_PREFIX) || key.startsWith(ViPRConstants.EMC_PREFIX)) { buf.append(key).append(':').append(value); } else { buf.append(value); } buf.append("\n"); } // Add all the interesting parameters buf.append(resource); String[] parameterNames = request.getParameters().keySet() .toArray(new String[request.getParameters().size()]); Arrays.sort(parameterNames); char separator = '?'; for (String parameterName : parameterNames) { // Skip any parameters that aren't part of the canonical signed string if (!SIGNED_PARAMETERS.contains(parameterName)) continue; buf.append(separator); buf.append(parameterName); String parameterValue = request.getParameters().get(parameterName); if (parameterValue != null) { buf.append("=").append(parameterValue); } separator = '&'; } return buf.toString(); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamISOLanguageTable.java
public void createISOLanguage(CFAccAuthorization Authorization, CFAccISOLanguageBuff Buff) { CFAccISOLanguagePKey pkey = schema.getFactoryISOLanguage().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); Buff.setRequiredId(pkey.getRequiredId()); CFAccISOLanguageByBaseIdxKey keyBaseIdx = schema.getFactoryISOLanguage().newBaseIdxKey(); keyBaseIdx.setRequiredBaseLanguageCode(Buff.getRequiredBaseLanguageCode()); CFAccISOLanguageByCountryIdxKey keyCountryIdx = schema.getFactoryISOLanguage().newCountryIdxKey(); keyCountryIdx.setOptionalISOCountryId(Buff.getOptionalISOCountryId()); CFAccISOLanguageByCodeIdxKey keyCodeIdx = schema.getFactoryISOLanguage().newCodeIdxKey(); keyCodeIdx.setRequiredISOCode(Buff.getRequiredISOCode()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createISOLanguage", pkey);//from w ww . j av a 2s . c o m } if (dictByCodeIdx.containsKey(keyCodeIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createISOLanguage", "ISOLanguageCodeIdx", keyCodeIdx); } // Validate foreign keys // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAccISOLanguagePKey, CFAccISOLanguageBuff> subdictBaseIdx; if (dictByBaseIdx.containsKey(keyBaseIdx)) { subdictBaseIdx = dictByBaseIdx.get(keyBaseIdx); } else { subdictBaseIdx = new TreeMap<CFAccISOLanguagePKey, CFAccISOLanguageBuff>(); dictByBaseIdx.put(keyBaseIdx, subdictBaseIdx); } subdictBaseIdx.put(pkey, Buff); SortedMap<CFAccISOLanguagePKey, CFAccISOLanguageBuff> subdictCountryIdx; if (dictByCountryIdx.containsKey(keyCountryIdx)) { subdictCountryIdx = dictByCountryIdx.get(keyCountryIdx); } else { subdictCountryIdx = new TreeMap<CFAccISOLanguagePKey, CFAccISOLanguageBuff>(); dictByCountryIdx.put(keyCountryIdx, subdictCountryIdx); } subdictCountryIdx.put(pkey, Buff); dictByCodeIdx.put(keyCodeIdx, Buff); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamISOLanguageTable.java
public void createISOLanguage(CFAstAuthorization Authorization, CFAstISOLanguageBuff Buff) { CFAstISOLanguagePKey pkey = schema.getFactoryISOLanguage().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); Buff.setRequiredId(pkey.getRequiredId()); CFAstISOLanguageByBaseIdxKey keyBaseIdx = schema.getFactoryISOLanguage().newBaseIdxKey(); keyBaseIdx.setRequiredBaseLanguageCode(Buff.getRequiredBaseLanguageCode()); CFAstISOLanguageByCountryIdxKey keyCountryIdx = schema.getFactoryISOLanguage().newCountryIdxKey(); keyCountryIdx.setOptionalISOCountryId(Buff.getOptionalISOCountryId()); CFAstISOLanguageByCodeIdxKey keyCodeIdx = schema.getFactoryISOLanguage().newCodeIdxKey(); keyCodeIdx.setRequiredISOCode(Buff.getRequiredISOCode()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createISOLanguage", pkey);/* ww w . j a v a 2 s .co m*/ } if (dictByCodeIdx.containsKey(keyCodeIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createISOLanguage", "ISOLanguageCodeIdx", keyCodeIdx); } // Validate foreign keys // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAstISOLanguagePKey, CFAstISOLanguageBuff> subdictBaseIdx; if (dictByBaseIdx.containsKey(keyBaseIdx)) { subdictBaseIdx = dictByBaseIdx.get(keyBaseIdx); } else { subdictBaseIdx = new TreeMap<CFAstISOLanguagePKey, CFAstISOLanguageBuff>(); dictByBaseIdx.put(keyBaseIdx, subdictBaseIdx); } subdictBaseIdx.put(pkey, Buff); SortedMap<CFAstISOLanguagePKey, CFAstISOLanguageBuff> subdictCountryIdx; if (dictByCountryIdx.containsKey(keyCountryIdx)) { subdictCountryIdx = dictByCountryIdx.get(keyCountryIdx); } else { subdictCountryIdx = new TreeMap<CFAstISOLanguagePKey, CFAstISOLanguageBuff>(); dictByCountryIdx.put(keyCountryIdx, subdictCountryIdx); } subdictCountryIdx.put(pkey, Buff); dictByCodeIdx.put(keyCodeIdx, Buff); }
From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java
/** * Merge two Maps together. In the event of any key collisions the Master map wins * * Any blank value keys are dropped from the final Map * * Map is sorted by value (String) length * * @param master//w w w .java2s.c o m * @param slave * @return */ private SortedMap<String, String> mergeMaps(SortedMap<String, String> master, SortedMap<String, String> slave) { SortedMap<String, String> map = new TreeMap<String, String>(new StringLengthComparator()); for (final String key : master.keySet()) { if (StringUtils.isNotBlank(master.get(key))) { map.put(key, master.get(key)); } } for (final String key : slave.keySet()) { if (master.containsKey(key)) { continue; } if (StringUtils.isNotBlank(slave.get(key))) { map.put(key, slave.get(key)); } } return map; }
From source file:net.sourceforge.msscodefactory.cfcore.v1_11.GenKbRam.GenKbRamContactURLTable.java
public void createContactURL(GenKbAuthorization Authorization, GenKbContactURLBuff Buff) { GenKbContactURLPKey pkey = schema.getFactoryContactURL().newPKey(); pkey.setRequiredContactURLId(schema.nextContactURLIdGen()); Buff.setRequiredContactURLId(pkey.getRequiredContactURLId()); GenKbContactURLByContactIdxKey keyContactIdx = schema.getFactoryContactURL().newContactIdxKey(); keyContactIdx.setRequiredContactId(Buff.getRequiredContactId()); GenKbContactURLByProtocolIdxKey keyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey(); keyProtocolIdx.setOptionalURLProtocolId(Buff.getOptionalURLProtocolId()); GenKbContactURLByUNameIdxKey keyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey(); keyUNameIdx.setRequiredContactId(Buff.getRequiredContactId()); keyUNameIdx.setRequiredName(Buff.getRequiredName()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createContactURL", pkey);/*from w ww .j a va 2 s . c om*/ } if (dictByUNameIdx.containsKey(keyUNameIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createContactURL", "ContactURLUNameIdx", keyUNameIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableContact().readDerivedByPIdx(Authorization, Buff.getRequiredContactId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createContactURL", "Container", "Contact", "Contact", null); } } } { boolean allNull = true; if (Buff.getOptionalURLProtocolId() != null) { allNull = false; } if (!allNull) { if (null == schema.getTableURLProtocol().readDerivedByPIdx(Authorization, Buff.getOptionalURLProtocolId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createContactURL", "Lookup", "URLProtocol", "URLProtocol", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<GenKbContactURLPKey, GenKbContactURLBuff> subdictContactIdx; if (dictByContactIdx.containsKey(keyContactIdx)) { subdictContactIdx = dictByContactIdx.get(keyContactIdx); } else { subdictContactIdx = new TreeMap<GenKbContactURLPKey, GenKbContactURLBuff>(); dictByContactIdx.put(keyContactIdx, subdictContactIdx); } subdictContactIdx.put(pkey, Buff); SortedMap<GenKbContactURLPKey, GenKbContactURLBuff> subdictProtocolIdx; if (dictByProtocolIdx.containsKey(keyProtocolIdx)) { subdictProtocolIdx = dictByProtocolIdx.get(keyProtocolIdx); } else { subdictProtocolIdx = new TreeMap<GenKbContactURLPKey, GenKbContactURLBuff>(); dictByProtocolIdx.put(keyProtocolIdx, subdictProtocolIdx); } subdictProtocolIdx.put(pkey, Buff); dictByUNameIdx.put(keyUNameIdx, Buff); }
From source file:eu.itesla_project.modules.histo.IIDM2DB.java
public static JSONArray toTopoSet(VoltageLevel vl) throws JSONException { SortedMap<String, JSONArray> topoList = new TreeMap<>(); Multimap<String, String> topoTmp = HashMultimap.create(); vl.visitEquipments(new TerminalTopologyVisitor() { @Override/*from ww w . j av a 2 s . co m*/ public void visitTerminal(Terminal t) { Connectable c = t.getConnectable(); Bus b = t.getBusView().getBus(); if (b == null) { if (c.getType() == ConnectableType.LOAD || c.getType() == ConnectableType.GENERATOR || c.getType() == ConnectableType.SHUNT_COMPENSATOR) { // add the injection in the topo set even if not connected but just connectable to this bus // see WP4.2 data mining topology spec for more detailed information b = t.getBusView().getConnectableBus(); } } if (b != null) { topoTmp.put(b.getId(), c.getId()); } else { // connect the equipment to its own bus topoTmp.put(c.getId() + "FICTIVE_BUS", c.getId()); } } }); for (Map.Entry<String, Collection<String>> entry : topoTmp.asMap().entrySet()) { SortedSet<String> topoContent = new TreeSet<>(entry.getValue()); JSONArray topoArray = new JSONArray(topoContent.toArray(new String[] {})); topoList.put(topoArray.toString(), topoArray); } return new JSONArray(topoList.values().toArray(new JSONArray[] {})); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamTenantTable.java
public void createTenant(CFAstAuthorization Authorization, CFAstTenantBuff Buff) { CFAstTenantPKey pkey = schema.getFactoryTenant().newPKey(); pkey.setRequiredId(schema.nextTenantIdGen()); Buff.setRequiredId(pkey.getRequiredId()); CFAstTenantByClusterIdxKey keyClusterIdx = schema.getFactoryTenant().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFAstTenantByUNameIdxKey keyUNameIdx = schema.getFactoryTenant().newUNameIdxKey(); keyUNameIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyUNameIdx.setRequiredTenantName(Buff.getRequiredTenantName()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createTenant", pkey); }//from w w w . j a v a 2 s .c om if (dictByUNameIdx.containsKey(keyUNameIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createTenant", "TenantUNameIdx", keyUNameIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createTenant", "Container", "TenantCluster", "Cluster", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAstTenantPKey, CFAstTenantBuff> subdictClusterIdx; if (dictByClusterIdx.containsKey(keyClusterIdx)) { subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx); } else { subdictClusterIdx = new TreeMap<CFAstTenantPKey, CFAstTenantBuff>(); dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx); } subdictClusterIdx.put(pkey, Buff); dictByUNameIdx.put(keyUNameIdx, Buff); }
From source file:jenkins.scm.impl.subversion.SubversionSCMSource.java
/** * Groups a set of path segments based on a supplied prefix. * * @param pathSegments the input path segments. * @param prefix the prefix to group on. * @return a map, all keys will {@link #startsWith(java.util.List, java.util.List)} the input prefix and be longer * than the input prefix, all values will {@link #startsWith(java.util.List, * java.util.List)} their corresponding key. *//*from ww w . jav a 2 s . c o m*/ @NonNull static SortedMap<List<String>, SortedSet<List<String>>> groupPaths( @NonNull SortedSet<List<String>> pathSegments, @NonNull List<String> prefix) { // ensure pre-condition is valid and ensure we are using a copy pathSegments = filterPaths(pathSegments, prefix); SortedMap<List<String>, SortedSet<List<String>>> result = new TreeMap<List<String>, SortedSet<List<String>>>( COMPARATOR); while (!pathSegments.isEmpty()) { List<String> longestPrefix = null; int longestIndex = -1; for (List<String> pathSegment : pathSegments) { if (longestPrefix == null) { longestPrefix = pathSegment; longestIndex = indexOfNextWildcard(pathSegment, prefix.size()); } else { int index = indexOfNextWildcard(pathSegment, prefix.size()); if (index > longestIndex) { longestPrefix = pathSegment; longestIndex = index; } } } assert longestPrefix != null; longestPrefix = new ArrayList<String>(longestPrefix.subList(0, longestIndex)); SortedSet<List<String>> group = filterPaths(pathSegments, longestPrefix); result.put(longestPrefix, group); pathSegments.removeAll(group); } String optimization; while (null != (optimization = getOptimizationPoint(result.keySet(), prefix.size()))) { List<String> optimizedPrefix = copyAndAppend(prefix, optimization); SortedSet<List<String>> optimizedGroup = new TreeSet<List<String>>(COMPARATOR); for (Iterator<Map.Entry<List<String>, SortedSet<List<String>>>> iterator = result.entrySet() .iterator(); iterator.hasNext();) { Map.Entry<List<String>, SortedSet<List<String>>> entry = iterator.next(); if (startsWith(entry.getKey(), optimizedPrefix)) { iterator.remove(); optimizedGroup.addAll(entry.getValue()); } } result.put(optimizedPrefix, optimizedGroup); } return result; }