Java Code Examples for java.util.LinkedHashMap#values()
The following examples show how to use
java.util.LinkedHashMap#values() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBootConfigProvider.java From spring-boot-keycloak-server-example with Apache License 2.0 | 6 votes |
@Override public String[] getArray(String key) { Object obj = getObject(key, null); if (obj == null) { return new String[0]; } // TODO find better way to parse config yaml into a list instead of a LinkedHashMap in the first place if (obj instanceof LinkedHashMap) { LinkedHashMap lm = (LinkedHashMap) obj; String[] strings = new String[lm.size()]; int i = 0; for (Object entryValue : lm.values()) { strings[i++] = String.valueOf(entryValue); } return strings; } return (String[]) obj; }
Example 2
Source File: SpatialHeatmapFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Called by FacetComponent's impl of * {@link org.apache.solr.handler.component.SearchComponent#modifyRequest(ResponseBuilder, SearchComponent, ShardRequest)}. */ public static void distribModifyRequest(ShardRequest sreq, LinkedHashMap<String, HeatmapFacet> heatmapFacets) { // Set the format to PNG because it's compressed and it's the only format we have code to read at the moment. // We re-write the facet.heatmap list with PNG format in local-params where it has highest precedence. //Remove existing heatmap field param vals; we will rewrite sreq.params.remove(FacetParams.FACET_HEATMAP); for (HeatmapFacet facet : heatmapFacets.values()) { //add heatmap field param ModifiableSolrParams newLocalParams = new ModifiableSolrParams(); if (facet.localParams != null) { newLocalParams.add(facet.localParams); } // Set format to PNG; it's the only one we parse newLocalParams.set(FacetParams.FACET_HEATMAP_FORMAT, FacetHeatmap.FORMAT_PNG); sreq.params.add(FacetParams.FACET_HEATMAP, newLocalParams.toLocalParamsString() + facet.facetOn); } }
Example 3
Source File: MetadataWriter.java From j2objc with Apache License 2.0 | 6 votes |
private Expression createAnnotations(List<Annotation> annotations) { // Group repeated annotations. LinkedHashMap<DeclaredType, List<Annotation>> groupedAnnotations = new LinkedHashMap<>(); for (Annotation annotation : annotations) { DeclaredType type = annotation.getAnnotationMirror().getAnnotationType(); groupedAnnotations.computeIfAbsent(type, k -> new ArrayList<>()).add(annotation); } List<Expression> expressions = new ArrayList<>(); for (List<Annotation> group : groupedAnnotations.values()) { if (group.size() == 1) { expressions.add(translationUtil.createAnnotation(group.get(0).getAnnotationMirror())); } else { expressions.add(createContainerAnnotation(group)); } } return translationUtil.createObjectArray(expressions, annotationArray); }
Example 4
Source File: StreamingFileCommitter.java From flink with Apache License 2.0 | 6 votes |
private void commitPartitions(long checkpointId) throws Exception { List<String> partitions = checkpointId == Long.MAX_VALUE ? trigger.endInput() : trigger.committablePartitions(checkpointId); if (partitions.isEmpty()) { return; } try (TableMetaStoreFactory.TableMetaStore metaStore = metaStoreFactory.createTableMetaStore()) { for (String partition : partitions) { LinkedHashMap<String, String> partSpec = extractPartitionSpecFromPath(new Path(partition)); LOG.info("Partition {} of table {} is ready to be committed", partSpec, tableIdentifier); Path path = new Path(locationPath, generatePartitionPath(partSpec)); PartitionCommitPolicy.Context context = new PolicyContext( new ArrayList<>(partSpec.values()), path); for (PartitionCommitPolicy policy : policies) { if (policy instanceof MetastoreCommitPolicy) { ((MetastoreCommitPolicy) policy).setMetastore(metaStore); } policy.commit(context); } } } }
Example 5
Source File: FastaWriter.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
public static void main(String[] args) { try { FileInputStream is = new FileInputStream("/Users/Scooter/scripps/dyadic/c1-454Scaffolds.faa"); FastaReader<ProteinSequence, AminoAcidCompound> fastaReader = new FastaReader<ProteinSequence, AminoAcidCompound>(is, new GenericFastaHeaderParser<ProteinSequence, AminoAcidCompound>(), new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())); LinkedHashMap<String, ProteinSequence> proteinSequences = fastaReader.process(); is.close(); // logger.debug(proteinSequences); FileOutputStream fileOutputStream = new FileOutputStream("/Users/Scooter/scripps/dyadic/c1-454Scaffolds_temp.faa"); BufferedOutputStream bo = new BufferedOutputStream(fileOutputStream); long start = System.currentTimeMillis(); FastaWriter<ProteinSequence, AminoAcidCompound> fastaWriter = new FastaWriter<ProteinSequence, AminoAcidCompound>(bo, proteinSequences.values(), new GenericFastaHeaderFormat<ProteinSequence, AminoAcidCompound>()); fastaWriter.process(); bo.close(); long end = System.currentTimeMillis(); logger.info("Took {} seconds", (end - start)); fileOutputStream.close(); } catch (IOException e) { logger.warn("Exception: ", e); } }
Example 6
Source File: LayoutTransition.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Starts the animations set up for a CHANGING transition. We separate the setup of these * animations from actually starting them, to avoid side-effects that starting the animations * may have on the properties of the affected objects. After setup, we tell the affected parent * that this transition should be started. The parent informs its ViewAncestor, which then * starts the transition after the current layout/measurement phase, just prior to drawing * the view hierarchy. * * @hide */ public void startChangingAnimations() { LinkedHashMap<View, Animator> currentAnimCopy = (LinkedHashMap<View, Animator>) currentChangingAnimations.clone(); for (Animator anim : currentAnimCopy.values()) { if (anim instanceof ObjectAnimator) { ((ObjectAnimator) anim).setCurrentPlayTime(0); } anim.start(); } }
Example 7
Source File: GeneFeatureHelperTest.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test of getGeneSequences method, of class GeneFeatureHelper. */ @Test public void testGetGeneSequences() throws Exception { // logger.info("getGeneSequences"); LinkedHashMap<String, ChromosomeSequence> chromosomeSequenceList = GeneFeatureHelper .loadFastaAddGeneFeaturesFromGmodGFF3(new File("src/test/resources/volvox_all.fna"), new File( "src/test/resources/volvox.gff3"), true); LinkedHashMap<String, GeneSequence> geneSequenceHashMap = GeneFeatureHelper .getGeneSequences(chromosomeSequenceList.values()); Collection<GeneSequence> geneSequences = geneSequenceHashMap.values(); File tmp = File.createTempFile("volvox_all_genes_exon_uppercase", "fna"); tmp.deleteOnExit(); FastaWriterHelper.writeGeneSequence(tmp, geneSequences, true); }
Example 8
Source File: MCRTransferPackage.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * Builds the transfer package. * * @throws MCRUsageException is thrown if some of the referenced objects or derivates couldn't be retrieved */ public void build() throws MCRUsageException { LinkedHashMap<MCRObjectID, MCRObject> objectMap = new LinkedHashMap<>(); Set<MCRCategoryID> categories = new HashSet<>(); resolveChildrenAndLinks(source, objectMap, categories); this.objects = new LinkedHashSet<>(objectMap.values()); this.classifications = categories.stream().map(MCRCategoryID::getRootID).distinct().collect(Collectors.toSet()); this.fileContainers = buildFileContainers(source); }
Example 9
Source File: LinkedHashMapTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.util.LinkedHashMap#clone() */ public void test_clone() { // Test for method java.lang.Object java.util.LinkedHashMap.clone() LinkedHashMap hm2 = (LinkedHashMap) hm.clone(); assertTrue("Clone answered equivalent LinkedHashMap", hm2 != hm); for (int counter = 0; counter < hmSize; counter++) assertTrue("Clone answered unequal LinkedHashMap", hm .get(objArray2[counter]) == hm2.get(objArray2[counter])); LinkedHashMap map = new LinkedHashMap(); map.put("key", "value"); // get the keySet() and values() on the original Map Set keys = map.keySet(); Collection values = map.values(); assertEquals("values() does not work", "value", values.iterator().next()); assertEquals("keySet() does not work", "key", keys.iterator().next()); AbstractMap map2 = (AbstractMap) map.clone(); map2.put("key", "value2"); Collection values2 = map2.values(); assertTrue("values() is identical", values2 != values); // values() and keySet() on the cloned() map should be different assertEquals("values() was not cloned", "value2", values2.iterator().next()); map2.clear(); map2.put("key2", "value3"); Set key2 = map2.keySet(); assertTrue("keySet() is identical", key2 != keys); assertEquals("keySet() was not cloned", "key2", key2.iterator().next()); }
Example 10
Source File: PartnerBookmarksReader.java From delion with Apache License 2.0 | 5 votes |
private void recreateFolderHierarchy(LinkedHashMap<Long, Bookmark> idMap) { for (Bookmark bookmark : idMap.values()) { if (bookmark.mId == ROOT_FOLDER_ID) continue; // Look for invalid parent ids and self-cycles. if (!idMap.containsKey(bookmark.mParentId) || bookmark.mParentId == bookmark.mId) { bookmark.mParent = idMap.get(ROOT_FOLDER_ID); bookmark.mParent.mEntries.add(bookmark); continue; } bookmark.mParent = idMap.get(bookmark.mParentId); bookmark.mParent.mEntries.add(bookmark); } }
Example 11
Source File: RPackagesUtils.java From nexus-repository-r with Eclipse Public License 1.0 | 5 votes |
public static List<Map<String, String>> merge(List<List<Map<String, String>>> parts) { final LinkedHashMap<String, Map<String, String>> merged = new LinkedHashMap<>(); for (List<Map<String, String>> part : parts) { for (Map<String, String> thisEntry : part) { merged.putIfAbsent(thisEntry.get(P_PACKAGE), thisEntry); } } return new ArrayList<>(merged.values()); }
Example 12
Source File: RecentEntityMenuBase.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
public static List<MenuItem> getMenuItems(ArrayList<RecentEntityMenuBase> menus) { LinkedHashMap<String, MenuItem> menuItems = new LinkedHashMap<String, MenuItem>(); if (menus != null && menus.size() > 0) { Iterator<RecentEntityMenuBase> it = menus.iterator(); while (it.hasNext()) { findMenuItems(it.next().createMenuModel(WebUtil.getSessionScopeBean(), 0).getContents(), menuItems); } } return new ArrayList<MenuItem>(menuItems.values()); }
Example 13
Source File: DocTimeReporter.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sorts LinkedHashMap by its values(natural descending order). keeps the * duplicates as it is. * * @param passedMap * An Object of type LinkedHashMap to be sorted by its values. * @return An Object containing the sorted LinkedHashMap. */ private LinkedHashMap<?,?> sortHashMapByValues(LinkedHashMap<String,String> passedMap) { List<String> mapKeys = new ArrayList<String>(passedMap.keySet()); List<String> mapValues = new ArrayList<String>(passedMap.values()); Collections.sort(mapValues, new ValueComparator()); Collections.sort(mapKeys); // Reversing the collection to sort the values in descending order Collections.reverse(mapValues); LinkedHashMap<String,String> sortedMap = new LinkedHashMap<String,String>(); Iterator<String> valueIt = mapValues.iterator(); while (valueIt.hasNext()) { String val = valueIt.next(); Iterator<String> keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { String key = keyIt.next(); String comp1 = passedMap.get(key); String comp2 = val; if (comp1.equals(comp2)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put(key, val); break; } } } return sortedMap; }
Example 14
Source File: PRTimeReporter.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sorts LinkedHashMap by its values(natural descending order). keeps the * duplicates as it is. * * @param passedMap * An Object of type LinkedHashMap to be sorted by its values. * * @return An Object containing the sorted LinkedHashMap. */ private LinkedHashMap<String,String> sortHashMapByValues(LinkedHashMap<String,String> passedMap) { List<String> mapKeys = new ArrayList<String>(passedMap.keySet()); List<String> mapValues = new ArrayList<String>(passedMap.values()); Collections.sort(mapValues, new ValueComparator()); Collections.sort(mapKeys); Collections.reverse(mapValues); LinkedHashMap<String,String> sortedMap = new LinkedHashMap<String,String>(); Iterator<String> valueIt = mapValues.iterator(); while (valueIt.hasNext()) { String val = valueIt.next(); Iterator<String> keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { String key = keyIt.next(); String comp1 = passedMap.get(key); String comp2 = val; if (comp1.equals(comp2)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put(key, val); break; } } } return sortedMap; }
Example 15
Source File: GenerateLexerRulesForLiteralsAction.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void actionPerformed(AnActionEvent e) { LOG.info("actionPerformed GenerateLexerRulesForLiteralsAction"); final Project project = e.getProject(); final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); if (psiFile == null) { return; } String inputText = psiFile.getText(); ParsingResult results = ParsingUtils.parseANTLRGrammar(inputText); final Parser parser = results.parser; final ParseTree tree = results.tree; Collection<ParseTree> literalNodes = XPath.findAll(tree, "//ruleBlock//STRING_LITERAL", parser); LinkedHashMap<String, String> lexerRules = new LinkedHashMap<String, String>(); for (ParseTree node : literalNodes) { String literal = node.getText(); String ruleText = String.format("%s : %s ;", RefactorUtils.getLexerRuleNameFromLiteral(literal), literal); lexerRules.put(literal, ruleText); } // remove those already defined String lexerRulesXPath = "//lexerRule"; String treePattern = "<TOKEN_REF> : <STRING_LITERAL>;"; ParseTreePattern p = parser.compileParseTreePattern(treePattern, ANTLRv4Parser.RULE_lexerRule); List<ParseTreeMatch> matches = p.findAll(tree, lexerRulesXPath); for (ParseTreeMatch match : matches) { ParseTree lit = match.get("STRING_LITERAL"); if (lexerRules.containsKey(lit.getText())) { // we have rule for this literal already lexerRules.remove(lit.getText()); } } final LiteralChooser chooser = new LiteralChooser(project, new ArrayList<String>(lexerRules.values())); chooser.show(); List<String> selectedElements = chooser.getSelectedElements(); // chooser disposed automatically. final Editor editor = e.getData(PlatformDataKeys.EDITOR); final Document doc = editor.getDocument(); final CommonTokenStream tokens = (CommonTokenStream) parser.getTokenStream(); // System.out.println(selectedElements); if (selectedElements != null) { String text = doc.getText(); int cursorOffset = editor.getCaretModel().getOffset(); // make sure it's not in middle of rule; put between. // System.out.println("offset "+cursorOffset); Collection<ParseTree> allRuleNodes = XPath.findAll(tree, "//ruleSpec", parser); for (ParseTree r : allRuleNodes) { Interval extent = r.getSourceInterval(); // token indexes int start = tokens.get(extent.a).getStartIndex(); int stop = tokens.get(extent.b).getStopIndex(); // System.out.println("rule "+r.getChild(0).getText()+": "+start+".."+stop); if (cursorOffset < start) { // before this rule, so must be between previous and this one cursorOffset = start; // put right before this rule break; } else if (cursorOffset >= start && cursorOffset <= stop) { // cursor in this rule cursorOffset = stop + 2; // put right before this rule (after newline) if (cursorOffset >= text.length()) { cursorOffset = text.length(); } break; } } String allRules = Utils.join(selectedElements.iterator(), "\n"); text = text.substring(0, cursorOffset) + "\n" + allRules + "\n" + text.substring(cursorOffset, text.length()); MyPsiUtils.replacePsiFileFromText(project, psiFile, text); } }
Example 16
Source File: SpnegoAuthenticator.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
private void fix() { /* * Useful references: * http://tools.ietf.org/html/rfc4121#page-5 * http://tools.ietf.org/html/rfc2743#page-81 * https://msdn.microsoft.com/en-us/library/ms995330.aspx */ // Scan until we find the mech types list. If we find anything // unexpected, abort the fix process. if (!tag(0x60)) return; if (!length()) return; if (!oid("1.3.6.1.5.5.2")) return; if (!tag(0xa0)) return; if (!length()) return; if (!tag(0x30)) return; if (!length()) return; if (!tag(0xa0)) return; lengthAsInt(); if (!tag(0x30)) return; // Now at the start of the mechType list. // Read the mechTypes into an ordered set int mechTypesLen = lengthAsInt(); int mechTypesStart = pos; LinkedHashMap<String, int[]> mechTypeEntries = new LinkedHashMap<String, int[]>(); while (pos < mechTypesStart + mechTypesLen) { int[] value = new int[2]; value[0] = pos; String key = oidAsString(); value[1] = pos - value[0]; mechTypeEntries.put(key, value); } // Now construct the re-ordered mechType list byte[] replacement = new byte[mechTypesLen]; int replacementPos = 0; int[] first = mechTypeEntries.remove("1.2.840.113554.1.2.2"); if (first != null) { System.arraycopy(token, first[0], replacement, replacementPos, first[1]); replacementPos += first[1]; } for (int[] markers : mechTypeEntries.values()) { System.arraycopy(token, markers[0], replacement, replacementPos, markers[1]); replacementPos += markers[1]; } // Finally, replace the original mechType list with the re-ordered // one. System.arraycopy(replacement, 0, token, mechTypesStart, mechTypesLen); }
Example 17
Source File: TeiidRSProvider.java From teiid-spring-boot with Apache License 2.0 | 4 votes |
private InputStream executeProc(Connection conn, String procedureName, LinkedHashMap<String, Object> parameters, String charSet, boolean usingReturn) throws SQLException { // the generated code sends a empty string rather than null. if (charSet != null && charSet.trim().isEmpty()) { charSet = null; } Object result = null; StringBuilder sb = new StringBuilder(); sb.append("{ "); //$NON-NLS-1$ if (usingReturn) { sb.append("? = "); //$NON-NLS-1$ } sb.append("CALL ").append(procedureName); //$NON-NLS-1$ sb.append("("); //$NON-NLS-1$ boolean first = true; for (Map.Entry<String, Object> entry : parameters.entrySet()) { if (entry.getValue() == null) { continue; } if (!first) { sb.append(", "); //$NON-NLS-1$ } first = false; sb.append(SQLStringVisitor.escapeSinglePart(entry.getKey())).append("=>?"); //$NON-NLS-1$ } sb.append(") }"); //$NON-NLS-1$ CallableStatement statement = conn.prepareCall(sb.toString()); if (!parameters.isEmpty()) { int i = usingReturn ? 2 : 1; for (Object value : parameters.values()) { if (value == null) { continue; } statement.setObject(i++, value); } } final boolean hasResultSet = statement.execute(); if (hasResultSet) { ResultSet rs = statement.getResultSet(); if (rs.next()) { result = rs.getObject(1); } else { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Only result producing procedures are allowed"); } } else if (usingReturn) { result = statement.getObject(1); } return handleResult(charSet, result); }
Example 18
Source File: SpnegoAuthenticator.java From Tomcat8-Source-Read with MIT License | 4 votes |
private void fix() { /* * Useful references: * http://tools.ietf.org/html/rfc4121#page-5 * http://tools.ietf.org/html/rfc2743#page-81 * https://msdn.microsoft.com/en-us/library/ms995330.aspx */ // Scan until we find the mech types list. If we find anything // unexpected, abort the fix process. if (!tag(0x60)) return; if (!length()) return; if (!oid("1.3.6.1.5.5.2")) return; if (!tag(0xa0)) return; if (!length()) return; if (!tag(0x30)) return; if (!length()) return; if (!tag(0xa0)) return; lengthAsInt(); if (!tag(0x30)) return; // Now at the start of the mechType list. // Read the mechTypes into an ordered set int mechTypesLen = lengthAsInt(); int mechTypesStart = pos; LinkedHashMap<String, int[]> mechTypeEntries = new LinkedHashMap<>(); while (pos < mechTypesStart + mechTypesLen) { int[] value = new int[2]; value[0] = pos; String key = oidAsString(); value[1] = pos - value[0]; mechTypeEntries.put(key, value); } // Now construct the re-ordered mechType list byte[] replacement = new byte[mechTypesLen]; int replacementPos = 0; int[] first = mechTypeEntries.remove("1.2.840.113554.1.2.2"); if (first != null) { System.arraycopy(token, first[0], replacement, replacementPos, first[1]); replacementPos += first[1]; } for (int[] markers : mechTypeEntries.values()) { System.arraycopy(token, markers[0], replacement, replacementPos, markers[1]); replacementPos += markers[1]; } // Finally, replace the original mechType list with the re-ordered // one. System.arraycopy(replacement, 0, token, mechTypesStart, mechTypesLen); }
Example 19
Source File: DbSiteService.java From sakai with Educational Community License v2.0 | 4 votes |
/** * @inheritDoc */ @SuppressWarnings("unchecked") public List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, List excludedSites, SortType sort, PagingPosition page, boolean requireDescription, String userId) { userId = getCurrentUserIdIfNull(userId); List<String> siteIds = getSiteIds(type, ofType, criteria, propertyCriteria, excludedSites, sort, page, userId); LinkedHashMap<String, Site> siteMap = getOrderedSiteMap(siteIds, requireDescription); SqlReader reader = requireDescription ? fullSiteReader : lightSiteReader; String order = null; if ((sort != SortType.CREATED_BY_ASC) && (sort != SortType.CREATED_BY_DESC) && (sort != SortType.MODIFIED_BY_ASC) && (sort != SortType.MODIFIED_BY_DESC)) { order = getSitesOrder(sort); } // Account for limitations in the number of IN parameters we can use by batching // Load just the sites that weren't found in cache List<String> siteIdsToLoad = siteMap.entrySet().stream().filter(e -> e.getValue() == null) .map(Map.Entry::getKey).collect(Collectors.toList()); int remaining = siteIdsToLoad.size(); while (remaining > 0) { // We are using fixed sized buckets for IN clause parameters, up to the platform maximum number and filling // with as many values as we have for this batch. This is to prepare a small number of queries and tabulate // query statistics in a meaningful way. Any remaining slots are filled with null, which optimizes nicely // and does not affect results against a non-null column (as with IDs). // Fill a bucket by passing the sublist from our current element to the end (remaining length) int start = siteIdsToLoad.size() - remaining; Object[] values = getFilledBucket(siteIdsToLoad.subList(start, start + remaining)); int bucketSize = values.length; String where = getWhereSiteIdIn(values); List<Site> dbSites; dbSites = (List<Site>) getSelectedResources(where, order, values, null, reader); // Cache the sites we retrieved and put them in the right ordered slots for return for (Site site : dbSites) { cacheSite(site); siteMap.put(site.getId(), site); } remaining -= bucketSize; } // Ensure we don't have any nulls in the return list for (Iterator<Site> i = siteMap.values().iterator(); i.hasNext(); ) { if (i.next() == null) i.remove(); } return new ArrayList<>(siteMap.values()); }
Example 20
Source File: SpnegoAuthenticator.java From tomcatsrc with Apache License 2.0 | 4 votes |
private void fix() { /* * Useful references: * http://tools.ietf.org/html/rfc4121#page-5 * http://tools.ietf.org/html/rfc2743#page-81 * https://msdn.microsoft.com/en-us/library/ms995330.aspx */ // Scan until we find the mech types list. If we find anything // unexpected, abort the fix process. if (!tag(0x60)) return; if (!length()) return; if (!oid("1.3.6.1.5.5.2")) return; if (!tag(0xa0)) return; if (!length()) return; if (!tag(0x30)) return; if (!length()) return; if (!tag(0xa0)) return; lengthAsInt(); if (!tag(0x30)) return; // Now at the start of the mechType list. // Read the mechTypes into an ordered set int mechTypesLen = lengthAsInt(); int mechTypesStart = pos; LinkedHashMap<String, int[]> mechTypeEntries = new LinkedHashMap<String, int[]>(); while (pos < mechTypesStart + mechTypesLen) { int[] value = new int[2]; value[0] = pos; String key = oidAsString(); value[1] = pos - value[0]; mechTypeEntries.put(key, value); } // Now construct the re-ordered mechType list byte[] replacement = new byte[mechTypesLen]; int replacementPos = 0; int[] first = mechTypeEntries.remove("1.2.840.113554.1.2.2"); if (first != null) { System.arraycopy(token, first[0], replacement, replacementPos, first[1]); replacementPos += first[1]; } for (int[] markers : mechTypeEntries.values()) { System.arraycopy(token, markers[0], replacement, replacementPos, markers[1]); replacementPos += markers[1]; } // Finally, replace the original mechType list with the re-ordered // one. System.arraycopy(replacement, 0, token, mechTypesStart, mechTypesLen); }