List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:game.plugins.algorithms.RealFeaturesTree.java
private RealVector getProbabilities(Dataset dataset) { Map<String, Double> prob = new HashMap<>(); Iterator<Instance> it = dataset.iterator(); double sum = 0; while (it.hasNext()) { Instance i = it.next();/*from www . j ava2 s . c o m*/ String key = i.getTarget().get().get(String.class); if (!prob.containsKey(key)) prob.put(key, 0.0); prob.put(key, prob.get(key) + 1.0); sum++; } List<String> labels = dataset.getTemplate().targetTemplate.getSingleton().getContent("labels"); RealVector ret = new ArrayRealVector(labels.size()); for (String key : prob.keySet()) { ret.setEntry(labels.indexOf(key), prob.get(key) / sum); } return ret; }
From source file:de.fme.topx.component.TopXUpdateComponent.java
/** * increase the hitcount for the given noderef by using the aspect * <code>topx:countable</code>. Does not fire events for other behaviours. * Using admin use to increment because not everybody has * //from w w w .j av a 2s. c o m * @param nodeRef * @param userName * current user who reads or updates the document. * @param counterUserProperty * @throws SystemException * @throws NotSupportedException * @throws HeuristicRollbackException * @throws HeuristicMixedException * @throws RollbackException * @throws IllegalStateException * @throws SecurityException */ @SuppressWarnings("unchecked") public Integer increaseHitcount(final NodeRef nodeRef, final String userName, final QName counterProperty, final QName counterDateProperty, final QName counterUserProperty) throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException { UserTransaction transaction = transactionService.getNonPropagatingUserTransaction(false); transaction.begin(); try { Preconditions.checkNotNull(nodeRef, "Passed noderef should not be null"); Preconditions.checkArgument(nodeService.exists(nodeRef), "Node[" + nodeRef + "] must exist in the repository"); filter.disableAllBehaviours(); Map<QName, Serializable> newProperties = Maps.newHashMap(); Integer counter = (Integer) nodeService.getProperty(nodeRef, counterProperty); if (counter == null) { counter = setHitCountProperties(nodeRef, counterProperty, counterDateProperty, counterUserProperty, newProperties, 1, userName); } else { boolean shouldCount = true; Map<QName, Serializable> properties = nodeService.getProperties(nodeRef); Serializable usersValue = properties.get(counterUserProperty); List<String> users; if (!(usersValue instanceof List)) { users = Lists.newArrayList((String) usersValue); } else { users = (List<String>) usersValue; } if (users != null) { int userIndex = users.indexOf(userName); if (userIndex != -1) { List<Date> counterDates = (List<Date>) properties.get(counterDateProperty); Date lastUserReadDate = counterDates.get(userIndex); // only count one download for a // document of // a user per day if (DateUtils.isSameDay(lastUserReadDate, new Date())) { shouldCount = false; LOG.info("User " + userName + " already downloads/updates document " + nodeRef + " today. Skip counting."); } } } if (shouldCount) { counter = setHitCountProperties(nodeRef, counterProperty, counterDateProperty, counterUserProperty, newProperties, counter, userName); } } transaction.commit(); LOG.info("Commiting transaction for Node " + nodeRef); return counter; } finally { filter.enableAllBehaviours(); if (transaction.getStatus() == javax.transaction.Status.STATUS_ACTIVE) { transaction.rollback(); LOG.warn("Had to rollback the transaction for Node " + nodeRef); } } }
From source file:net.sourceforge.fenixedu.domain.Summary.java
public String getOrder() { StringBuilder stringBuilder = new StringBuilder(); Lesson lesson = getLesson();/* ww w.j av a2s. co m*/ if (lesson != null) { SortedSet<YearMonthDay> allLessonDates = lesson.getAllLessonDates(); List<YearMonthDay> lessonDates = new ArrayList<YearMonthDay>(allLessonDates); if (!lessonDates.isEmpty()) { int index = lessonDates.indexOf(getSummaryDateYearMonthDay()); if (index != -1) { stringBuilder.append("(").append(index + 1).append("/"); return stringBuilder.append(lessonDates.size()).append(")").toString(); } } } return ""; }
From source file:org.mifos.androidclient.main.CollectionSheetActivity.java
private void updateCustomers(CollectionSheetData collectionSheet) { List<CollectionSheetCustomer> tmpCustomer = collectionSheet.getCollectionSheetCustomer(); for (CollectionSheetCustomer customer : tmpCustomer) { if (customer.getName().equalsIgnoreCase(mSelectedCustomer.getName())) { tmpCustomer.set(tmpCustomer.indexOf(customer), mSelectedCustomer); }/*from ww w.j a v a2s. c om*/ } }
From source file:com.employee.scheduler.nurserostering.swingui.NurseRosteringPanel.java
private void advancePlanningWindowStart() { logger.info("Advancing planningWindowStart."); if (solutionBusiness.isSolving()) { JOptionPane.showMessageDialog(this.getTopLevelAncestor(), "The GUI does not support this action yet during solving.\nOptaPlanner itself does support it.\n" + "\nTerminate solving first and try again.", "Unsupported in GUI", JOptionPane.ERROR_MESSAGE); return;/* w ww . j av a2 s . c o m*/ } solutionBusiness.doProblemFactChange(new ProblemFactChange() { public void doChange(ScoreDirector scoreDirector) { NurseRoster nurseRoster = (NurseRoster) scoreDirector.getWorkingSolution(); NurseRosterParametrization nurseRosterParametrization = nurseRoster.getNurseRosterParametrization(); List<ShiftDate> shiftDateList = nurseRoster.getShiftDateList(); ShiftDate planningWindowStart = nurseRosterParametrization.getPlanningWindowStart(); int windowStartIndex = shiftDateList.indexOf(planningWindowStart); if (windowStartIndex < 0) { throw new IllegalStateException("The planningWindowStart (" + planningWindowStart + ") must be in the shiftDateList (" + shiftDateList + ")."); } ShiftDate oldLastShiftDate = shiftDateList.get(shiftDateList.size() - 1); ShiftDate newShiftDate = new ShiftDate(); newShiftDate.setId(oldLastShiftDate.getId() + 1L); newShiftDate.setDayIndex(oldLastShiftDate.getDayIndex() + 1); newShiftDate.setDateString(oldLastShiftDate.determineNextDateString()); newShiftDate.setDayOfWeek(oldLastShiftDate.getDayOfWeek().determineNextDayOfWeek()); List<Shift> refShiftList = planningWindowStart.getShiftList(); List<Shift> newShiftList = new ArrayList<Shift>(refShiftList.size()); newShiftDate.setShiftList(newShiftList); nurseRoster.getShiftDateList().add(newShiftDate); scoreDirector.afterProblemFactAdded(newShiftDate); Shift oldLastShift = nurseRoster.getShiftList().get(nurseRoster.getShiftList().size() - 1); long shiftId = oldLastShift.getId() + 1L; int shiftIndex = oldLastShift.getIndex() + 1; long shiftAssignmentId = nurseRoster.getShiftAssignmentList() .get(nurseRoster.getShiftAssignmentList().size() - 1).getId() + 1L; for (Shift refShift : refShiftList) { Shift newShift = new Shift(); newShift.setId(shiftId); shiftId++; newShift.setShiftDate(newShiftDate); newShift.setShiftType(refShift.getShiftType()); newShift.setIndex(shiftIndex); shiftIndex++; newShift.setRequiredEmployeeSize(refShift.getRequiredEmployeeSize()); newShiftList.add(newShift); nurseRoster.getShiftList().add(newShift); scoreDirector.afterProblemFactAdded(newShift); for (int indexInShift = 0; indexInShift < newShift.getRequiredEmployeeSize(); indexInShift++) { ShiftAssignment newShiftAssignment = new ShiftAssignment(); newShiftAssignment.setId(shiftAssignmentId); shiftAssignmentId++; newShiftAssignment.setShift(newShift); newShiftAssignment.setIndexInShift(indexInShift); nurseRoster.getShiftAssignmentList().add(newShiftAssignment); scoreDirector.afterEntityAdded(newShiftAssignment); } } windowStartIndex++; ShiftDate newPlanningWindowStart = shiftDateList.get(windowStartIndex); nurseRosterParametrization.setPlanningWindowStart(newPlanningWindowStart); nurseRosterParametrization.setLastShiftDate(newShiftDate); scoreDirector.afterProblemFactChanged(nurseRosterParametrization); } }); resetPanel(solutionBusiness.getSolution()); validate(); }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private void populateThirdForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_city_title))); EditText cityEditText = createEditText(mContext.getString(R.string.account_create_city_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, CITY_KEY); if (mFormData.get(CITY_KEY) != null) { cityEditText.setText(mFormData.get(CITY_KEY)); }// ww w . j a v a 2 s .co m formLayout.addView(cityEditText); formLayout.addView(createErrorView(CITY_KEY)); formLayout.addView(createTitle(mContext.getString(R.string.account_create_country_title))); Spinner spinner = new Spinner(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = 17; spinner.setLayoutParams(params); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, Countries.COUNTRIES); spinner.setAdapter(adapter); spinner.setPrompt(mContext.getString(R.string.account_create_country_spinner_prompt)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { mFormData.put(COUNTRY_KEY, Countries.COUNTRY_CODES[pos]); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); if (mFormData.get(COUNTRY_KEY) != null) { List<String> array = Arrays.asList(Countries.COUNTRY_CODES); spinner.setSelection(array.indexOf(mFormData.get(COUNTRY_KEY))); } formLayout.addView(spinner); }
From source file:edu.vt.vbi.patric.portlets.PhylogeneticTree.java
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); SiteHelper.setHtmlMetaElements(request, response, "Phylogeny"); List<Integer> phylogenyOrderIds = Arrays.asList(2037, 1385, 80840, 213849, 51291, 186802, 91347, 186826, 118969, 356, 766, 136, 72273, 135623); String contextType = request.getParameter("context_type"); String contextId = request.getParameter("context_id"); if (contextType != null && contextId != null) { DataApiHandler dataApi = new DataApiHandler(request); List<Map<String, Object>> orderList = new ArrayList<>(); int taxonId = 0; try {/* w ww. j a v a 2s . c o m*/ if (contextType.equals("genome")) { Genome genome = dataApi.getGenome(contextId); taxonId = genome.getTaxonId(); } else { taxonId = Integer.parseInt(contextId); } // Step1. has Order in lineage? Taxonomy taxonomy = dataApi.getTaxonomy(taxonId); List<String> lineageRanks = taxonomy.getLineageRanks(); if (lineageRanks.contains("order")) { List<Integer> lineageIds = taxonomy.getLineageIds(); List<String> lineageNames = taxonomy.getLineageNames(); int index = lineageRanks.indexOf("order"); int orderTaxonId = lineageIds.get(index); if (phylogenyOrderIds.contains(orderTaxonId)) { Map order = new HashMap(); order.put("name", lineageNames.get(index)); order.put("taxonId", lineageIds.get(index)); orderList.add(order); } } if (orderList.isEmpty()) { // no rank Order found in lineage, then, // Step2. has Order rank in descendants SolrQuery query = new SolrQuery( "lineage_ids:" + taxonId + " AND taxon_rank:order AND taxon_id:(" + StringUtils.join(phylogenyOrderIds, " OR ") + ")"); query.setFields("taxon_id,taxon_name,taxon_rank"); query.setRows(100); LOGGER.trace("[{}] {}", SolrCore.TAXONOMY.getSolrCoreName(), query.toString()); String apiResponse = dataApi.solrQuery(SolrCore.TAXONOMY, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); List<Map> sdl = (List<Map>) respBody.get("docs"); for (Map doc : sdl) { if (doc.get("taxon_rank").equals("order")) { Map node = new HashMap<>(); node.put("taxonId", doc.get("taxon_id")); node.put("name", doc.get("taxon_name").toString()); orderList.add(node); } } } } catch (MalformedURLException e) { LOGGER.error(e.getMessage(), e); } request.setAttribute("orderList", orderList); request.setAttribute("taxonId", taxonId); PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/index.jsp"); prd.include(request, response); } }
From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartLineGraphicCreator.java
/** * @param entries//from w ww .j a va2s. co m * @return index of the first element to add to the diagram */ private int getIndexFirstElementToDraw(List<TimeseriesEntry> entries) { for (TimeseriesEntry entry : entries) { if (entry.getDate().after(fromDate)) { return entries.indexOf(entry); } } return -1; }
From source file:bioLockJ.module.classifier.r16s.qiime.QiimePreprocessor.java
/** * When rearranging files, skip any index when adding columns, if it will be moved. * @param field//from w w w . jav a 2s . c o m * @param cols * @param sb * @param colsToSkip * @param colMsg * @return */ private int skipIndex(final String field, final List<String> cols, final StringBuffer sb, final List<Integer> colsToSkip, final String colMsg) { final int index = (cols.indexOf(field) + 2); sb.append(", $" + index); // $9 colsToSkip.add(index); // 9 Log.out.info(field + " found in column #" + index + " but QIIME requires " + colMsg); return index; }
From source file:com.eyeq.pivot4j.util.RaggedMemberWrapper.java
/** * @param baseMember/*from ww w . j a v a 2 s. c o m*/ * @param topMember * @param nameSegments * @param level */ private void initialize(Member baseMember, Member topMember, List<IdentifierSegment> nameSegments, Level level) { this.baseMember = baseMember; this.topMember = topMember; this.nameSegments = nameSegments; this.level = level; if (level.getDepth() - topMember.getDepth() < 2) { this.parentMember = topMember; } else { List<Level> levels = level.getHierarchy().getLevels(); int index = levels.indexOf(level); RaggedMemberWrapper wrapper = new RaggedMemberWrapper(); wrapper.initialize(baseMember, topMember, nameSegments, levels.get(index - 1)); wrapper.children = new NamedListImpl<RaggedMemberWrapper>(1); wrapper.children.add(this); this.parentMember = wrapper; } }