List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:com.ibm.watson.movieapp.dialog.fvt.config.Utils.java
/** * Get list of movie questions/* ww w.j a va 2 s . co m*/ * @param jsonFile * @return */ public static ArrayList<BaseQuestion> returnMovieList(String jsonFile) { ArrayList<BaseQuestion> questions = new ArrayList<BaseQuestion>(); RestAPI api = RestAPI.getAPI(); ArrayList<String> genre = api.getMovieOptions(GENRE, jsonFile); ArrayList<String> time = api.getMovieOptions(TIME, jsonFile); ArrayList<String> rating = api.getMovieOptions(RATING, jsonFile); ArrayList<String> expected = api.getMovieOptions(EXPECTED, jsonFile); Iterator<String> genreList = genre.iterator(); while (genreList.hasNext()) { String genreVal = genreList.next(); Iterator<String> timeList = time.iterator(); while (timeList.hasNext()) { String timeVal = timeList.next(); Iterator<String> ratingList = rating.iterator(); while (ratingList.hasNext()) { String ratingVal = ratingList.next(); BaseQuestion question = new BaseQuestion.Builder("").genre(genreVal).timeFrame(timeVal) .rating(ratingVal).expectedResponse(expected).build(); //Make question from parts question.makeQuestion(); //add question to list of questions questions.add(question); } } } return questions; }
From source file:it.cnr.isti.thematrix.scripting.sys.DatasetSchema.java
/** * Check if a set of attributes can be added to a dataset without duplication in the Schema, return null if no * issues are found. The method checks both duplication with the existing schema and duplicate name in the list of * attributes to be added. If passed a null or empty list of attributes, the method will warn in the logs but return * true. A detailed error message is returned if issues are found. * * @param schema/*from w ww . j a v a 2 s . c om*/ * the schema to extend * @param newAttributes * the List of new attributes as Symbol<?> * @return either a String with detailed error messages about all conflicting new attributes, or null if there are * none. */ public static String canExtend(DatasetSchema schema, List<Symbol<?>> newAttributes) { if (newAttributes == null || newAttributes.size() == 0) { LogST.logP(0, "WARNING DatasetSchema.canExtend() called with empty or null newAttributes"); return null; } String result = null; List<String> duplicates = new ArrayList<String>(); for (Symbol<?> attribute : newAttributes) { if (schema.containsKey(attribute.name)) duplicates.add(attribute.name); } if (duplicates.size() > 0) result = " new attributes duplicate existing attributes: " + duplicates.toString() + ";"; /** * sort the List of new attributes, so that we can check with the existing ones and between them. * We copy the list for sorting it, but we do not modify its elements. * FIXME the comparator for Symbol<?> should be in Symbol **/ ArrayList<Symbol<?>> copyNewAttributes = new ArrayList(newAttributes); Collections.sort(copyNewAttributes, new Comparator<Symbol<?>>() { public int compare(Symbol<?> s1, Symbol<?> s2) { return s1.name.compareTo(s2.name); } }); Iterator<Symbol<?>> i = copyNewAttributes.iterator(); Symbol<?> s = i.next(); // we know the list is not empty Symbol<?> prev = null; duplicates.clear(); while (i.hasNext()) { prev = s; s = i.next(); if (s.name.equals(prev.name)) duplicates.add(s.name); } if (duplicates.size() > 0) { if (result == null) result = ""; result = result + " new attributes duplicate each other: " + duplicates.toString() + ";"; } return result == null ? null : "DatasetSchema : " + result; }
From source file:XmlHelper.java
/** * Returns an iterator over the children of the given element with the given * tag name./*from w ww. j a v a2 s . c o m*/ * * @param element * The parent element * @param tagName * The name of the desired child * @return An interator of children or null if element is null. */ public static Iterator<Element> getChildrenByTagName(Element element, String tagName) { if (element == null) return null; // getElementsByTagName gives the corresponding elements in the whole // descendance. We want only children NodeList children = element.getChildNodes(); ArrayList<Element> goodChildren = new ArrayList<Element>(); for (int i = 0; i < children.getLength(); i++) { Node currentChild = children.item(i); if (currentChild.getNodeType() == Node.ELEMENT_NODE && ((Element) currentChild).getTagName().equals(tagName)) { goodChildren.add((Element) currentChild); } } return goodChildren.iterator(); }
From source file:com.android.launcher3.InstallShortcutReceiver.java
static void flushInstallQueue(Context context) { String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context); if (!installQueue.isEmpty()) { Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator(); ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>(); while (iter.hasNext()) { final PendingInstallShortcutInfo pendingInfo = iter.next(); final Intent intent = pendingInfo.launchIntent; if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) { if (DBG) Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent); continue; }//from w w w . j a v a 2s .co m // If the intent specifies a package, make sure the package exists String packageName = pendingInfo.getTargetPackage(); if (!TextUtils.isEmpty(packageName)) { UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) { if (DBG) Log.d(TAG, "Ignoring shortcut for absent package:" + intent); continue; } } final boolean exists = LauncherModel.shortcutExists(context, pendingInfo.label, intent, pendingInfo.user); if (!exists) { // Generate a shortcut info to add into the model addShortcuts.add(pendingInfo.getShortcutInfo()); } } // Add the new apps to the model and bind them if (!addShortcuts.isEmpty()) { LauncherAppState app = LauncherAppState.getInstance(); app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts); } } }
From source file:com.sanfriend.launcher4.InstallShortcutReceiver.java
static void flushInstallQueue(Context context) { String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context); if (!installQueue.isEmpty()) { Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator(); ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>(); while (iter.hasNext()) { final PendingInstallShortcutInfo pendingInfo = iter.next(); final Intent intent = pendingInfo.launchIntent; // If the intent specifies a package, make sure the package exists String packageName = pendingInfo.getTargetPackage(); if (!TextUtils.isEmpty(packageName)) { UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) { if (DBG) Log.d(TAG, "Ignoring shortcut for absent package:" + intent); continue; }//from w w w .j ava 2 s.co m } // Generate a shortcut info to add into the model addShortcuts.add(pendingInfo.getShortcutInfo()); } // Add the new apps to the model and bind them if (!addShortcuts.isEmpty()) { LauncherAppState app = LauncherAppState.getInstance(); app.getModel().addAndBindAddedWorkspaceItems(context, addShortcuts); } } }
From source file:com.stv.launcher.receiver.InstallShortcutReceiver.java
static void flushInstallQueue(Context context) { String spKey = LauncherState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context); if (!installQueue.isEmpty()) { Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator(); ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>(); while (iter.hasNext()) { final PendingInstallShortcutInfo pendingInfo = iter.next(); final Intent intent = pendingInfo.launchIntent; if (LauncherState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) { if (DBG) Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent); continue; }/*w w w.java 2s . c om*/ // If the intent specifies a package, make sure the package exists String packageName = pendingInfo.getTargetPackage(); if (!TextUtils.isEmpty(packageName)) { UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) { if (DBG) Log.d(TAG, "Ignoring shortcut for absent package:" + intent); continue; } } final boolean exists = LauncherModel.shortcutExists(context, pendingInfo.label, intent, pendingInfo.user); if (!exists) { // Generate a shortcut info to add into the model addShortcuts.add(pendingInfo.getShortcutInfo()); } } // Add the new apps to the model and bind them if (!addShortcuts.isEmpty()) { LauncherState app = LauncherState.getInstance(); app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts); } } }
From source file:DeadlockDetectingLock.java
private static Iterator getAllLocksOwned(Thread t) { DeadlockDetectingLock current;/*from w w w . j av a2 s . c o m*/ ArrayList results = new ArrayList(); Iterator itr = deadlockLocksRegistry.iterator(); while (itr.hasNext()) { current = (DeadlockDetectingLock) itr.next(); if (current.getOwner() == t) results.add(current); } return results.iterator(); }
From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java
static void flushInstallQueue(Context context) { SharedPreferences sp = Utilities.getPrefs(context); ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context); if (!installQueue.isEmpty()) { Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator(); ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>(); while (iter.hasNext()) { final PendingInstallShortcutInfo pendingInfo = iter.next(); // If the intent specifies a package, make sure the package exists String packageName = pendingInfo.getTargetPackage(); if (!TextUtils.isEmpty(packageName)) { UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) { if (DBG) Log.d(TAG, "Ignoring shortcut for absent package: " + pendingInfo.launchIntent); continue; }// w w w . j av a 2s . c om } // Generate a shortcut info to add into the model addShortcuts.add(pendingInfo.getShortcutInfo()); } // Add the new apps to the model and bind them if (!addShortcuts.isEmpty()) { LauncherAppState app = LauncherAppState.getInstance(); app.getModel().addAndBindAddedWorkspaceItems(context, addShortcuts); } } }
From source file:net.metanotion.web.html.Tag.java
public static Iterator<Object> writeTag(String tagName, Map<String, Object> attributes, boolean selfClose) { final ArrayList<Object> t = new ArrayList<>((attributes.size() * 5) + 2); t.add("<" + tagName); for (final Map.Entry<String, Object> e : attributes.entrySet()) { t.add(" "); t.add(e.getKey());//w ww.ja va 2 s . com final Object val = e.getValue(); if (val != null) { t.add("=\""); t.add(StringEscapeUtils.escapeHtml4(val.toString())); t.add("\""); } } t.add(selfClose ? "/>" : ">"); return t.iterator(); }
From source file:it.cnr.icar.eric.client.ui.thin.OutputExceptions.java
/** * Find a string which should provide most information about a Throwable. * * @param t Throwable of interest/* ww w. j a v a2 s .co m*/ * @param forLog If true, return more information; going into log * @return String message describing original cause for t */ private static String getCause(Throwable t, boolean forLog) { // Find all causes for this exception ArrayList<Throwable> causes = new ArrayList<Throwable>(); while (null != t) { causes.add(t); t = t.getCause(); } Collections.reverse(causes); // Work backwards through the causes to find the original // (hopefully most informative) detail string Iterator<Throwable> iter = causes.iterator(); String msg = null; while (iter.hasNext() && null == msg) { t = iter.next(); if (null != t.getMessage()) { // Detail string exists if (forLog) { // Always get class information as well msg = t.toString(); } else { msg = goodMessage(t); } } } // No detail found, use class information about root cause if (null == msg) { msg = (causes.get(0)).toString(); } return msg; }