List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:com.appdynamics.monitors.hadoop.communicator.AmbariCommunicator.java
/** * Parses a JSON Reader object as service metrics and collect service state plus service * component metrics. Prefixes metric name with <code>hierarchy</code>. * @see #getComponentMetrics(java.io.Reader, String) * * @param response//from w w w .j a v a2 s.co m * @param hierarchy */ private void getServiceMetrics(Reader response, String hierarchy) { try { Map<String, Object> json = (Map<String, Object>) parser.parse(response, simpleContainer); try { Map serviceInfo = (Map) json.get("ServiceInfo"); String serviceName = (String) serviceInfo.get("service_name"); String serviceState = (String) serviceInfo.get("state"); List<String> states = new ArrayList<String>(); states.add("INIT"); states.add("INSTALLING"); states.add("INSTALL_FAILED"); states.add("INSTALLED"); states.add("STARTING"); states.add("STARTED"); states.add("STOPPING"); states.add("UNINSTALLING"); states.add("UNINSTALLED"); states.add("WIPING_OUT"); states.add("UPGRADING"); states.add("MAINTENANCE"); states.add("UNKNOWN"); metrics.put(hierarchy + "|" + serviceName + "|state", states.indexOf(serviceState)); List<Map> components = (ArrayList<Map>) json.get("components"); CompletionService<Reader> threadPool = new ExecutorCompletionService<Reader>(executor); int count = 0; for (Map component : components) { if (xmlParser.isIncludeServiceComponent(serviceName, (String) ((Map) component.get("ServiceComponentInfo")).get("component_name"))) { threadPool.submit(new Response(component.get("href") + COMPONENT_FIELDS)); count++; } } for (; count > 0; count--) { getComponentMetrics(threadPool.take().get(), hierarchy + "|" + serviceName); } } catch (Exception e) { logger.error("Failed to parse service metrics: " + stackTraceToString(e)); } } catch (Exception e) { logger.error("Failed to get response for service metrics: " + stackTraceToString(e)); } }
From source file:com.appdynamics.monitors.hadoop.communicator.AmbariCommunicator.java
/** * Parses a JSON Reader object as component metrics and collect component state plus all * numeric metrics. Prefixes metric name with <code>hierarchy</code>. * @see #getAllMetrics(java.util.Map, String) * * @param response//from ww w . ja v a 2 s.c om * @param hierarchy */ private void getComponentMetrics(Reader response, String hierarchy) { try { Map<String, Object> json = (Map<String, Object>) parser.parse(response, simpleContainer); try { Map componentInfo = (Map) json.get("ServiceComponentInfo"); String componentName = (String) componentInfo.get("component_name"); String componentState = (String) componentInfo.get("state"); List<String> states = new ArrayList<String>(); states.add("INIT"); states.add("INSTALLING"); states.add("INSTALL_FAILED"); states.add("INSTALLED"); states.add("STARTING"); states.add("STARTED"); states.add("STOPPING"); states.add("UNINSTALLING"); states.add("UNINSTALLED"); states.add("WIPING_OUT"); states.add("UPGRADING"); states.add("MAINTENANCE"); states.add("UNKNOWN"); metrics.put(hierarchy + "|" + componentName + "|state", states.indexOf(componentState)); Map componentMetrics = (Map) json.get("metrics"); if (componentMetrics == null) { //no metrics return; } //remove non metric data componentMetrics.remove("boottime"); Iterator<Map.Entry> iter = componentMetrics.entrySet().iterator(); while (iter.hasNext()) { if (!xmlParser.isIncludeComponentMetrics((String) iter.next().getKey())) { iter.remove(); } } getAllMetrics(componentMetrics, hierarchy + "|" + componentName); } catch (Exception e) { logger.error("Failed to parse component metrics: " + stackTraceToString(e)); } } catch (Exception e) { logger.error("Failed to get response for component metrics: " + stackTraceToString(e)); } }
From source file:com.mindquarry.desktop.client.widget.workspace.WorkspaceBrowserWidget.java
private ChangeSets getAllChanges(Profile selected) { log.debug("Getting all changes"); ChangeSets changeSets = new ChangeSets(); // getting list of all selected teams final List<Team> selectedTeams = new ArrayList<Team>(); Display.getDefault().syncExec(new Runnable() { public void run() { selectedTeams.addAll(client.getSelectedTeams()); }//from ww w. j a va 2s . c o m }); try { toIgnore = new HashMap<File, Integer>(); for (Team team : selectedTeams) { setMessage(I18N.get("Refreshing workspaces changes for team \"{0}\" (team {1} of {2}) ...", //$NON-NLS-1$ team.getName(), Integer.toString(selectedTeams.indexOf(team) + 1), Integer.toString(selectedTeams.size()))); long startTime = System.currentTimeMillis(); // TODO: also consider the case where the team folder exists // but is not a SVN checkout if (!team.dirExists(selected)) { continue; } SVNSynchronizer sc = team.createSynchronizer(selected, new InteractiveConflictHandler(client.getShell())); ChangeSet changeSet = new ChangeSet(team); // iterate over local changes first to avoid exceptions // later (in rare cases of "obstructed" state only): sc.cleanup(); boolean teamHasObstruction = false; List<Status> tmpLocalChanges = sc.getLocalChanges(); for (Status status : tmpLocalChanges) { if (status.getTextStatus() == StatusKind.obstructed) { changeSet.addChange(new ObstructedConflict(status)); teamHasObstruction = true; } } // we need to stop here in case of obstruction, // as getChangesAndConflicts() would throw a // ClientException: if (teamHasObstruction) { log.info("obstructed status, not calling getChangesAndConflicts()"); // skip further detection of conflicts, because it would break } else { // no obstruction List<Change> allChanges = sc.getChangesAndConflicts(); for (Change change : allChanges) { Status status = change.getStatus(); // we don't know why yet, but files may sometimes be // set to "normal". We ignore these files, i.e. treat // them as non-modified: // TODO: check whether that's actually necessary anymore if ((status.getTextStatus() == StatusKind.none || status.getTextStatus() == StatusKind.normal) && (status.getRepositoryTextStatus() == StatusKind.none || status.getRepositoryTextStatus() == StatusKind.normal)) { log.debug("ignoring " + change + " ..."); continue; } if (status.getTextStatus() == StatusKind.external && (status.getRepositoryTextStatus() == StatusKind.none || status.getRepositoryTextStatus() == StatusKind.external)) { log.debug("ignoring " + change + " ..."); continue; } changeSet.addChange(change); } } changeSets.add(changeSet); log.debug("conflicts and changes: " + changeSet); log.debug("internal svn files (to be ignored): " + toIgnore); log.debug("time required to find changes for team '" + team.getName() + "': " + (System.currentTimeMillis() - startTime) + "ms"); } workspaceRoot = new File(selected.getWorkspaceFolder()); } catch (ClientException e) { // TODO: handle exception // may happen on very first checkout (before checkout, actually) // may happen on network timeout // may happen on wrong credentials // may happen on wrong server url // list of seen apr errors: // 175002: connection refused log.error(e.toString() + " (apr error " + e.getAprError() + ")", e); } catch (IOException e) { log.error(e); } return changeSets; }
From source file:org.pf9.pangu.app.act.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java
private List<String> getHighLightedFlows(String processInstanceId, ProcessDefinitionEntity processDefinition) { List<String> highLightedFlows = new ArrayList<String>(); List<HistoricActivityInstance> historicActivityInstances = historyService .createHistoricActivityInstanceQuery().processInstanceId(processInstanceId) .orderByHistoricActivityInstanceStartTime().asc().list(); List<String> historicActivityInstanceList = new ArrayList<String>(); for (HistoricActivityInstance hai : historicActivityInstances) { historicActivityInstanceList.add(hai.getActivityId()); }/*from www . j a v a 2 s. c o m*/ // add current activities to list List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId); historicActivityInstanceList.addAll(highLightedActivities); // activities and their sequence-flows for (ActivityImpl activity : processDefinition.getActivities()) { int index = historicActivityInstanceList.indexOf(activity.getId()); if (index >= 0 && index + 1 < historicActivityInstanceList.size()) { List<PvmTransition> pvmTransitionList = activity.getOutgoingTransitions(); for (PvmTransition pvmTransition : pvmTransitionList) { String destinationFlowId = pvmTransition.getDestination().getId(); if (destinationFlowId.equals(historicActivityInstanceList.get(index + 1))) { highLightedFlows.add(pvmTransition.getId()); } } } } return highLightedFlows; }
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java
/** * When someone presses the map, this method is called and draws the pickup * or dropoff point on the map depending on which of the {@link Button}s, * {@link #btnSelectPickupPoint} or {@link #btnSelectDropoffPoint} that is pressed. *//*from w ww.j a v a 2s . c o m*/ @Override public synchronized boolean onSingleTapUp(MotionEvent e) { if (!isSelectingDropoffPoint && !isSelectingPickupPoint) { return false; } GeoPoint gp = mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY()); MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(gp); // If the user is selecting a pickup point if (isSelectingPickupPoint) { Location temp = findClosestLocationOnRoute(mapLocation); //Controls if the user has entered a NEW address if (pickupPoint != temp) { // Removes old pickup point (thumb) if (overlayPickupThumb != null) { mapView.getOverlays().remove(overlayPickupThumb); overlayPickupThumb = null; } mapView.invalidate(); // If no dropoff point is specified, we add the pickup point to the map. if (dropoffPoint == null) { pickupPoint = temp; overlayPickupThumb = drawThumb(pickupPoint, true); // Set pickup TextView to the new address acPickup.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(pickupPoint)) .replace(",", "\n")); } else { // If a dropoff point is specified: List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData(); // Checks to make sure the pickup point is before the dropoff point. if (l.indexOf(temp) < l.indexOf(dropoffPoint)) { //makeToast("The pickup point has to be before the dropoff point"); AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this); ad.setMessage("The pickup point has to be before the dropoff point"); ad.setTitle("Unable to send request"); ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); ad.show(); } else { // Adds the pickup point to the map by drawing a thumb pickupPoint = temp; overlayPickupThumb = drawThumb(pickupPoint, true); // Set pickup TextView to the new address acPickup.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(pickupPoint)) .replace(",", "\n")); } } } // If the user is selecting a dropoff point } else if (isSelectingDropoffPoint) { Location temp = findClosestLocationOnRoute(mapLocation); // Controls if the user has entered a NEW address if (dropoffPoint != temp) { // Removes old dropoff point (thumb) if (overlayDropoffThumb != null) { mapView.getOverlays().remove(overlayDropoffThumb); overlayDropoffThumb = null; } mapView.invalidate(); // If no pickup point is specified, we add the dropoff point to the map. if (pickupPoint == null) { dropoffPoint = temp; overlayDropoffThumb = drawThumb(dropoffPoint, false); // Set dropoff TextView to the new address acDropoff.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(dropoffPoint)) .replace(",", "\n")); } else { // If a pickup point is specified: List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData(); // Checks to make sure the dropoff point is after the pickup point. if (l.indexOf(temp) > l.indexOf(pickupPoint)) { //makeToast("The droppoff point has to be after the pickup point"); AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this); ad.setMessage("The droppoff point has to be after the pickup point"); ad.setTitle("Unable to send request"); ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); ad.show(); } else { // Adds the dropoff point to the map by drawing a thumb dropoffPoint = temp; overlayDropoffThumb = drawThumb(dropoffPoint, false); // Set dropoff TextView to the new address acDropoff.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(dropoffPoint)) .replace(",", "\n")); } } } } return true; }
From source file:com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.java
@SuppressWarnings("unchecked") @Override// ww w. j a v a 2 s .c om public void committed(Set<Entity> entities) { if (!State.VALID.equals(masterDs.getState())) return; Collection<T> collection = getCollection(); if (collection != null) { for (T item : new ArrayList<>(collection)) { for (Entity entity : entities) { if (entity.equals(item)) { if (collection instanceof List) { List list = (List) collection; list.set(list.indexOf(item), entity); } else if (collection instanceof Set) { Set set = (Set) collection; set.remove(item); set.add(entity); } attachListener(entity); fireCollectionChanged(Operation.UPDATE, Collections.singletonList(item)); } } detachListener(item); // to avoid duplication in any case attachListener(item); } } for (Entity entity : entities) { if (entity.equals(item)) { item = (T) entity; } } modified = false; clearCommitLists(); }
From source file:com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.java
@SuppressWarnings("unchecked") public void replaceItem(T item) { checkNotNullArgument(item, "item is null"); Collection<T> collection = getCollection(); if (collection != null) { for (T t : collection) { if (t.equals(item)) { detachListener(t);/*from w w w . ja v a 2s . c o m*/ if (collection instanceof List) { List list = (List) collection; int itemIdx = list.indexOf(t); list.set(itemIdx, item); } else if (collection instanceof LinkedHashSet) { LinkedHashSet set = (LinkedHashSet) collection; List list = new ArrayList(set); int itemIdx = list.indexOf(t); list.set(itemIdx, item); set.clear(); set.addAll(list); } else { collection.remove(t); collection.add(item); } attachListener(item); if (item.equals(this.item)) { this.item = item; } break; } } if (sortInfos != null) doSort(); fireCollectionChanged(Operation.UPDATE, Collections.singletonList(item)); } }
From source file:de.bund.bfr.math.VectorDiffFunction.java
public VectorDiffFunction(List<String> formulas, List<String> dependentVariables, List<Double> initValues, List<String> initParameters, List<String> parameters, Map<String, List<Double>> variableValues, List<Double> timeValues, String dependentVariable, String timeVariable, IntegratorFactory integrator, InterpolationFactory interpolator) throws ParseException { this.formulas = formulas; this.dependentVariables = dependentVariables; this.initValues = initValues; this.initParameters = initParameters; this.parameters = parameters; this.variableValues = variableValues; this.dependentVariable = dependentVariable; this.timeValues = timeValues; this.timeVariable = timeVariable; this.integrator = integrator; this.interpolator = interpolator; variableFunctions = MathUtils.createInterpolationFunctions(variableValues, timeVariable, interpolator); dependentIndex = dependentVariables.indexOf(dependentVariable); parser = new Parser(); functions = new ArrayList<>(); for (String f : formulas) { functions.add(parser.parse(f));/*from w w w . ja v a 2 s . c om*/ } }
From source file:com.igormaznitsa.jcp.maven.PreprocessorMojo.java
private void replaceSourceRootByPreprocessingDestinationFolder(@Nonnull final PreprocessorContext context) throws IOException { if (this.project != null) { final String sourceDirectories = context.getSourceDirectories(); final String[] splitted = sourceDirectories.split(";"); final List<String> sourceRoots = this.getUseTestSources() ? this.testCompileSourceRoots : this.compileSourceRoots; final List<String> sourceRootsAsCanonical = new ArrayList<String>(); for (final String src : sourceRoots) { sourceRootsAsCanonical.add(new File(src).getCanonicalPath()); }//from www . j av a2s . c o m for (final String str : splitted) { int index = sourceRoots.indexOf(str); if (index < 0) { // check for canonical paths final File src = new File(str); final String canonicalPath = src.getCanonicalPath(); index = sourceRootsAsCanonical.indexOf(canonicalPath); } if (index >= 0) { info("A Compile source root has been removed from the root list [" + sourceRoots.get(index) + ']'); sourceRoots.remove(index); } } final String destinationDir = context.getDestinationDirectoryAsFile().getCanonicalPath(); sourceRoots.add(destinationDir); info("The New compile source root has been added into the list [" + destinationDir + ']'); } }
From source file:com.limegroup.gnutella.metadata.MP3DataEditor.java
/** * Actually writes the ID3 tags out to the ID3V3 section of the mp3 file */// www . j av a 2 s . c o m private int writeID3V2DataToDisk(File file) throws IOException, ID3v2Exception { ID3v2 id3Handler = new ID3v2(file); Vector frames = null; try { frames = (Vector) id3Handler.getFrames().clone(); } catch (NoID3v2TagException ex) {//there are no ID3v2 tags in the file //fall thro' we'll deal with it later -- frames will be null } List framesToUpdate = new ArrayList(); addAllNeededFrames(framesToUpdate); if (framesToUpdate.size() == 0) //we have nothing to update return LimeXMLReplyCollection.NORMAL; if (frames != null) { //old frames present, update the differnt ones for (Iterator iter = frames.iterator(); iter.hasNext();) { ID3v2Frame oldFrame = (ID3v2Frame) iter.next(); //note: equality of ID3v2Frame based on value of id int index = framesToUpdate.indexOf(oldFrame); ID3v2Frame newFrame = null; if (index >= 0) { newFrame = (ID3v2Frame) framesToUpdate.remove(index); if (Arrays.equals(oldFrame.getContent(), newFrame.getContent())) continue;//no need to update, skip this frame } //we are either going to replace it if it was changed, or remove //it since there is no equivalent frame in the ones we need to //update, this means the user probably removed it id3Handler.removeFrame(oldFrame); if (newFrame != null) id3Handler.addFrame(newFrame); } } //now we are left with the ones we need to add only, if there were no //old tags this will be all the frames that need to get updated for (Iterator iter = framesToUpdate.iterator(); iter.hasNext();) { ID3v2Frame frame = (ID3v2Frame) iter.next(); id3Handler.addFrame(frame); } id3Handler.update(); //No Exceptions? We are home return LimeXMLReplyCollection.NORMAL; }