List of usage examples for java.util ArrayList indexOf
public int indexOf(Object o)
From source file:org.apache.hadoop.hbase.regionserver.compactions.SortedCompactionPolicy.java
protected ArrayList<StoreFile> getCurrentEligibleFiles(ArrayList<StoreFile> candidateFiles, final List<StoreFile> filesCompacting) { // candidates = all storefiles not already in compaction queue if (!filesCompacting.isEmpty()) { // exclude all files older than the newest file we're currently // compacting. this allows us to preserve contiguity (HBASE-2856) StoreFile last = filesCompacting.get(filesCompacting.size() - 1); int idx = candidateFiles.indexOf(last); Preconditions.checkArgument(idx != -1); candidateFiles.subList(0, idx + 1).clear(); }// w w w.j a va 2 s . c o m return candidateFiles; }
From source file:org.cds06.speleograph.GraphPanel.java
/** * Method called when a Series has changed in the application. * * @param event information about the event. *//*w w w . j a va 2 s .c o m*/ @Override public void datasetChanged(DatasetChangeEvent event) { for (int i = 0, max = plot.getDatasetCount(); i < max; i++) { plot.setDataset(i, null); plot.setRangeAxis(i, null); plot.setRenderer(i, null); } final ArrayList<NumberAxis> shownAxis = new ArrayList<>(series.size()); for (final Series set : series) { if (set == null) continue; NumberAxis rangeAxis = set.getAxis(); if (set.isShow()) { int id = series.indexOf(set); plot.setDataset(id, set); plot.setRenderer(id, set.getRenderer(), false); int index = shownAxis.indexOf(rangeAxis); if (index == -1) { shownAxis.add(rangeAxis); index = shownAxis.indexOf(rangeAxis); plot.setRangeAxis(index, rangeAxis, false); plot.setRangeAxisLocation(index, AxisLocation.BOTTOM_OR_LEFT); } plot.mapDatasetToRangeAxis(id, index); plot.getRenderer().setSeriesItemLabelsVisible(0, true, true); plot.datasetChanged(new DatasetChangeEvent(this, set)); } } if (shownAxis.size() == 0) { setupEmptyChart(); } else { plot.setDomainAxis(dateAxis); } }
From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorVisitController.java
@RequestMapping(value = "/module/accessmonitor/visit", method = RequestMethod.GET) public void person(ModelMap model, HttpServletRequest request) { // ((OrderAccessService) Context.getService(OrderAccessService.class)).generateData(); // ((VisitAccessService) Context.getService(VisitAccessService.class)).generateData(); // ((PersonAccessService) Context.getService(PersonAccessService.class)).generateData(); offset = 0;/*from w ww .j a v a2 s .c o m*/ // parse them to Date, null is acceptabl DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); // Get the from date and to date Date to = null; Date from = null; try { from = format.parse(request.getParameter("datepickerFrom")); } catch (Exception e) { //System.out.println("======From Date Empty======="); } try { to = format.parse(request.getParameter("datepickerTo")); } catch (Exception e) { //System.out.println("======To Date Empty======="); } // get all the records in the date range visitAccessData = ((VisitAccessService) Context.getService(VisitAccessService.class)) .getVisitAccessesByAccessDateOrderByPatientId(from, to); if (visitAccessData == null) { visitAccessData = new ArrayList<VisitServiceAccess>(); } // get date for small graph Date toSmall = to; Date fromSmall = null; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); if (toSmall == null) { toSmall = calendar.getTime(); } else { calendar.setTime(toSmall); } calendar.add(Calendar.DATE, -DAYNUM); fromSmall = calendar.getTime(); List<String> dateStrings = new ArrayList<String>(); for (int i = 0; i < DAYNUM; i++) { if (i == DAYNUM - 1) { dateStrings.add(format.format(toSmall)); } else if (i == 0) { dateStrings.add(format.format(fromSmall)); } else { dateStrings.add(""); } } ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>(); tooltip.add(new ArrayList<Integer>()); for (int j = 0; j < SHOWNUM + 1; j++) { tooltip.get(0).add(1000 + j); } for (int i = 1; i < DAYNUM + 1; i++) { tooltip.add(new ArrayList<Integer>()); tooltip.get(i).add(i); for (int j = 0; j < SHOWNUM; j++) { tooltip.get(i).add(0); } } ArrayList<String> patientIds = new ArrayList<String>(); ArrayList<Integer> patientCounts = new ArrayList<Integer>(); for (VisitServiceAccess va : visitAccessData) { // data for big graph String idString = (va.getPatientId() == null) ? "No ID" : va.getPatientId().toString(); int index = patientIds.indexOf(idString); if (index < 0) { if (patientIds.size() >= SHOWNUM) break; patientIds.add(idString); patientCounts.add(1); index = patientIds.size() - 1;//index = patientIds.indexOf(idString); } else { patientCounts.set(index, patientCounts.get(index) + 1); } // data for small graph if (va.getAccessDate().after(fromSmall) && va.getAccessDate().before(toSmall)) { int index2 = (int) ((va.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24)); if (index2 < DAYNUM && index2 >= 0) tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1); } } String patientIdString = JSONValue.toJSONString(patientIds); String patientCountString = JSONValue.toJSONString(patientCounts); String dateSmallString = JSONValue.toJSONString(dateStrings); String tooltipdata = JSONValue.toJSONString(tooltip); model.addAttribute("patientIds", patientIdString); model.addAttribute("patientCounts", patientCountString); model.addAttribute("dateSmallString", dateSmallString); model.addAttribute("tooltipdata", tooltipdata); model.addAttribute("user", Context.getAuthenticatedUser()); // model.addAttribute("tables1", visitAccessData); // model.addAttribute("dateSmall", dateStrings); model.addAttribute("currentoffset", String.valueOf(offset)); }
From source file:dr.app.bss.Utils.java
public static int taxaIsIdenticalWith(Taxa taxa, ArrayList<Taxa> taxaList) { int index = -Integer.MAX_VALUE; for (Taxa taxa2 : taxaList) { if (taxaToString(taxa, true).equalsIgnoreCase(taxaToString(taxa2, true))) { index = taxaList.indexOf(taxa2); break; }/*from ww w . j av a2 s .c o m*/ } return index; }
From source file:dr.app.bss.Utils.java
public static int treeModelIsIdenticalWith(TreeModel treeModel, ArrayList<TreeModel> treeModelList) { int index = -Integer.MAX_VALUE; for (TreeModel treeModel2 : treeModelList) { if (treeModel.getNewick().equalsIgnoreCase(treeModel2.getNewick())) { index = treeModelList.indexOf(treeModel2); break; }//from w w w . j a v a 2 s . co m } return index; }
From source file:android.databinding.tool.util.XmlEditor.java
public static String strip(File f, String newTag) throws IOException { ANTLRInputStream inputStream = new ANTLRInputStream(new FileReader(f)); XMLLexer lexer = new XMLLexer(inputStream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); XMLParser parser = new XMLParser(tokenStream); XMLParser.DocumentContext expr = parser.document(); XMLParser.ElementContext root = expr.element(); if (root == null || !"layout".equals(nodeName(root))) { return null; // not a binding layout }// ww w . ja v a 2 s. com List<? extends ElementContext> childrenOfRoot = elements(root); List<? extends XMLParser.ElementContext> dataNodes = filterNodesByName("data", childrenOfRoot); if (dataNodes.size() > 1) { L.e("Multiple binding data tags in %s. Expecting a maximum of one.", f.getAbsolutePath()); } ArrayList<String> lines = new ArrayList<>(); lines.addAll(FileUtils.readLines(f, "utf-8")); for (android.databinding.parser.XMLParser.ElementContext it : dataNodes) { replace(lines, toPosition(it.getStart()), toEndPosition(it.getStop()), ""); } List<? extends XMLParser.ElementContext> layoutNodes = excludeNodesByName("data", childrenOfRoot); if (layoutNodes.size() != 1) { L.e("Only one layout element and one data element are allowed. %s has %d", f.getAbsolutePath(), layoutNodes.size()); } final XMLParser.ElementContext layoutNode = layoutNodes.get(0); ArrayList<Pair<String, android.databinding.parser.XMLParser.ElementContext>> noTag = new ArrayList<>(); recurseReplace(layoutNode, lines, noTag, newTag, 0); // Remove the <layout> Position rootStartTag = toPosition(root.getStart()); Position rootEndTag = toPosition(root.content().getStart()); replace(lines, rootStartTag, rootEndTag, ""); // Remove the </layout> ImmutablePair<Position, Position> endLayoutPositions = findTerminalPositions(root, lines); replace(lines, endLayoutPositions.left, endLayoutPositions.right, ""); StringBuilder rootAttributes = new StringBuilder(); for (AttributeContext attr : attributes(root)) { rootAttributes.append(' ').append(attr.getText()); } Pair<String, XMLParser.ElementContext> noTagRoot = null; for (Pair<String, XMLParser.ElementContext> pair : noTag) { if (pair.getRight() == layoutNode) { noTagRoot = pair; break; } } if (noTagRoot != null) { ImmutablePair<String, XMLParser.ElementContext> newRootTag = new ImmutablePair<>( noTagRoot.getLeft() + rootAttributes.toString(), layoutNode); int index = noTag.indexOf(noTagRoot); noTag.set(index, newRootTag); } else { ImmutablePair<String, XMLParser.ElementContext> newRootTag = new ImmutablePair<>( rootAttributes.toString(), layoutNode); noTag.add(newRootTag); } //noinspection NullableProblems Collections.sort(noTag, new Comparator<Pair<String, XMLParser.ElementContext>>() { @Override public int compare(Pair<String, XMLParser.ElementContext> o1, Pair<String, XMLParser.ElementContext> o2) { Position start1 = toPosition(o1.getRight().getStart()); Position start2 = toPosition(o2.getRight().getStart()); int lineCmp = Integer.compare(start2.line, start1.line); if (lineCmp != 0) { return lineCmp; } return Integer.compare(start2.charIndex, start1.charIndex); } }); for (Pair<String, android.databinding.parser.XMLParser.ElementContext> it : noTag) { XMLParser.ElementContext element = it.getRight(); String tag = it.getLeft(); Position endTagPosition = endTagPosition(element); fixPosition(lines, endTagPosition); String line = lines.get(endTagPosition.line); String newLine = line.substring(0, endTagPosition.charIndex) + " " + tag + line.substring(endTagPosition.charIndex); lines.set(endTagPosition.line, newLine); } return StringUtils.join(lines, System.getProperty("line.separator")); }
From source file:edu.cmu.cylab.starslinger.view.FindContactActivity.java
public void generateView() { setContentView(R.layout.contact_adder); final ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); bar.setTitle(R.string.app_name);/* www .j a v a2 s .c o m*/ bar.setSubtitle(R.string.title_find); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // Obtain handles to UI objects mEditTextName = (EditText) findViewById(R.id.contactNameEditText); mButtonDone = (Button) findViewById(R.id.contactDoneButton); mEditTextPassNext = (EditText) findViewById(R.id.EditTextPassphrase); mEditTextPassDone = (EditText) findViewById(R.id.EditTextPassphraseAgain); mTextViewLicensePrivacy = (TextView) findViewById(R.id.textViewLicensePrivacy); mSpinnerLanguage = (Spinner) findViewById(R.id.spinnerLanguage); final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final ArrayList<String> codes = SafeSlinger.getApplication().getListLanguages(true); mSpinnerLanguage.setPrompt(getText(R.string.title_language)); mSpinnerLanguage.setAdapter(adapter); ArrayList<String> all = SafeSlinger.getApplication().getListLanguages(false); for (String l : all) { adapter.add(l); } mSpinnerLanguage.setSelection(codes.indexOf(SafeSlingerPrefs.getLanguage())); // read defaults and set them mSelectedName = SafeSlingerPrefs.getContactName(); // see if name is there... if (mSelectedName != null) { mEditTextName.setText(mSelectedName); } mEditTextPassNext.setVisibility(View.VISIBLE); mEditTextPassNext.setHint(R.string.label_PassHintCreate); mEditTextPassDone.setHint(R.string.label_PassHintRepeat); // enable hyperlinks mTextViewLicensePrivacy.setText(Html.fromHtml("<a href=\"" + SafeSlingerConfig.EULA_URL + "\">" + getText(R.string.menu_License) + "</a> / <a href=\"" + SafeSlingerConfig.PRIVACY_URL + "\">" + getText(R.string.menu_PrivacyPolicy) + "</a>")); mTextViewLicensePrivacy.setMovementMethod(LinkMovementMethod.getInstance()); mSpinnerLanguage.setOnItemSelectedListener(new OnItemSelectedListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long i) { if (!codes.get(position).equals(SafeSlingerPrefs.getLanguage())) { SafeSlingerPrefs.setLanguage(codes.get(position)); SafeSlinger.getApplication().updateLanguage(codes.get(position)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { recreate(); } else { generateView(); } } } @Override public void onNothingSelected(AdapterView<?> parent) { // We don't need to worry about nothing being selected } }); mEditTextName.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mSelectedName = mEditTextName.getText().toString(); } }); mButtonDone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onDoneButtonClicked(); } }); mEditTextPassDone.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { doValidatePassphrase(); return true; } return false; } }); }
From source file:com.nikhilnayak.games.octoshootar.beta.SensorDelayDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Sensor Delay"); final ArrayList<String> sensorDelayString = new ArrayList<String>(); sensorDelayString.add("Delay Fastest"); sensorDelayString.add("Delay Game"); sensorDelayString.add("Delay Ui"); sensorDelayString.add("Delay Normal"); final ArrayList<Integer> sensorDelayInteger = new ArrayList<Integer>(); sensorDelayInteger.add(SensorManager.SENSOR_DELAY_FASTEST); sensorDelayInteger.add(SensorManager.SENSOR_DELAY_GAME); sensorDelayInteger.add(SensorManager.SENSOR_DELAY_UI); sensorDelayInteger.add(SensorManager.SENSOR_DELAY_NORMAL); final SharedPreferences sharedPreferences = getActivity() .getSharedPreferences(BetaUtils.KEY_SHARED_PREFERENCES, Context.MODE_PRIVATE); final SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit(); int currentSensorDelayIndex = sensorDelayInteger .indexOf(sharedPreferences.getInt(BetaUtils.KEY_SENSOR_DELAY, SensorManager.SENSOR_DELAY_GAME)); builder.setSingleChoiceItems(sensorDelayString.toArray(new String[] {}), currentSensorDelayIndex, new DialogInterface.OnClickListener() { @Override/*from ww w. j a v a 2 s . co m*/ public void onClick(DialogInterface dialog, int which) { sharedPreferencesEditor.putInt(BetaUtils.KEY_SENSOR_DELAY, sensorDelayInteger.get(which)); } }); builder.setPositiveButton(R.string.craft_dialog_fragment_ok_response, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { sharedPreferencesEditor.commit(); } }); return builder.create(); }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected void revertButtonActionPerformed(ActionEvent evt, Path vpkToRevert) { //TODO: See if we can abstract away some of this functionality if (currentTree.getSelectionRows().length != 0 && ((TreeNode) currentTree.getSelectionPath().getLastPathComponent()).isLeaf()) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) currentTree.getSelectionPath() .getLastPathComponent(); String selectedWaveString = ((DefaultMutableTreeNode) selectedNode).getUserObject().toString(); String selectedWaveParentString = ((DefaultMutableTreeNode) ((DefaultMutableTreeNode) selectedNode) .getParent()).getUserObject().toString(); selectedNode = (DefaultMutableTreeNode) this.getTreeNodeFromWavePath(selectedWaveString); //First go in and delete the sound in customSounds deleteSoundFileByWaveString(selectedWaveString); //Get the relevant wavestring from the internal scriptfile VPKArchive vpk = new VPKArchive(); try {//from w ww . j a va 2 s .com vpk.load(new File(vpkToRevert.toString())); } catch (IOException ex) { ex.printStackTrace(); } String scriptDir = getCurrentScriptString(); scriptDir = scriptDir.replace(Paths.get(installDir, "/dota/").toString(), ""); scriptDir = scriptDir.replace("\\", "/"); //Match internal forward slashes scriptDir = scriptDir.substring(1); //Cut off leading slash byte[] bytes = null; VPKEntry entry = vpk.getEntry(scriptDir); try { ByteBuffer scriptBuffer = entry.getData(); bytes = new byte[scriptBuffer.remaining()]; scriptBuffer.get(bytes); } catch (IOException ex) { ex.printStackTrace(); } String scriptFileString = new String(bytes, Charset.forName("UTF-8")); ArrayList<String> wavePathList = this.getWavePathsAsList(selectedNode.getParent()); int waveStringIndex = wavePathList.indexOf(selectedWaveString); //Cut off every part of the scriptFileString before we get to the entry describing the relevant hero action, so we don't accidentally get the wrong wavepaths StringBuilder scriptFileStringShortened = new StringBuilder(); Scanner scan = new Scanner(scriptFileString); boolean found = false; while (scan.hasNextLine()) { String curLine = scan.nextLine(); if (curLine.equals(selectedWaveParentString)) { found = true; } if (found == true) { scriptFileStringShortened.append(curLine).append(System.lineSeparator()); } } scriptFileString = scriptFileStringShortened.toString(); ArrayList<String> internalWavePathsList = getWavePathListFromString(scriptFileString); String replacementString = internalWavePathsList.get(waveStringIndex); selectedNode.setUserObject(replacementString); ScriptParser parser = new ScriptParser(this.currentTreeModel); parser.writeModelToFile(getCurrentScriptString()); //Modify the UI treeNode in addition to the backing TreeNode ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(replacementString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); } }
From source file:com.bitants.wally.fragments.SavedImagesFragment.java
private void checkIfAddedOrRemovedItem(ArrayList<Uri> oldList, ArrayList<Uri> newList) { ArrayList<Uri> oldCompList = new ArrayList<Uri>(oldList); ArrayList<Uri> newCompList = new ArrayList<Uri>(newList); oldCompList.removeAll(newList);/* w w w . ja va 2s . c o m*/ if (oldCompList.size() > 0) { //Items removed recyclerSavedImagesAdapter.notifyItemRangeRemoved(oldList.indexOf(oldCompList.get(0)), oldCompList.size()); } newCompList.removeAll(oldList); if (newCompList.size() > 0) { //Items added recyclerSavedImagesAdapter.notifyItemRangeInserted(newList.indexOf(newCompList.get(0)), newCompList.size()); } }