List of usage examples for java.util ArrayList indexOf
public int indexOf(Object o)
From source file:com.panet.imeta.core.xml.XMLHandler.java
public static String[] getNodeElements(Node node) { ArrayList<String> elements = new ArrayList<String>(); // List of String NodeList nodeList = node.getChildNodes(); if (nodeList == null) return null; for (int i = 0; i < nodeList.getLength(); i++) { String nodeName = nodeList.item(i).getNodeName(); if (elements.indexOf(nodeName) < 0) elements.add(nodeName);//w w w . ja v a 2s . com } if (elements.isEmpty()) return null; return elements.toArray(new String[elements.size()]); }
From source file:com.digium.respoke.ContactManager.java
public void onLeave(RespokeConnection connection, RespokeGroup sender) { if (-1 != groups.indexOf(sender)) { String groupName = sender.getGroupID(); // Get the list of known connections for this group ArrayList<RespokeConnection> groupMembers = groupConnectionArrays.get(groupName); int index = groupMembers.indexOf(connection); // Get the list of known endpoints for this group ArrayList<RespokeEndpoint> groupEndpoints = groupEndpointArrays.get(groupName); if (-1 != index) { groupMembers.remove(index);// ww w.ja va 2 s . com RespokeEndpoint parentEndpoint = connection.getEndpoint(); if (null != parentEndpoint) { // Make sure that this is the last connection for this endpoint before removing it from the list int connectionCount = 0; int groupConnectionCount = 0; for (Map.Entry<String, ArrayList<RespokeConnection>> entry : groupConnectionArrays.entrySet()) { for (RespokeConnection eachConnection : entry.getValue()) { if (eachConnection.getEndpoint() == parentEndpoint) { connectionCount++; if (entry.getValue() == groupMembers) { groupConnectionCount++; } } } } if (connectionCount == 0) { Log.d(TAG, "Left: " + parentEndpoint.getEndpointID()); int endpointIndex = allKnownEndpoints.indexOf(parentEndpoint); if (-1 != endpointIndex) { allKnownEndpoints.remove(endpointIndex); conversations.remove(parentEndpoint.getEndpointID()); // Notify any UI listeners that an endpoint has left Intent intent = new Intent(ENDPOINT_DISAPPEARED); intent.putExtra("endpointID", parentEndpoint.getEndpointID()); intent.putExtra("index", endpointIndex); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } } if (groupConnectionCount == 0) { int groupIndex = groupEndpoints.indexOf(parentEndpoint); if (-1 != groupIndex) { groupEndpoints.remove(groupIndex); // Notify any UI listeners that an endpoint has left this group Intent intent = new Intent(ENDPOINT_LEFT_GROUP); intent.putExtra("endpointID", parentEndpoint.getEndpointID()); intent.putExtra("groupID", sender.getGroupID()); intent.putExtra("index", groupIndex); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } } } } } }
From source file:com.android.switchaccess.SwitchAccessPreferenceActivity.java
private void adjustAutoscanPrefs() { if (isAutoScanEnabled(this)) { ListPreference scanMethodsPref = (ListPreference) findPreference( getString(R.string.pref_scanning_methods_key)); String optionScanKey = getString(R.string.option_scanning_key); if (isOptionScanningEnabled(this)) { /* If somehow both autoscan and option scan are enabled, turn off option scan */ scanMethodsPref.setValue(getString(R.string.row_col_scanning_key)); SharedPreferencesUtils.getSharedPreferences(this).edit() .putString(getString(R.string.pref_scanning_methods_key), getString(R.string.row_col_scanning_key)) .commit();//from w w w. java 2s . c o m } ArrayList<String> entries = new ArrayList<>( Arrays.asList(getResources().getStringArray(R.array.switch_access_scanning_methods_entries))); ArrayList<String> entryValues = new ArrayList<>( Arrays.asList(getResources().getStringArray(R.array.switch_access_scanning_methods_values))); int optionScanIndex = entryValues.indexOf(optionScanKey); entries.remove(optionScanIndex); entryValues.remove(optionScanIndex); scanMethodsPref.setEntries(entries.toArray(new String[entries.size()])); scanMethodsPref.setEntryValues(entryValues.toArray(new String[entries.size()])); } else { PreferenceScreen mainPrefScreen = (PreferenceScreen) findPreference( getString(R.string.main_pref_screen_key)); PreferenceScreen keyAssignmentScreen = (PreferenceScreen) findPreference( getString(R.string.pref_category_scan_mappings_key)); mainPrefScreen.removePreference(findPreference(getString(R.string.pref_key_auto_scan_time_delay))); removeKeyAssignmentPressIfEmpty(keyAssignmentScreen, R.string.pref_key_mapped_to_auto_scan_key); removeKeyAssignmentPressIfEmpty(keyAssignmentScreen, R.string.pref_key_mapped_to_reverse_auto_scan_key); if (isOptionScanningEnabled(this)) { mainPrefScreen.removePreference(findPreference(getString(R.string.pref_key_auto_scan_enabled))); } } }
From source file:com.fullteem.yueba.net.http.RequestParams.java
@Override public String toString() { StringBuilder result = new StringBuilder(); for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) { if (result.length() > 0) result.append("&"); result.append(entry.getKey());//from w w w .j a va2s . com result.append("="); result.append(entry.getValue()); } for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) { if (result.length() > 0) result.append("&"); result.append(entry.getKey()); result.append("="); result.append("FILE"); } for (ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) { if (result.length() > 0) result.append("&"); ArrayList<String> values = entry.getValue(); for (String value : values) { if (values.indexOf(value) != 0) result.append("&"); result.append(entry.getKey()); result.append("="); result.append(value); } } for (ConcurrentHashMap.Entry<String, Integer> entry : intParams.entrySet()) { if (result.length() > 0) result.append("&"); result.append(entry.getKey()); result.append("="); result.append(entry.getValue()); } return result.toString(); }
From source file:com.citesnap.android.app.ocr.OcrCaptureActivity.java
/** * onTap is called to capture the first TextBlock under the tap location and return it to * the Initializing Activity./*from ww w .j av a2 s . c o m*/ * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); if (graphic == null) { mCameraSource.autoFocus(null); return false; } ArrayList<OcrGraphic> graphics = mOcrDetectorProcessor.getGraphics(); int index = graphics.indexOf(graphic); OcrGraphic graphicBefore = index > 0 ? graphics.get(index - 1) : null; OcrGraphic graphicAfter = index < graphics.size() - 1 ? graphics.get(index + 1) : null; String textBefore = ""; String text = ""; String textAfter = ""; if (graphic != null && graphic.getTextBlock() != null) { text = graphic.getTextBlock().getValue(); if (graphicBefore != null) { textBefore = graphicBefore.getTextBlock().getValue(); } if (graphicAfter != null) { textAfter = graphicAfter.getTextBlock().getValue(); } if (text != null && text != null) { Intent data = new Intent(this, AddQuoteActivity.class); String[] value = { textBefore, text, textAfter }; data.putExtra(TextBlockObject, value); startActivity(data); } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG, "no text detected"); } return text != null; }
From source file:com.liferay.ide.portlet.core.PluginPackageModel.java
public void swapDependencies(String property, String dep1, String dep2) { String[] deps = null;//from w ww . j a va 2 s .co m String depsValue = pluginPackageProperties.getString(property, null); if (depsValue != null) { deps = depsValue.split(","); //$NON-NLS-1$ } else { deps = new String[0]; } ArrayList<String> list = new ArrayList<String>(); Collections.addAll(list, deps); int index1 = list.indexOf(dep1); int index2 = list.indexOf(dep2); list.set(index2, dep1); list.set(index1, dep2); String[] newValues = list.toArray(new String[0]); StringBuffer buffer = new StringBuffer(); for (String val : newValues) { buffer.append(val + ","); //$NON-NLS-1$ } String newValue = buffer.toString().substring(0, buffer.length() - 1); pluginPackageProperties.setProperty(property, newValue); flushProperties(); fireModelChanged(new ModelChangedEvent(this, null, property, depsValue, newValue)); }
From source file:gda.function.lookup.LookupTable.java
/** * returns or find the index of a scannable name in an Arraylist of Scannable names * /*from w w w. j a v a 2 s. c o m*/ * @param scannableNames * @param scannableName * @return index */ private int indexOfScannable(ArrayList<String> scannableNames, String scannableName) { return scannableNames.indexOf(scannableName); }
From source file:im.vector.activity.CommonActivityUtils.java
/** * Parse an userIDS text into a list.//from www.j ava 2s. c o m * * @param userIDsText the userIDs text. * @param homeServerSuffix the home server suffix * @return the userIDs list. */ public static ArrayList<String> parseUserIDsList(String userIDsText, String homeServerSuffix) { ArrayList<String> userIDsList = new ArrayList<String>(); if (!TextUtils.isEmpty(userIDsText)) { userIDsText = userIDsText.trim(); if (!TextUtils.isEmpty(userIDsText)) { // they are separated by a ; String[] splitItems = userIDsText.split(";"); for (int i = 0; i < splitItems.length; i++) { String item = splitItems[i]; // avoid null name if (item.length() > 0) { // add missing @ or home suffix String checkedItem = CommonActivityUtils.checkUserId(item, homeServerSuffix); // not yet added ? -> add it if (userIDsList.indexOf(checkedItem) < 0) { checkedItem.trim(); userIDsList.add(checkedItem); } } } } } return userIDsList; }
From source file:org.drugis.addis.gui.WelcomeDialog.java
private void initComps() { final ButtonGroup examples = new ButtonGroup(); examples.add(new JRadioButton(Main.Examples.DEPRESSION.name, true)); examples.add(new JRadioButton(Main.Examples.HYPERTENSION.name)); final AbstractAction exampleAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { d_main.loadExampleDomain(Main.Examples.findFileName(getSelection(examples).getText())); closeWelcome();//w ww . j a v a 2 s .c o m } }; final AbstractAction loadAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { if (d_main.fileLoadActions() == JFileChooser.APPROVE_OPTION) { closeWelcome(); } } }; final AbstractAction newAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { d_main.newFileActions(); closeWelcome(); } }; FormLayout layout = new FormLayout("left:pref, " + SPACING + "px, left:pref", "p, 3dlu, p, " + SPACING + "px, p, " + SPACING + "px, p, 3dlu, p"); PanelBuilder builder = new PanelBuilder(layout); final CellConstraints cc = new CellConstraints(); builder.add(createImageLabel(FileNames.IMAGE_HEADER), cc.xyw(1, 1, 3)); builder.add(createButton("Load example", FileNames.ICON_TIP, exampleAction), cc.xy(1, 3)); final PanelBuilder radios = new PanelBuilder(new FormLayout("p, fill:pref:grow, right:pref", "p, 3dlu, p")); final ArrayList<AbstractButton> buttons = Collections.list(examples.getElements()); forAllDo(buttons, new Closure<AbstractButton>() { public void execute(final AbstractButton exampleOption) { int row = buttons.indexOf(exampleOption) == 0 ? 1 : buttons.indexOf(exampleOption) + 2; exampleOption.setOpaque(false); radios.add(exampleOption, cc.xy(1, row)); radios.add(createHelpButton(exampleOption), cc.xy(3, row)); } private JButton createHelpButton(final AbstractButton exampleOption) { JButton help = GUIFactory.createIconButton(org.drugis.mtc.gui.FileNames.ICON_ABOUT, "Information about this example"); removeBackground(help); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Examples example = Examples.findByName(exampleOption.getText()); String helpText = s_help.getHelpText(example.name().toLowerCase()); showExampleInfo(helpText); } }); return help; } }); JPanel radiosPanel = radios.getPanel(); setBorder(radiosPanel); builder.add(radiosPanel, cc.xy(3, 3)); builder.add(createButton("Open file", FileNames.ICON_OPENFILE, loadAction), cc.xy(1, 5)); JTextPane load = createLabel("Load an existing ADDIS data file stored on your computer."); builder.add(load, cc.xy(3, 5)); builder.add(createButton("New dataset", FileNames.ICON_FILE_NEW, newAction), cc.xy(1, 7)); builder.add(createLabel("Start with an empty file to build up your own data and analyses."), cc.xy(3, 7)); builder.add(createImageLabel(FileNames.IMAGE_FOOTER), cc.xyw(1, 9, 3)); setContentPane(builder.getPanel()); }
From source file:com.moez.QKSMS.model.MediaModelFactory.java
/** * This method is meant to identify the part in the given PduBody that corresponds to the given * src string./*from w ww .j a v a 2 s . co m*/ * * Essentially, a SMIL MMS is formatted as follows: * * 1. A smil/application part, which contains XML-like formatting for images, text, audio, * slideshows, videos, etc. * 2. One or more parts that correspond to one of the elements that was mentioned in the * formatting above. * * In the smil/application part, elements are identified by a "src" attribute in an XML-like * element. The challenge of this method lies in the fact that sometimes, the src string isn't * located at all in the part that it is meant to identify. * * We employ several methods of pairing src strings up to parts, using certain patterns we've * seen in failed MMS messages. These are described in this method. * TODO TODO TODO: Create a testing suite for this! */ private static PduPart findPart(final Context context, PduBody pb, String src, ArrayList<String> srcs) { PduPart result = null; if (src != null) { src = unescapeXML(src); // Sometimes, src takes the form of "cid:[NUMBER]". if (contentIdSrc(src)) { // Extract the content ID, and try finding the part using that. result = pb.getPartByContentId("<" + src.substring("cid:".length()) + ">"); if (result == null) { // Another thing that can happen is that there is a slideshow of images, each with // "cid:[NUMBER]" src, but the parts aren't labelled with the content ID. If // this is the case, then we just return the ith image part, where i is the position // of src if all the srcs are sorted in ascending order as content IDs. srcs may // include duplicates; we remove those and then identify i when the list is free from // duplicates. // // i.e., for srcs = [ "cid:755", "cid:755", "cid:756", "cid:757", "cid:758" ], // the i of "cid:755" is 0; for "cid:756" is 1, etc. // First check that all the src strings are content IDs. boolean allContentIDs = true; for (String _src : srcs) { if (!contentIdSrc(_src)) { allContentIDs = false; break; } } if (allContentIDs) { // Now, build a list of long IDs, sort them, and remove the duplicates. ArrayList<Long> cids = new ArrayList<>(); for (String _src : srcs) { cids.add(getContentId(_src)); } Collections.sort(cids); int removed = 0; long previous = -1; for (int i = 0; i < cids.size() - removed; i++) { long cid = cids.get(i); if (cid == previous) { cids.remove(i); removed++; } else { previous = cid; } } // Find the i such that getContentId(src) == cids[i] long cid = getContentId(src); int i = cids.indexOf(cid); // Finally, since the SMIL formatted part will come first, we expect to see // 1 + cids.size() parts, and the right part for this particular cid will be // 1 + i. if (1 + i < pb.getPartsNum()) { result = pb.getPart(i + 1); } } } } else if (textSrc(src)) { // This is just a text src, so look for the PduPart that is has the "text/plain" // content type. for (int i = 0; i < pb.getPartsNum(); i++) { PduPart part = pb.getPart(i); String contentType = byteArrayToString(part.getContentType()); if ("text/plain".equals(contentType)) { result = part; break; } } } // Try a few more things in case the previous processing didn't work correctly: // Search by name if (result == null) { result = pb.getPartByName(src); } // Search by filename if (result == null) { result = pb.getPartByFileName(src); } // Search by content location if (result == null) { result = pb.getPartByContentLocation(src); } // Try treating the src string as a content ID, and searching by content ID. if (result == null) { result = pb.getPartByContentId("<" + src + ">"); } // TODO: // four remaining cases currently in Firebase: // 1. src: "image:[NUMBER]" (broken formatting) // 2. src: "[NUMBER]" (broken formatting) // 3. src: "[name].vcf" (we don't support x-vcard) // 3. src: "Current Location.loc.vcf" (we don't support x-vcard) } if (result != null) { return result; } if (pb.getPartsNum() > 0) { final JSONArray array = new JSONArray(); for (int i = 0; i < pb.getPartsNum(); i++) { JSONObject object = new JSONObject(); try { object.put("part_number", i); } catch (Exception e) { e.printStackTrace(); } try { object.put("location", i); } catch (Exception e) { e.printStackTrace(); } try { object.put("charset", pb.getPart(i).getCharset()); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_disposition", byteArrayToString(pb.getPart(i).getContentDisposition())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_id", byteArrayToString(pb.getPart(i).getContentId())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_location", byteArrayToString(pb.getPart(i).getContentLocation())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_transfer_encoding", byteArrayToString(pb.getPart(i).getContentTransferEncoding())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_type", byteArrayToString(pb.getPart(i).getContentType())); } catch (Exception e) { e.printStackTrace(); } try { object.put("data", byteArrayToString(pb.getPart(i).getData())); } catch (Exception e) { e.printStackTrace(); } try { object.put("data_uri", pb.getPart(i).getDataUri()); } catch (Exception e) { e.printStackTrace(); } try { object.put("file_name", byteArrayToString(pb.getPart(i).getFilename())); } catch (Exception e) { e.printStackTrace(); } try { object.put("name", byteArrayToString(pb.getPart(i).getName())); } catch (Exception e) { e.printStackTrace(); } if (pb.getPart(i).generateLocation() != null) { Log.d(TAG, "Location: " + pb.getPart(i).generateLocation()); if (pb.getPart(i).generateLocation().contains(src)) { return pb.getPart(i); } } array.put(object); } } throw new IllegalArgumentException("No part found for the model."); }