List of usage examples for java.util ArrayList isEmpty
public boolean isEmpty()
From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java
/** * Builds and returns a {@link MediaInfo} that was wrapped in a * {@link Bundle} by <code>fromMediaInfo</code>. * //from w ww. j a v a2 s. c o m * @see <code>fromMediaInfo()</code> * @param wrapper * @return */ public static MediaInfo toMediaInfo(Bundle wrapper) { if (null == wrapper) { return null; } MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE)); metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE)); metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO)); ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES); if (null != images && !images.isEmpty()) { for (String url : images) { Uri uri = Uri.parse(url); metaData.addImage(new WebImage(uri)); } } String customDataStr = wrapper.getString(KEY_CUSTOM_DATA); JSONObject customData = null; if (!TextUtils.isEmpty(customDataStr)) { try { customData = new JSONObject(customDataStr); } catch (JSONException e) { Log.e(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr); } } return new MediaInfo.Builder(wrapper.getString(KEY_URL)).setStreamType(wrapper.getInt(KEY_STREAM_TYPE)) .setContentType(wrapper.getString(KEY_CONTENT_TYPE)).setMetadata(metaData).setCustomData(customData) .build(); }
From source file:org.opendatakit.odktables.relation.DbColumnDefinitions.java
/** * This code needs to parallel that of the javascript in ODK Survey and the java * code in ODK Tables and the ODK Database layer. * // w w w.j ava 2s . co m * @param defnList */ public static void markUnitOfRetention(List<DbColumnDefinitionsEntity> defnList) { // for all arrays, mark all descendants of the array as not-retained // because they are all folded up into the json representation of the array Map<String, DbColumnDefinitionsEntity> defn = new HashMap<String, DbColumnDefinitionsEntity>(); for (DbColumnDefinitionsEntity colDefn : defnList) { defn.put(colDefn.getElementKey(), colDefn); } for (DbColumnDefinitionsEntity colDefn : defnList) { if (!colDefn.isUnitOfRetention()) { // this has already been processed continue; } String elementType = colDefn.getElementType(); ArrayList<String> childElementKeys = colDefn.getArrayListChildElementKeys(); ElementType type = ElementType.parseElementType(elementType, !childElementKeys.isEmpty()); if (type.getDataType() == ElementDataType.array) { ArrayList<String> scratchArray = new ArrayList<String>(); while (!childElementKeys.isEmpty()) { for (String childKey : childElementKeys) { DbColumnDefinitionsEntity subDefn = defn.get(childKey); if (!subDefn.isUnitOfRetention()) { // this has already been processed continue; } subDefn.setNotUnitOfRetention(); if (subDefn.getListChildElementKeys() != null) { scratchArray.addAll(subDefn.getArrayListChildElementKeys()); } } childElementKeys = scratchArray; scratchArray = new ArrayList<String>(); } } } // and mark any non-arrays with multiple fields as not retained for (DbColumnDefinitionsEntity colDefn : defnList) { if (!colDefn.isUnitOfRetention()) { // this has already been processed continue; } String elementType = colDefn.getElementType(); ArrayList<String> childElementKeys = colDefn.getArrayListChildElementKeys(); ElementType type = ElementType.parseElementType(elementType, !childElementKeys.isEmpty()); if (type.getDataType() != ElementDataType.array) { if (!colDefn.getArrayListChildElementKeys().isEmpty()) { colDefn.setNotUnitOfRetention(); } } } }
From source file:cz.incad.kramerius.virtualcollections.VirtualCollectionsManager.java
public static VirtualCollection doVC(String pid, FedoraAccess fedoraAccess, ArrayList<String> languages) { try {/*w w w. j av a 2s .co m*/ String xPathStr; XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr; ArrayList<String> langs = new ArrayList<String>(); if (languages == null || languages.isEmpty()) { String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages"); for (int i = 0; i < ls.length; i++) { String lang = ls[++i]; langs.add(lang); } } else { langs = new ArrayList<String>(languages); } String name = ""; boolean canLeave = true; fedoraAccess.getDC(pid); Document doc = fedoraAccess.getDC(pid); xPathStr = "//dc:title/text()"; expr = xpath.compile(xPathStr); Node node = (Node) expr.evaluate(doc, XPathConstants.NODE); if (node != null) { name = StringEscapeUtils.escapeXml(node.getNodeValue()); } xPathStr = "//dc:type/text()"; expr = xpath.compile(xPathStr); node = (Node) expr.evaluate(doc, XPathConstants.NODE); if (node != null) { canLeave = Boolean.parseBoolean(StringEscapeUtils.escapeXml(node.getNodeValue())); } VirtualCollection vc = new VirtualCollection(name, pid, canLeave); for (String lang : langs) { String dsName = TEXT_DS_PREFIX + lang; String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName), Charset.forName("UTF8"), true); vc.addDescription(lang, value); } return vc; } catch (Exception vcex) { logger.log(Level.WARNING, "Could not get virtual collection for " + pid + ": " + vcex.toString()); return null; } }
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. java 2s .c o 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; }/* w w w . jav a 2 s. 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: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; }/*from ww w . j av a2 s . c o 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()) { LauncherState app = LauncherState.getInstance(); app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts); } } }
From source file:com.dh.perfectoffer.event.framework.net.network.NetworkConnectionImpl.java
/** * ???/*from w w w . ja v a2s .c om*/ * * @param paramText * @return */ private static String bulidFormText(ArrayList<BasicNameValuePair> paramText) { if (paramText == null || paramText.isEmpty()) return ""; StringBuffer sb = new StringBuffer(""); for (BasicNameValuePair bnvp : paramText) { sb.append(PREFIX).append(BOUNDARY).append(LINEND); sb.append("Content-Disposition:form-data;name=\"" + bnvp.getName() + "\"" + LINEND); sb.append(LINEND); sb.append(bnvp.getValue()); sb.append(LINEND); } return sb.toString(); }
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; }/*from w w w. ja v a 2 s . com*/ } // 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:edu.usc.squash.Main.java
private static HashMap<String, Module> parseQASMHF(Library library) { HFQParser hfqParser = null;//w w w .j a v a2s. c om /* * Pass 1: Getting module info */ try { hfqParser = new HFQParser(new FileInputStream(hfqPath)); } catch (FileNotFoundException e) { e.printStackTrace(); } HashMap<String, Module> moduleMap = hfqParser.parse(library, true, null); /* * In order traversal of modules */ ArrayList<CalledModule> modulesList = new ArrayList<CalledModule>(); modulesList.add(new CalledModule(moduleMap.get("main"), new ArrayList<String>())); while (!modulesList.isEmpty()) { Module module = modulesList.get(0).getModule(); if (!module.isVisited()) { module.setVisited(); ArrayList<CalledModule> calledModules = module.getChildModules(); modulesList.addAll(calledModules); for (CalledModule calledModule : calledModules) { Module childModule = calledModule.getModule(); for (int i = 0; i < calledModule.getOps().size(); i++) { Operand operand = childModule.getOperand(i); if (operand.isArray() && operand.getLength() == -1) { operand.setLength(module.getOperandLength(calledModule.getOps().get(i))); } } } } modulesList.remove(0); } /* * Pass 2: Making hierarchical QMDG */ try { hfqParser = new HFQParser(new FileInputStream(hfqPath)); } catch (FileNotFoundException e) { e.printStackTrace(); } HashMap<String, Module> modules = hfqParser.parse(library, false, moduleMap); return modules; }
From source file:net.opentsdb.tree.Leaf.java
/** * Attempts to fetch the requested leaf from storage. * <b>Note:</b> This method will not load the UID names from a TSDB. This is * only used to fetch a particular leaf from storage for collision detection * @param tsdb The TSDB to use for storage access * @param branch_id ID of the branch this leaf belongs to * @param display_name Name of the leaf/*w w w .j a va 2s. co m*/ * @return A valid leaf if found, null if the leaf did not exist * @throws HBaseException if there was an issue * @throws JSONException if the object could not be serialized */ private static Deferred<Leaf> getFromStorage(final TSDB tsdb, final byte[] branch_id, final String display_name) { final Leaf leaf = new Leaf(); leaf.setDisplayName(display_name); final GetRequest get = new GetRequest(tsdb.treeTable(), branch_id); get.family(Tree.TREE_FAMILY()); get.qualifier(leaf.columnQualifier()); /** * Called with the results of the fetch from storage */ final class GetCB implements Callback<Deferred<Leaf>, ArrayList<KeyValue>> { /** * @return null if the row was empty, a valid Leaf if parsing was * successful */ @Override public Deferred<Leaf> call(ArrayList<KeyValue> row) throws Exception { if (row == null || row.isEmpty()) { return Deferred.fromResult(null); } final Leaf leaf = JSON.parseToObject(row.get(0).value(), Leaf.class); return Deferred.fromResult(leaf); } } return tsdb.getClient().get(get).addCallbackDeferring(new GetCB()); }