Java Code Examples for java.util.List#indexOf()
The following examples show how to use
java.util.List#indexOf() .
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: EnumType.java From api with Apache License 2.0 | 6 votes |
private static Pair<Integer, Codec> createViaJSON(Types.ConstructorDef def, LinkedHashMap<String, String> aliasses, String key, Object value) { // JSON comes in the form of { "<type (lowercased)>": "<value for type>" }, here we // additionally force to lower to ensure forward compat //const keys = Object.keys(def).map((k) => k.toLowerCase()); List<String> keys = def.getNames().stream().map(k -> k.toLowerCase()).collect(Collectors.toList()); String keyLower = key.toLowerCase(); Map<String, String> aliasLower = aliasses.entrySet().stream() .map(e -> new String[]{e.getKey().toLowerCase(), e.getValue().toLowerCase()}) .collect(Collectors.toMap((sa) -> sa[0], (sa) -> sa[1])); String aliasKey = aliasLower.getOrDefault(keyLower, keyLower); int index = keys.indexOf(aliasKey); //assert(index !== -1, `Cannot map input on JSON, unable to find '${key}' in ${keys.join(', ')}`); return EnumType.createValue(def, index, value); }
Example 2
Source File: JingleRtpConnection.java From Conversations with GNU General Public License v3.0 | 6 votes |
private void processCandidates(final List<String> indices, final Set<Map.Entry<String, RtpContentMap.DescriptionTransport>> contents) { for (final Map.Entry<String, RtpContentMap.DescriptionTransport> content : contents) { final String ufrag = content.getValue().transport.getAttribute("ufrag"); for (final IceUdpTransportInfo.Candidate candidate : content.getValue().transport.getCandidates()) { final String sdp; try { sdp = candidate.toSdpAttribute(ufrag); } catch (IllegalArgumentException e) { Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": ignoring invalid ICE candidate " + e.getMessage()); continue; } final String sdpMid = content.getKey(); final int mLineIndex = indices.indexOf(sdpMid); final IceCandidate iceCandidate = new IceCandidate(sdpMid, mLineIndex, sdp); Log.d(Config.LOGTAG, "received candidate: " + iceCandidate); this.webRTCWrapper.addIceCandidate(iceCandidate); } } }
Example 3
Source File: GuiModules.java From The-5zig-Mod with MIT License | 6 votes |
private boolean move(int pos) { Module module = guiList.getSelectedRow(); if (module == null) { return false; } List<Module> modules = The5zigMod.getModuleMaster().getModules(); int currentIndex = modules.indexOf(module); int nextIndex = currentIndex + pos; if (nextIndex >= 0 && nextIndex < modules.size()) { Collections.swap(modules, currentIndex, nextIndex); guiList.setSelectedId(nextIndex); return true; } return false; }
Example 4
Source File: LabelColorSchemes.java From diirt with MIT License | 6 votes |
/** *Returns a new LabelColorScheme, based on the given hex labels. * @param labels a list of strings (color values in hexadecimal) * @return a LabelColorScheme with the method getColor, that will return a Color corresponding to the hex label. */ public static LabelColorScheme orderedHueColor(List<String> labels) { final List<String> orderedUniqueLabels = new ArrayList<String>(new TreeSet<String>(labels)); return new LabelColorScheme() { float step = (1.0f / 3) / ((float) Math.ceil(orderedUniqueLabels.size() / 3.0)); @Override public int getColor(String label) { int index = orderedUniqueLabels.indexOf(label); if (index == -1) { return 0; } return Color.HSBtoRGB(index * step, 1.0f, 1.0f); } }; }
Example 5
Source File: RowRowRecordParser.java From incubator-iotdb with Apache License 2.0 | 6 votes |
/** * Creates RowRowRecordParser from output RowTypeInfo and selected series in the RowRecord. The row field "time" * will be used to store the timestamp value. The other row fields store the values of the same field names of * the RowRecord. * * @param outputRowTypeInfo The RowTypeInfo of the output row. * @param selectedSeries The selected series in the RowRecord. * @return The RowRowRecordParser. */ public static RowRowRecordParser create(RowTypeInfo outputRowTypeInfo, List<Path> selectedSeries) { List<String> selectedSeriesNames = selectedSeries.stream().map(Path::toString).collect(Collectors.toList()); String[] rowFieldNames = outputRowTypeInfo.getFieldNames(); int[] indexMapping = new int[outputRowTypeInfo.getArity()]; for (int i = 0; i < outputRowTypeInfo.getArity(); i++) { if (!QueryConstant.RESERVED_TIME.equals(rowFieldNames[i])) { int index = selectedSeriesNames.indexOf(rowFieldNames[i]); if (index >= 0) { indexMapping[i] = index; } else { throw new IllegalArgumentException(rowFieldNames[i] + " is not found in selected series."); } } else { // marked as timestamp field. indexMapping[i] = -1; } } return new RowRowRecordParser(indexMapping, outputRowTypeInfo); }
Example 6
Source File: AutomaticQA.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 从首选项中获取自动检查中要检查的项 * @return */ public LinkedList<String> getAutoQAItems() { LinkedList<String> itemsList = new LinkedList<String>(); String itemsValue = preferenceStore.getString(QAConstant.QA_PREF_AUTO_QAITEMS); List<String> itemsValList = new ArrayList<String>(); String[] itemsValArray = itemsValue.split(","); for (int index = 0; index < itemsValArray.length; index++) { itemsValList.add(itemsValArray[index]); } //获取所有的品质检查项的标识符 model.getQaItemId_Name_Class().keySet(); Iterator<String> qaIt = model.getQaItemId_Name_Class().keySet().iterator(); while (qaIt.hasNext()) { String qaItermId = qaIt.next(); if (itemsValList.indexOf(qaItermId) >= 0) { itemsList.add(qaItermId); } } return itemsList; }
Example 7
Source File: WebSocketInitializerTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Test public void test_handler_order() throws Exception { final WebSocketInitializer webSocketInitializer = new WebSocketInitializer(websocketListener); webSocketInitializer.addHandlers(channel); final List<String> handlerNames = channel.pipeline().names(); final int hscIdx = handlerNames.indexOf(HTTP_SERVER_CODEC); final int hoaIdx = handlerNames.indexOf(HTTP_OBJECT_AGGREGATOR); final int wsphIdx = handlerNames.indexOf(WEBSOCKET_SERVER_PROTOCOL_HANDLER); final int wbfhIdx = handlerNames.indexOf(WEBSOCKET_BINARY_FRAME_HANDLER); final int wtfhIdx = handlerNames.indexOf(WEBSOCKET_TEXT_FRAME_HANDLER); final int mweIdx = handlerNames.indexOf(MQTT_WEBSOCKET_ENCODER); assertTrue(hscIdx < hoaIdx); assertTrue(hoaIdx < wsphIdx); assertTrue(wsphIdx < wbfhIdx); assertTrue(wbfhIdx < wtfhIdx); assertTrue(wtfhIdx < mweIdx); }
Example 8
Source File: MirrorCredentialsManagerTest.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Test findMirrorCredentials() sort order. * @throws Exception if something goes wrong */ public void testFindMirrorCredentialsSortOrder() throws Exception { // Store some credentials storeTestCredentials(); storeTestCredentials(); MirrorCredentialsDto primaryCreds = storeTestCredentials(); storeTestCredentials(); // Make one of them the primary credsManager.makePrimaryCredentials(primaryCreds.getId()); List<MirrorCredentialsDto> creds = credsManager.findMirrorCredentials(); // Remember the ID of the last iteration long lastId = -1; for (MirrorCredentialsDto c : creds) { // Primary should be first if (creds.indexOf(c) == 0) { assertEquals(primaryCreds, c); } // After that: ascending IDs else if (creds.indexOf(c) >= 2) { assertTrue(c.getId() > lastId); } lastId = c.getId(); } }
Example 9
Source File: ShareOrderDialog.java From RedReader with GNU General Public License v3.0 | 5 votes |
private List<ResolveInfo> prioritizeTopApps(List<ResolveInfo> unorderedList){ if(unorderedList.isEmpty()){ General.quickToast(context, R.string.error_toast_no_share_app_installed); dismiss(); } // Make a copy of the list since the original is not modifiable LinkedList<ResolveInfo> orderedList = new LinkedList<>(unorderedList); List<String> prioritizedAppNames = Arrays.asList(PrefsUtility.pref_behaviour_sharing_dialog_data_get( context, PreferenceManager.getDefaultSharedPreferences(context)).split(";")); ResolveInfo[] prioritizedApps = new ResolveInfo[prioritizedAppNames.size()]; // get the ResolveInfos for the available prioritized Apps and save them in order int count = 0; Iterator<ResolveInfo> iterator = orderedList.iterator(); while(iterator.hasNext()){ ResolveInfo currentApp = iterator.next(); String currentAppName = currentApp.activityInfo.name; if(prioritizedAppNames.contains(currentAppName)){ prioritizedApps[prioritizedAppNames.indexOf(currentAppName)] = currentApp; iterator.remove(); // Exit early if all apps matched if(++count >= prioritizedAppNames.size()) break; } } // Combine the two lists in order, respecting unavailable apps (null values in the Array) for(int i = prioritizedApps.length - 1; i >= 0; i--){ if(prioritizedApps[i] != null){ orderedList.addFirst(prioritizedApps[i]); } } return orderedList; }
Example 10
Source File: Util.java From ramus with GNU General Public License v3.0 | 5 votes |
public void addAttributes(List<Attribute> sources, Eval eval, List<Attribute> attributes) { String[] values = eval.getValues(); for (Attribute attribute : attributes) { if (sources.indexOf(attribute) < 0) { for (String value : values) { if (getAttributeEId(attribute.getId()).equals(value)) { sources.add(attribute); break; } } } } }
Example 11
Source File: PartConnection.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Report the index in provided candidate sequence of the (first) 2-staff part. * * @param sequence sequence of parts * @return index of bi-staff part in sequence, or -1 if not found */ private int biIndex (List<Candidate> sequence) { for (Candidate candidate : sequence) { if (candidate.getStaffCount() == 2) { return sequence.indexOf(candidate); } } return -1; }
Example 12
Source File: CobolFieldFactory.java From Cobol-to-Hive with Apache License 2.0 | 5 votes |
private CobolField getElementaryType(String cobolName, String line, List<String> fieldParts, int levelNo) throws CobolSerdeException { int picIndex = fieldParts.indexOf("pic"); if (picIndex == -1) picIndex = fieldParts.indexOf("picture"); if (picIndex > -1) { String name = getUniqueColumnName(cobolName); String picClause = fieldParts.get(picIndex + 1); switch (picClause.charAt(0)) { case 'x': case 'a': return new CobolStringField(line, levelNo, name, picClause); // return cf; case 'v': case 'n': case '9': case 'z': case '+': case '-': case '$': case 's': int compType = 0; if ((fieldParts.indexOf("comp-3") > -1) || (fieldParts.indexOf("comp-3.") > -1)) { compType = 3; } if ((fieldParts.indexOf("comp-4") > -1) || (fieldParts.indexOf("comp-4.") > -1)) { compType = 4; } if ((fieldParts.indexOf("comp") > -1) || (fieldParts.indexOf("comp.") > -1)) { compType = 4; } return new CobolNumberField(line, levelNo, name, picClause, compType); // return cf; default: break; // may need to throw exception } } return null; }
Example 13
Source File: Selection.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private static int addAndGetIndex(ColumnDefinition def, List<ColumnDefinition> l) { int idx = l.indexOf(def); if (idx < 0) { idx = l.size(); l.add(def); } return idx; }
Example 14
Source File: NNThroughputBenchmark.java From hadoop with Apache License 2.0 | 5 votes |
/** * Parse first 2 arguments, corresponding to the "-op" option. * * @param args argument list * @return true if operation is all, which means that options not related * to this operation should be ignored, or false otherwise, meaning * that usage should be printed when an unrelated option is encountered. */ protected boolean verifyOpArgument(List<String> args) { if(args.size() < 2 || ! args.get(0).startsWith("-op")) printUsage(); // process common options int krIndex = args.indexOf("-keepResults"); keepResults = (krIndex >= 0); if(keepResults) { args.remove(krIndex); } int llIndex = args.indexOf("-logLevel"); if(llIndex >= 0) { if(args.size() <= llIndex + 1) printUsage(); logLevel = Level.toLevel(args.get(llIndex+1), Level.ERROR); args.remove(llIndex+1); args.remove(llIndex); } int ugrcIndex = args.indexOf("-UGCacheRefreshCount"); if(ugrcIndex >= 0) { if(args.size() <= ugrcIndex + 1) printUsage(); int g = Integer.parseInt(args.get(ugrcIndex+1)); if(g > 0) ugcRefreshCount = g; args.remove(ugrcIndex+1); args.remove(ugrcIndex); } String type = args.get(1); if(OP_ALL_NAME.equals(type)) { type = getOpName(); return true; } if(!getOpName().equals(type)) printUsage(); return false; }
Example 15
Source File: InlineInlayImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public VisualPosition getVisualPosition() { int offset = getOffset(); VisualPosition pos = myEditor.offsetToVisualPosition(offset); List<Inlay> inlays = myEditor.getInlayModel().getInlineElementsInRange(offset, offset); int order = inlays.indexOf(this); return new VisualPosition(pos.line, pos.column + order, true); }
Example 16
Source File: Package.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void transformSourceFile(boolean minimize) { // Replace "obvious" SourceFile by null. Attribute olda = getAttribute(attrSourceFileSpecial); if (olda == null) return; // no SourceFile attr. String obvious = getObviousSourceFile(); List<Entry> ref = new ArrayList<>(1); olda.visitRefs(this, VRM_PACKAGE, ref); Utf8Entry sfName = (Utf8Entry) ref.get(0); Attribute a = olda; if (sfName == null) { if (minimize) { // A pair of zero bytes. Cannot use predef. layout. a = Attribute.find(ATTR_CONTEXT_CLASS, "SourceFile", "H"); a = a.addContent(new byte[2]); } else { // Expand null attribute to the obvious string. byte[] bytes = new byte[2]; sfName = getRefString(obvious); Object f = null; f = Fixups.addRefWithBytes(f, bytes, sfName); a = attrSourceFileSpecial.addContent(bytes, f); } } else if (obvious.equals(sfName.stringValue())) { if (minimize) { // Replace by an all-zero attribute. a = attrSourceFileSpecial.addContent(new byte[2]); } else { assert(false); } } if (a != olda) { if (verbose > 2) Utils.log.fine("recoding obvious SourceFile="+obvious); List<Attribute> newAttrs = new ArrayList<>(getAttributes()); int where = newAttrs.indexOf(olda); newAttrs.set(where, a); setAttributes(newAttrs); } }
Example 17
Source File: NiFi.java From localization_nifi with Apache License 2.0 | 5 votes |
private static String getKeyFromArgs(List<String> parsedArgs) { String key; LOGGER.debug("The bootstrap process provided the " + KEY_FLAG + " flag"); int i = parsedArgs.indexOf(KEY_FLAG); if (parsedArgs.size() <= i + 1) { LOGGER.error("The bootstrap process passed the {} flag without a key", KEY_FLAG); throw new IllegalArgumentException("The bootstrap process provided the " + KEY_FLAG + " flag but no key"); } key = parsedArgs.get(i + 1); LOGGER.info("Read property protection key from bootstrap process"); return key; }
Example 18
Source File: AppUtils.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
public static MaterialDialog.Builder buildResendDialog(Context context, int failedMessagesCount, final IResendMessage listener) { List<String> items = new ArrayList<>(); List<Integer> itemsId = new ArrayList<>(); items.add(context.getString(R.string.resend_chat_message)); itemsId.add(0); if (failedMessagesCount > 1) { items.add(String.format(context.getString(R.string.resend_all_messages), failedMessagesCount)); itemsId.add(1); } items.add(context.getString(R.string.delete_item_dialog)); itemsId.add(2); int[] newIds = new int[itemsId.size()]; for (Integer integer : itemsId) { newIds[itemsId.indexOf(integer)] = integer; } return new MaterialDialog.Builder(context).title(R.string.resend_chat_message).negativeText(context.getString(R.string.cancel)).items(items).itemsIds(newIds).itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) { switch (itemView.getId()) { case 0: listener.resendMessage(); break; case 1: listener.resendAllMessages(); break; case 2: listener.deleteMessage(); break; } } }); }
Example 19
Source File: GPOUtils.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
public static IndexSubset computeSubIndices(FieldsDescriptor child, FieldsDescriptor parent) { IndexSubset indexSubset = new IndexSubset(); for (Map.Entry<Type, List<String>> entry : child.getTypeToFields().entrySet()) { Type type = entry.getKey(); List<String> childFields = entry.getValue(); List<String> parentFields = parent.getTypeToFields().get(type); int size = child.getTypeToSize().get(type); int[] indices; if (child.getTypeToFields().get(type) != null && child.getCompressedTypes().contains(type)) { indices = new int[1]; } else { indices = new int[size]; for (int index = 0; index < size; index++) { if (parentFields == null) { indices[index] = -1; } else { indices[index] = parentFields.indexOf(childFields.get(index)); } } } switch (type) { case BOOLEAN: { indexSubset.fieldsBooleanIndexSubset = indices; break; } case CHAR: { indexSubset.fieldsCharacterIndexSubset = indices; break; } case STRING: { indexSubset.fieldsStringIndexSubset = indices; break; } case BYTE: { indexSubset.fieldsByteIndexSubset = indices; break; } case SHORT: { indexSubset.fieldsShortIndexSubset = indices; break; } case INTEGER: { indexSubset.fieldsIntegerIndexSubset = indices; break; } case LONG: { indexSubset.fieldsLongIndexSubset = indices; break; } case FLOAT: { indexSubset.fieldsFloatIndexSubset = indices; break; } case DOUBLE: { indexSubset.fieldsDoubleIndexSubset = indices; break; } default: { throw new UnsupportedOperationException("Type " + type); } } } return indexSubset; }
Example 20
Source File: ValueFormat.java From diirt with MIT License | 3 votes |
/** * Parses the string and returns the index in the enum. * <p> * Default implementation matches the label and returns the index. * * @param source the text to parse * @param labels the labels for the enum * @return the parsed representation */ public int parseEnum(String source, List<String> labels) { int index = labels.indexOf(source); if (index != -1) { return index; } throw new RuntimeException(source + " is not part of enum " + labels); }