List of usage examples for java.util ArrayList indexOf
public int indexOf(Object o)
From source file:org.pentaho.big.data.kettle.plugins.kafka.KafkaConsumerInputDialog.java
private void setTopicsFromTable() { int itemCount = topicsTable.getItemCount(); ArrayList<String> tableTopics = new ArrayList<String>(); for (int rowIndex = 0; rowIndex < itemCount; rowIndex++) { TableItem row = topicsTable.getTable().getItem(rowIndex); String topic = row.getText(1); if (!"".equals(topic) && tableTopics.indexOf(topic) == -1) { tableTopics.add(topic);// w w w . j a va 2s. c o m } } meta.setTopics(tableTopics); }
From source file:org.openmrs.module.rwandareports.renderer.PatientHistoryExcelTemplateRenderer.java
/** * @see ReportRenderer#render(ReportData, String, OutputStream) *///from ww w . j av a 2 s. c om public void render(ReportData reportData, String argument, OutputStream out) throws IOException, RenderingException { try { log.debug("Attempting to render report with ExcelTemplateRenderer"); ReportDesign design = getDesign(argument); Workbook wb = getExcelTemplate(design); if (wb == null) { XlsReportRenderer xlsRenderer = new XlsReportRenderer(); xlsRenderer.render(reportData, argument, out); } else { //This should be changed to get the dataset name form a parameter DataSet ds = reportData.getDataSets().get("patient"); ArrayList<String> names = new ArrayList<String>(); for (DataSetColumn dataSetRow : ds.getMetaData().getColumns()) { names.add(dataSetRow.getName()); } Sheet s = wb.getSheetAt(0); Row h = s.createRow(8); CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setFontName(HSSFFont.FONT_ARIAL); font.setBold(true); style.setFont(font); for (String name : names) { Cell c = h.createCell(names.indexOf(name)); String value = name.toUpperCase().replace("_", " "); c.setCellValue(value); c.setCellStyle(style); } //Trying to creat a row that has the replacement values pre-populated Row r = s.getRow(9); for (String name : names) { Cell c = r.createCell(names.indexOf(name)); String value = "#patient." + name + "#"; c.setCellValue(value); } ExcelUtil.formatRow(r); Map<String, String> repeatSections = getRepeatingSections(design); // Put together base set of replacements. Any dataSet with only one row is included. Map<String, Object> replacements = getBaseReplacementData(reportData, design); // Iterate across all of the sheets in the workbook, and configure all those that need to be added/cloned List<SheetToAdd> sheetsToAdd = new ArrayList<SheetToAdd>(); Set<String> usedSheetNames = new HashSet<String>(); int numberOfSheets = wb.getNumberOfSheets(); for (int sheetNum = 0; sheetNum < numberOfSheets; sheetNum++) { Sheet currentSheet = wb.getSheetAt(sheetNum); String originalSheetName = wb.getSheetName(sheetNum); String dataSetName = getRepeatingSheetProperty(sheetNum, repeatSections); if (dataSetName != null) { DataSet repeatingSheetDataSet = getDataSet(reportData, dataSetName, replacements); int dataSetRowNum = 0; for (Iterator<DataSetRow> rowIterator = repeatingSheetDataSet.iterator(); rowIterator .hasNext();) { DataSetRow dataSetRow = rowIterator.next(); dataSetRowNum++; Map<String, Object> newReplacements = getReplacementData(replacements, reportData, design, dataSetName, dataSetRow, dataSetRowNum); Sheet newSheet = (dataSetRowNum == 1 ? currentSheet : wb.cloneSheet(sheetNum)); sheetsToAdd.add(new SheetToAdd(newSheet, sheetNum, originalSheetName, newReplacements)); } } else { sheetsToAdd.add(new SheetToAdd(currentSheet, sheetNum, originalSheetName, replacements)); } } // Then iterate across all of these and add them in for (int i = 0; i < sheetsToAdd.size(); i++) { addSheet(wb, sheetsToAdd.get(i), usedSheetNames, reportData, design, repeatSections); } wb.write(out); } } catch (Exception e) { throw new RenderingException("Unable to render results due to: " + e, e); } }
From source file:org.peerfact.impl.network.gnp.topology.GnpSpace.java
/** * /* www . ja va 2 s . co m*/ * @param noOfDimensions * number of Dimensions must be smaller than number of Monitors * @param monitorResheduling * number of rescheduling the downhill simplex * @param mapRef * reference to HostMap * @return optimized positions for Monitors */ private static GnpSpace getGnpWithDownhillSimplex(int noOfDimensions, int monitorResheduling, HostMap mapRef) { GnpSpace.calculationStepStatus = 1; GnpSpace.calculationInProgress = true; double alpha = 1.0; double beta = 0.5; double gamma = 2; double maxDiversity = 0.5; // N + 1 initial random Solutions int dhs_N = mapRef.getNoOfMonitors(); ArrayList<GnpSpace> solutions = new ArrayList<GnpSpace>(dhs_N + 1); for (int c = 0; c < dhs_N + 1; c++) { solutions.add(new GnpSpace(noOfDimensions, mapRef)); } // best and worst solution GnpSpace bestSolution = Collections.min(solutions); GnpSpace worstSolution = Collections.max(solutions); double bestError = bestSolution.getObjectiveValueMonitor(); double worstError = worstSolution.getObjectiveValueMonitor(); for (int z = 0; z < monitorResheduling; z++) { GnpSpace.calculationProgressStatus = z; // resheduling int count = 0; for (GnpSpace gnp : solutions) { if (gnp != bestSolution) { GnpPosition monitor = gnp.getMonitorPosition(count); monitor.diversify(gnp.getDimension(), maxDiversity); count++; } } // best and worst solution bestSolution = Collections.min(solutions); worstSolution = Collections.max(solutions); bestError = bestSolution.getObjectiveValueMonitor(); worstError = worstSolution.getObjectiveValueMonitor(); // stop criterion while (worstError - bestError > 0.00001 && calculationInProgress) { // move to center ... GnpSpace center = GnpSpace.getCenterSolution(solutions); GnpSpace newSolution1 = GnpSpace.getMovedSolution(worstSolution, center, 1 + alpha); double newError1 = newSolution1.getObjectiveValueMonitor(); if (newError1 <= bestError) { int IndexOfWorstSolution = solutions.indexOf(worstSolution); GnpSpace newSolution2 = GnpSpace.getMovedSolution(worstSolution, center, 1 + alpha + gamma); double newError2 = newSolution2.getObjectiveValueMonitor(); if (newError2 <= newError1) { solutions.set(IndexOfWorstSolution, newSolution2); bestError = newError2; } else { solutions.set(IndexOfWorstSolution, newSolution1); bestError = newError1; } bestSolution = solutions.get(IndexOfWorstSolution); } else if (newError1 < worstError) { int IndexOfWorstSolution = solutions.indexOf(worstSolution); solutions.set(IndexOfWorstSolution, newSolution1); } else { // ... or contract around best solution for (int c = 0; c < solutions.size(); c++) { if (solutions.get(c) != bestSolution) { solutions.set(c, GnpSpace.getMovedSolution(solutions.get(c), bestSolution, beta)); } } bestSolution = Collections.min(solutions); bestError = bestSolution.getObjectiveValueMonitor(); } worstSolution = Collections.max(solutions); worstError = worstSolution.getObjectiveValueMonitor(); } } // Set the Coordinate Reference to the Peer for (int c = 0; c < bestSolution.getNumberOfMonitors(); c++) { bestSolution.getMonitorPosition(c).getHostRef() .setPositionReference(bestSolution.getMonitorPosition(c)); } // GnpSpace.calculationStepStatus = 0; // GnpSpace.calculationInProgress = false; return bestSolution; }
From source file:com.money.manager.ex.common.CategoryListFragment.java
/** * Show alter binaryDialog, for create or edit new category *//*from w w w . java 2 s. co m*/ private void showDialogEditSubCategoryName(final SQLTypeTransaction type, final int categoryId, final int subCategoryId, final CharSequence subCategName) { // inflate view View viewDialog = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_new_edit_subcategory, null); final EditText edtSubCategName = (EditText) viewDialog.findViewById(R.id.editTextCategName); final Spinner spnCategory = (Spinner) viewDialog.findViewById(R.id.spinnerCategory); // set category description edtSubCategName.setText(subCategName); if (!TextUtils.isEmpty(subCategName)) { edtSubCategName.setSelection(subCategName.length()); } // Fill categories list. CategoryService categoryService = new CategoryService(getActivity()); final List<Category> categories = categoryService.getList(); ArrayList<String> categoryNames = new ArrayList<>(); ArrayList<Integer> categoryIds = new ArrayList<>(); for (Category category : categories) { categoryIds.add(category.getId()); categoryNames.add(category.getName().toString()); } ArrayAdapter<String> adapterCategory = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, categoryNames); adapterCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spnCategory.setAdapter(adapterCategory); //select category if present if (categoryId > 0) { spnCategory.setSelection(categoryIds.indexOf(categoryId), true); } int titleId = type.equals(SQLTypeTransaction.INSERT) ? R.string.add_subcategory : R.string.edit_categoryName; new MaterialDialog.Builder(getContext()).customView(viewDialog, true) .icon(FontIconDrawable.inflate(getContext(), R.xml.ic_tag)).title(titleId) .positiveText(android.R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { // get category description String name = edtSubCategName.getText().toString(); // check position if (spnCategory.getSelectedItemPosition() == Spinner.INVALID_POSITION) return; // get category id int categId = categories.get(spnCategory.getSelectedItemPosition()).getId(); ContentValues values = new ContentValues(); values.put(Subcategory.CATEGID, categId); values.put(Subcategory.SUBCATEGNAME, name); SubcategoryRepository repo = new SubcategoryRepository(getActivity()); // check type transaction is request switch (type) { case INSERT: if (getActivity().getContentResolver().insert(repo.getUri(), values) == null) { Toast.makeText(getActivity(), R.string.db_insert_failed, Toast.LENGTH_SHORT).show(); } break; case UPDATE: if (getActivity().getContentResolver().update(repo.getUri(), values, Subcategory.CATEGID + "=" + categoryId + " AND " + Subcategory.SUBCATEGID + "=" + subCategoryId, null) == 0) { Toast.makeText(getActivity(), R.string.db_update_failed, Toast.LENGTH_SHORT).show(); } break; } // restart loader restartLoader(); } }).negativeText(android.R.string.cancel).onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.cancel(); } }).build().show(); }
From source file:info.jtrac.repository.HibernateJtracDao.java
private void doInMemorySort(List<Item> list, ItemSearch itemSearch) { // we should never come here if search is across multiple spaces final Field field = itemSearch.getSpace().getMetadata().getField(itemSearch.getSortFieldName()); final ArrayList<String> valueList = new ArrayList<String>(field.getOptions().keySet()); Comparator<Item> comp = new Comparator<Item>() { @Override// w w w. jav a2 s.co m public int compare(Item left, Item right) { Object leftVal = left.getValue(field.getName()); String leftValString = leftVal == null ? null : leftVal.toString(); int leftInd = valueList.indexOf(leftValString); Object rightVal = right.getValue(field.getName()); String rightValString = rightVal == null ? null : rightVal.toString(); int rightInd = valueList.indexOf(rightValString); return leftInd - rightInd; } }; @SuppressWarnings("unchecked") Comparator<Item> comparator = itemSearch.isSortDescending() ? (Comparator<Item>) ComparatorUtils.reversedComparator(comp) : comp; Collections.sort(list, comparator); }
From source file:oscar.eform.data.EForm.java
public void setValues(ArrayList<String> names, ArrayList<String> values) { if (names.size() != values.size()) return;//from www . j av a 2 s .com StringBuilder html = new StringBuilder(this.formHtml); int pointer = -1; while ((pointer = getFieldIndex(html, pointer + 1)) >= 0) { String fieldHeader = getFieldHeader(html, pointer); String fieldName = EFormUtil.removeQuotes(EFormUtil.getAttribute("name", fieldHeader)); int i; if ((i = names.indexOf(fieldName)) < 0) continue; String val = values.get(i); pointer = nextSpot(html, pointer); html = putValue(val, getFieldType(fieldHeader), pointer, html); } this.formHtml = html.toString(); }
From source file:org.openmrs.module.mksreports.renderer.PatientHistoryExcelTemplateRenderer.java
/** * @see ReportRenderer#render(ReportData, String, OutputStream) */// ww w.jav a 2 s . com public void render(ReportData reportData, String argument, OutputStream out) throws IOException, RenderingException { try { log.debug("Attempting to render report with ExcelTemplateRenderer"); ReportDesign design = getDesign(argument); Workbook wb = getExcelTemplate(design); if (wb == null) { XlsReportRenderer xlsRenderer = new XlsReportRenderer(); xlsRenderer.render(reportData, argument, out); } else { //This should be changed to get the dataset name form a parameter DataSet ds = reportData.getDataSets().get("patient"); ArrayList<String> names = new ArrayList<String>(); for (DataSetColumn dataSetRow : ds.getMetaData().getColumns()) { names.add(dataSetRow.getName()); } Sheet s = wb.getSheetAt(0); //Trying to creat a row that has the replacement values pre-populated Row h = s.createRow(8); CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setFontName(HSSFFont.FONT_ARIAL); font.setBold(true); style.setFont(font); for (String name : names) { Cell c = h.createCell(names.indexOf(name)); String value = name.toUpperCase().replace("_", " "); c.setCellValue(value); c.setCellStyle(style); } Row r = s.getRow(9); for (String name : names) { Cell c = r.createCell(names.indexOf(name)); String value = "#patient." + name + "#"; c.setCellValue(value); } Map<String, String> repeatSections = getRepeatingSections(design); // Put together base set of replacements. Any dataSet with only one row is included. Map<String, Object> replacements = getBaseReplacementData(reportData, design); // Iterate across all of the sheets in the workbook, and configure all those that need to be added/cloned List<SheetToAdd> sheetsToAdd = new ArrayList<SheetToAdd>(); Set<String> usedSheetNames = new HashSet<String>(); int numberOfSheets = wb.getNumberOfSheets(); for (int sheetNum = 0; sheetNum < numberOfSheets; sheetNum++) { Sheet currentSheet = wb.getSheetAt(sheetNum); String originalSheetName = wb.getSheetName(sheetNum); String dataSetName = getRepeatingSheetProperty(sheetNum, repeatSections); if (dataSetName != null) { DataSet repeatingSheetDataSet = getDataSet(reportData, dataSetName, replacements); int dataSetRowNum = 0; for (Iterator<DataSetRow> rowIterator = repeatingSheetDataSet.iterator(); rowIterator .hasNext();) { DataSetRow dataSetRow = rowIterator.next(); dataSetRowNum++; Map<String, Object> newReplacements = getReplacementData(replacements, reportData, design, dataSetName, dataSetRow, dataSetRowNum); Sheet newSheet = (dataSetRowNum == 1 ? currentSheet : wb.cloneSheet(sheetNum)); sheetsToAdd.add(new SheetToAdd(newSheet, sheetNum, originalSheetName, newReplacements)); } } else { sheetsToAdd.add(new SheetToAdd(currentSheet, sheetNum, originalSheetName, replacements)); } } // Then iterate across all of these and add them in for (int i = 0; i < sheetsToAdd.size(); i++) { addSheet(wb, sheetsToAdd.get(i), usedSheetNames, reportData, design, repeatSections); } wb.write(out); } } catch (Exception e) { throw new RenderingException("Unable to render results due to: " + e, e); } }
From source file:com.paniclauncher.workers.InstanceInstaller.java
public ArrayList<Mod> sortMods(ArrayList<Mod> original) { ArrayList<Mod> mods = new ArrayList<Mod>(original); for (Mod mod : original) { if (mod.isOptional()) { if (!mod.getLinked().isEmpty()) { for (Mod mod1 : original) { if (mod1.getName().equalsIgnoreCase(mod.getLinked())) { mods.remove(mod); int index = mods.indexOf(mod1) + 1; mods.add(index, mod); }//from w ww . j av a 2 s.c o m } } } } return mods; }
From source file:org.apache.hadoop.hbase.mob.compactions.TestMobCompactor.java
private void commonPolicyTestLogic(final String tableNameAsString, final MobCompactPartitionPolicy pType, final boolean majorCompact, final int expectedFileNumbers, final String[] expectedFileNames, final boolean setupAndLoadData) throws Exception { if (setupAndLoadData) { setUpForPolicyTest(tableNameAsString, pType); loadDataForPartitionPolicy(admin, bufMut, tableName); } else {// ww w . j a v a 2 s. c om alterForPolicyTest(pType); } if (majorCompact) { admin.majorCompact(tableName, hcd1.getName(), CompactType.MOB); } else { admin.compact(tableName, hcd1.getName(), CompactType.MOB); } waitUntilMobCompactionFinished(tableName); // Run cleaner to make sure that files in archive directory are cleaned up TEST_UTIL.getMiniHBaseCluster().getMaster().getHFileCleaner().choreForTesting(); //check the number of files Path mobDirPath = MobUtils.getMobFamilyPath(conf, tableName, family1); FileStatus[] fileList = fs.listStatus(mobDirPath); assertTrue(fileList.length == expectedFileNumbers); // the file names are expected ArrayList<String> fileNames = new ArrayList<>(expectedFileNumbers); for (FileStatus file : fileList) { fileNames.add(MobFileName.getDateFromName(file.getPath().getName())); } int index = 0; for (String fileName : expectedFileNames) { index = fileNames.indexOf(fileName); assertTrue(index >= 0); fileNames.remove(index); } // Check daily mob files are removed from the mobdir, and only weekly mob files are there. // Also check that there is no data loss. verifyPolicyValues(); }
From source file:com.hp.application.automation.tools.results.RunResultRecorder.java
private String getUniqueZipFileNameInFolder(ArrayList<String> names, String fileName) throws IOException, InterruptedException { String result = fileName + "_Report.zip"; int index = 0; while (names.indexOf(result) > -1) { result = fileName + "_" + (++index) + "_Report.zip"; }/* w w w . jav a 2 s .co m*/ return result; }