List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:com.music.mybarr.activities.ExampleActivity.java
/** * Get Rdio's site-wide heavy rotation and play 30s samples. * Doesn't require auth or the Rdio app to be installed *///w w w .ja va2 s. c o m private void doSomethingWithoutApp() { Log.i(TAG, "Getting heavy rotation"); showGetHeavyRotationDialog(); List<NameValuePair> args = new LinkedList<NameValuePair>(); args.add(new BasicNameValuePair("type", "albums")); rdio.apiCall("getHeavyRotation", args, new RdioApiCallback() { @Override public void onApiSuccess(JSONObject result) { try { //Log.i(TAG, "Heavy rotation: " + result.toString(2)); JSONArray albums = result.getJSONArray("result"); final ArrayList<String> albumKeys = new ArrayList<String>(albums.length()); for (int i = 0; i < albums.length(); i++) { JSONObject album = albums.getJSONObject(i); String albumKey = album.getString("key"); albumKeys.add(albumKey); } // Build our argument to pass to the get api StringBuffer keyBuffer = new StringBuffer(); Iterator<String> iter = albumKeys.iterator(); while (iter.hasNext()) { keyBuffer.append(iter.next()); if (iter.hasNext()) { keyBuffer.append(","); } } Log.i(TAG, "album keys to fetch: " + keyBuffer.toString()); List<NameValuePair> getArgs = new LinkedList<NameValuePair>(); getArgs.add(new BasicNameValuePair("keys", keyBuffer.toString())); getArgs.add(new BasicNameValuePair("extras", "tracks")); // Get more details (like tracks) for all the albums we parsed out of the heavy rotation rdio.apiCall("get", getArgs, new RdioApiCallback() { @Override public void onApiFailure(String methodName, Exception e) { Log.e(TAG, "get() failed!", e); } @Override public void onApiSuccess(JSONObject result) { try { //Log.i(TAG, "get result: " + result.toString(2)); result = result.getJSONObject("result"); List<Track> trackKeys = new LinkedList<Track>(); // Build our list of tracks to put into the player queue for (String albumKey : albumKeys) { if (!result.has(albumKey)) { Log.w(TAG, "result didn't contain album key: " + albumKey); continue; } JSONObject album = result.getJSONObject(albumKey); JSONArray tracks = album.getJSONArray("tracks"); Log.i(TAG, "album " + albumKey + " has " + tracks.length() + " tracks"); for (int i = 0; i < tracks.length(); i++) { JSONObject trackObject = tracks.getJSONObject(i); String key = trackObject.getString("key"); String name = trackObject.getString("name"); String artist = trackObject.getString("artist"); String albumName = trackObject.getString("album"); String albumArt = trackObject.getString("icon"); Log.d(TAG, "Found track: " + key + " => " + trackObject.getString("name")); trackKeys.add(new Track(key, name, artist, albumName, albumArt)); } } if (trackKeys.size() > 1) trackQueue.addAll(trackKeys); dismissGetHeavyRotationDialog(); next(true); } catch (Exception e) { Log.e(TAG, "Failed to handle JSONObject: ", e); } } }); } catch (Exception e) { Log.e(TAG, "Failed to handle JSONObject: ", e); } finally { dismissGetHeavyRotationDialog(); } } @Override public void onApiFailure(String methodName, Exception e) { dismissGetHeavyRotationDialog(); Log.e(TAG, "getHeavyRotation failed. ", e); } }); }
From source file:ar.com.fdvs.dj.core.layout.ClassicLayoutManager.java
/** * Finds the highest sum of height for each possible alignment (left, center, right) * @param aligments/*from w w w. j a va2 s . com*/ * @param autotexts * @return */ protected int findTotalOffset(ArrayList aligments, ArrayList autotexts, byte position) { int total = 0; for (Iterator iterator = aligments.iterator(); iterator.hasNext();) { HorizontalBandAlignment currentAlignment = (HorizontalBandAlignment) iterator.next(); int aux = 0; for (Iterator iter = getReport().getAutoTexts().iterator(); iter.hasNext();) { AutoText autotext = (AutoText) iter.next(); if (autotext.getPosition() == position && currentAlignment.equals(autotext.getAlignment())) { aux += autotext.getHeight().intValue(); } } if (aux > total) total = aux; } return total; }
From source file:com.planetmayo.debrief.satc_rcp.views.SpatialView.java
private void plotRoutesWithScores(HashMap<LegWithRoutes, ArrayList<ScoredRoute>> legRoutes) { if (legRoutes.size() == 0) return;/*from w w w .ja va2 s . c o m*/ // we need to store the point labels. get ready to store them _scoredRouteLabels.clear(); final DateFormat labelTimeFormat = new SimpleDateFormat("mm:ss"); // work through the legs Iterator<LegWithRoutes> lIter = legRoutes.keySet().iterator(); while (lIter.hasNext()) { final LegWithRoutes thisL = lIter.next(); final ArrayList<ScoredRoute> scoredRoutes = legRoutes.get(thisL); double max = 0, min = Double.MAX_VALUE; for (Iterator<ScoredRoute> iterator = scoredRoutes.iterator(); iterator.hasNext();) { ScoredRoute route = iterator.next(); // Ensure thisScore is between 0-100 double thisScore = route.theScore; thisScore = Math.log(thisScore); if (max < thisScore) { max = thisScore; } if (min > thisScore) { min = thisScore; } } System.out.println(" for leg: " + thisL.getClass().getName() + " min:" + min + " max:" + max); for (Iterator<ScoredRoute> iterator = scoredRoutes.iterator(); iterator.hasNext();) { ScoredRoute route = iterator.next(); Point startP = route.theRoute.getStartPoint(); Point endP = route.theRoute.getEndPoint(); // Ensure thisScore is between 0-100 double thisScore = route.theScore; thisScore = Math.log(thisScore); double thisColorScore = (thisScore - min) / (max - min); // System.out.println("this s:" + (int) thisScore + " was:" // + route.theScore); XYSeries series = new XYSeries("" + (_numCycles++), false); series.add(new XYDataItem(startP.getY(), startP.getX())); series.add(new XYDataItem(endP.getY(), endP.getX())); // get the shape _myData.addSeries(series); // get the series num int num = _myData.getSeriesCount() - 1; _renderer.setSeriesPaint(num, getHeatMapColorFor(thisColorScore)); // make the line width inversely proportional to the score, with a max // width of 2 pixels final float width = (float) (2f - 2 * thisColorScore); // make the top score solid, and worse scores increasingly sparse final float dash[]; if (thisScore == min) { dash = null; } else { float thisWid = (float) (1f + Math.exp(thisScore - min) / 3); float[] tmpDash = { 4, thisWid }; dash = tmpDash; } // and put this line thickness, dashing into a stroke object BasicStroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, dash, 0.0f); _renderer.setSeriesStroke(num, stroke, false); _renderer.setSeriesLinesVisible(num, true); _renderer.setSeriesShapesVisible(num, false); _renderer.setSeriesVisibleInLegend(num, false); // ok, we'll also show the route points XYSeries series2 = new XYSeries("" + (_numCycles++), false); ArrayList<String> theseLabels = new ArrayList<String>(); // loop through the points Iterator<State> stIter = route.rawRoute.getStates().iterator(); while (stIter.hasNext()) { State state = (State) stIter.next(); Point loc = state.getLocation(); XYDataItem newPt = new XYDataItem(loc.getY(), loc.getX()); series2.add(newPt); // and store the label for this point theseLabels.add(labelTimeFormat.format(state.getTime())); } // get the shape _myData.addSeries(series2); // // // get the series num num = _myData.getSeriesCount() - 1; // ok, we now need to put hte series into the right slot _scoredRouteLabels.put(num, theseLabels); if (_settings.isShowRoutePointLabels()) { _renderer.setSeriesItemLabelGenerator(num, new XYItemLabelGenerator() { @Override public String generateLabel(XYDataset arg0, int arg1, int arg2) { String res = null; ArrayList<String> thisList = _scoredRouteLabels.get(arg1); if (thisList != null) { res = thisList.get(arg2); } return res; } }); _renderer.setSeriesItemLabelPaint(num, getHeatMapColorFor(thisColorScore)); } // _renderer.setSeriesPaint(num, getHeatMapColorFor(thisColorScore)); _renderer.setSeriesItemLabelsVisible(num, _settings.isShowRoutePointLabels()); _renderer.setSeriesLinesVisible(num, false); _renderer.setSeriesPaint(num, getHeatMapColorFor(thisColorScore)); _renderer.setSeriesShapesVisible(num, _settings.isShowRoutePoints()); _renderer.setSeriesVisibleInLegend(num, false); } } }
From source file:com.wavemaker.tools.project.upgrade.six_dot_four.RemoveMySQLHBMCatalogUpgradeTask.java
@Override public void doUpgrade(Project project, UpgradeInfo upgradeInfo) { Folder servicesFolder = project.getRootFolder().getFolder("services"); // Don't bother if we do not have services try {//from www .j av a2 s . c om if (servicesFolder.exists()) { Resource servicesDir = project.getProjectRoot().createRelative("services/"); ArrayList<String> mySQLServices = new ArrayList<String>(); try { // Find MySQL Services IOFileFilter propFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("properties")); List<File> propFiles = new UpgradeFileFinder(propFilter).findFiles(servicesDir.getFile()); Iterator<File> propIt = propFiles.iterator(); while (propIt.hasNext()) { File propFile = propIt.next(); String propContent = FileUtils.readFileToString(propFile); if (propContent.contains(mySQLStr)) { String propFileName = propFile.getName(); int index = propFileName.lastIndexOf("."); if (index > 0 && index <= propFileName.length()) { mySQLServices.add(propFileName.substring(0, index)); } } } // Find HBM files in MySQLServices Iterator<String> servIt = mySQLServices.iterator(); while (servIt.hasNext()) { IOFileFilter hbmFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("hbm.xml")); String path = servIt.next(); Resource mySQLServiceDir = servicesDir .createRelative(path.endsWith("/") ? path : path + "/"); List<File> hbmFiles = new UpgradeFileFinder(hbmFilter).findFiles(mySQLServiceDir.getFile()); Iterator<File> hbmIt = hbmFiles.iterator(); while (hbmIt.hasNext()) { File hbmFile = hbmIt.next(); String hbmContent = FileUtils.readFileToString(hbmFile); hbmContent.replaceFirst(catalogStr, replaceStr); FileUtils.writeStringToFile(hbmFile, hbmContent); System.out .println("Project upgrade: Catalog removed from " + hbmFile.getAbsolutePath()); } } if (!mySQLServices.isEmpty()) { upgradeInfo.addMessage("\nMySQL Catalog upgrade task completed. See wm.log for details"); } else { System.out.println("Project Upgrade: No MySQL Services found"); } } catch (IOException ioe) { upgradeInfo .addMessage("\nError removing Catalog from MySQL Services. Check wm.log for details."); ioe.printStackTrace(); } } else { System.out.println("Project Upgrade: No Services found"); } } catch (IOException e) { throw new WMRuntimeException(e); } }
From source file:de.suse.swamp.core.workflow.WorkflowTemplate.java
/** * @return A new workflow item following this template. * Not yet stored in DB, use createWorkflow() for creating a real * Workflow in the system.// w w w . ja va 2 s .c o m */ public Workflow getWorkflow() { ArrayList newNodes = new ArrayList(); // hashed by id for setting references in edges HashMap nodeLookup = new HashMap(); // first, get all nodes. beware: they still don't have edges. Keep a map // with (node.getId(), node) pairs for (Iterator iter = nodeTempls.keySet().iterator(); iter.hasNext();) { NodeTemplate ntmpl = (NodeTemplate) nodeTempls.get(iter.next()); Node newNode = ntmpl.getNode(); newNodes.add(newNode); nodeLookup.put(newNode.getName(), newNode); } // now that all nodes are created, loop over them again so that they may // create their edges. for (Iterator iter = newNodes.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); node.createEdges(nodeLookup); } // give it all nodes Workflow workflow = new Workflow(name, version); workflow.setNodes(newNodes); return workflow; }
From source file:de.uni_hannover.dcsec.siafu.model.World.java
/** * Create the people to simulate by asking the AgentModel to do so. * // w ww . ja va 2 s . c o m */ private synchronized void createPeople() { people = new HashMap<String, Agent>(); try { agentModel = (BaseAgentModel) simData.getAgentModelClass() .getConstructor(new Class[] { this.getClass() }).newInstance(new Object[] { this }); } catch (Exception e) { throw new RuntimeException("Can't instantiate the agent model", e); } Agent.initialize(this); Controller.getProgress().reportCreatingAgents(); ArrayList<Agent> peopleList = agentModel.createAgents(); Iterator<Agent> peopleIt = peopleList.iterator(); while (peopleIt.hasNext()) { Agent p = peopleIt.next(); people.put(p.getName(), p); } }
From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java
/**************************************************************************** * APPINFO UTILITIES/* ww w .j av a2 s.c o m*/ ****************************************************************************/ private Element getAppInfo(String regex) { Element appInfo = null; ArrayList<Element> list = new ArrayList<Element>(); // list.addAll(annotation.getUserInformation()); if (annotation == null) { return null; } list.addAll(annotation.getApplicationInformation()); for (Iterator<Element> iter = list.iterator(); iter.hasNext();) { Element ann = iter.next(); String name = ann.getLocalName(); if ("appinfo".equals(name.toLowerCase())) {//$NON-NLS-1$ name = ann.getAttribute("source");//$NON-NLS-1$ if (name.matches(regex)) { appInfo = ann; break; } } } return appInfo; }
From source file:com.bigdata.journal.jini.ha.AbstractHAJournalServerTestCase.java
private Iterator<File> getLogs(final File f, final FileFilter fileFilter) { final ArrayList<File> files = new ArrayList<File>(); recursiveAdd(files, f, fileFilter);//from ww w .j a v a2s . co m return files.iterator(); }
From source file:com.qspin.qtaste.testsuite.impl.JythonTestScript.java
private DebugVariable dumpJavaObject(Object javaObject, DebugVariable debugVar) { if (javaObject.getClass().getName().startsWith("java.lang.")) { return debugVar; }// www . j av a2s . co m if (javaObject.getClass().equals(ArrayList.class)) { ArrayList<?> arrayList = (ArrayList<?>) javaObject; Iterator<?> arrayListIt = arrayList.iterator(); int index = 0; while (arrayListIt.hasNext()) { Object javaObjectInArray = arrayListIt.next(); DebugVariable fieldVar = new DebugVariable("[" + index + "]", javaObjectInArray.getClass().toString(), javaObjectInArray.toString()); fieldVar = dumpJavaObject(javaObjectInArray, fieldVar); debugVar.addField(fieldVar); index++; } } Field[] fields = javaObject.getClass().getFields(); for (Field field : fields) { String fieldName = field.getName(); try { Object fieldObject = field.get(javaObject); String fieldValue = fieldObject.toString(); DebugVariable fieldVar = new DebugVariable(fieldName, field.getClass().toString(), fieldValue); fieldVar = dumpJavaObject(fieldValue, fieldVar); debugVar.addField(fieldVar); } catch (IllegalArgumentException e) { debugVar.addField(new DebugVariable(fieldName, field.getClass().toString(), "Illegal argument")); } catch (IllegalAccessException e) { debugVar.addField( new DebugVariable(fieldName, field.getClass().toString(), "Illegal Access Exception")); } catch (NullPointerException e) { debugVar.addField( new DebugVariable(fieldName, field.getClass().toString(), "Null Pointer Exception")); } } Method[] methods = javaObject.getClass().getMethods(); for (Method method : methods) { if ((method.getName().startsWith("get")) && (!(method.getName().equals("getClass"))) && (!(method.getName().equals("getAccessorKeys")))) { try { Object returnValue = method.invoke(javaObject); DebugVariable fieldVar = new DebugVariable(method.getName(), javaObject.getClass().toString(), returnValue.toString()); fieldVar = dumpJavaObject(returnValue, fieldVar); debugVar.addField(fieldVar); } catch (Exception e) { } } } return debugVar; }
From source file:com.openkm.module.jcr.JcrSearchModule.java
@Override public Map<String, Integer> getKeywordMap(String token, List<String> filter) throws RepositoryException, DatabaseException { log.debug("getKeywordMap({}, {})", token, filter); String statement = "/jcr:root//*[@jcr:primaryType eq 'okm:document' or @jcr:primaryType eq 'okm:mail' or @jcr:primaryType eq 'okm:folder']"; HashMap<String, Integer> cloud = new HashMap<String, Integer>(); Session session = null;/* w w w. j av a 2s. c o m*/ try { if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } Workspace workspace = session.getWorkspace(); QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, Query.XPATH); javax.jcr.query.QueryResult qResult = query.execute(); for (NodeIterator nit = qResult.getNodes(); nit.hasNext();) { Node doc = nit.nextNode(); Value[] keywordsValue = doc.getProperty(com.openkm.bean.Property.KEYWORDS).getValues(); ArrayList<String> keywordCollection = new ArrayList<String>(); for (int i = 0; i < keywordsValue.length; i++) { keywordCollection.add(keywordsValue[i].getString()); } if (filter != null && keywordCollection.containsAll(filter)) { for (Iterator<String> it = keywordCollection.iterator(); it.hasNext();) { String keyword = it.next(); if (!filter.contains(keyword)) { Integer occurs = cloud.get(keyword) != null ? cloud.get(keyword) : 0; cloud.put(keyword, occurs + 1); } } } } } catch (javax.jcr.RepositoryException e) { log.error(e.getMessage(), e); throw new RepositoryException(e.getMessage(), e); } finally { if (token == null) { JCRUtils.logout(session); } } log.debug("getKeywordMap: {}", cloud); return cloud; }