List of usage examples for java.util ArrayList isEmpty
public boolean isEmpty()
From source file:gov.wa.wsdot.android.wsdot.ui.NewsFragment.java
public void onLoadFinished(Loader<ArrayList<NewsItem>> loader, ArrayList<NewsItem> data) { if (!data.isEmpty()) { mAdapter.setData(data);// w w w. j a v a 2 s . c o m } else { TextView t = (TextView) mEmptyView; t.setText(R.string.no_connection); getListView().setEmptyView(mEmptyView); } swipeRefreshLayout.setRefreshing(false); }
From source file:com.enitalk.opentok.CheckAvailabilityRunnable.java
private String makeChat(JsonNode event) { String out = null;/*from w ww .jav a 2s .c o m*/ try { ArrayList<JsonNode> data = pubnub.fetchData(event); if (data.isEmpty()) { logger.info("No text for event {}", event.path("ii").asText()); return out; } String chat = pubnub.makeChatText(event, data); return chat; } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } return out; }
From source file:com.google.developers.actions.debugger.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RECOGNIZER_REQ_CODE && resultCode == RESULT_OK) { ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (!matches.isEmpty()) { for (String match : matches) { if (match.startsWith(PLAY_PREFIX)) { askCayley(match.substring(PLAY_PREFIX.length())); Toast.makeText(this, match, Toast.LENGTH_LONG).show(); break; }/*from www .j a v a 2 s .c o m*/ } //Result code for various error. } else if (resultCode == RecognizerIntent.RESULT_AUDIO_ERROR) { Utils.showError(MainActivity.this, "Audio Error"); } else if (resultCode == RecognizerIntent.RESULT_CLIENT_ERROR) { Utils.showError(MainActivity.this, "Client Error"); } else if (resultCode == RecognizerIntent.RESULT_NETWORK_ERROR) { Utils.showError(MainActivity.this, "Network Error"); } else if (resultCode == RecognizerIntent.RESULT_NO_MATCH) { Utils.showError(MainActivity.this, "No Match"); } else if (resultCode == RecognizerIntent.RESULT_SERVER_ERROR) { Utils.showError(MainActivity.this, "Server Error"); } } }
From source file:net.opentsdb.tree.Tree.java
/** * Attempts to fetch the given tree from storage, loading the rule set at * the same time./*from w w w . ja va2s . c o m*/ * @param tsdb The TSDB to use for access * @param tree_id The Tree to fetch * @return A tree object if found, null if the tree did not exist * @throws IllegalArgumentException if the tree ID was invalid * @throws HBaseException if a storage exception occurred * @throws JSONException if the object could not be deserialized */ public static Deferred<Tree> fetchTree(final TSDB tsdb, final int tree_id) { if (tree_id < 1 || tree_id > 65535) { throw new IllegalArgumentException("Invalid Tree ID"); } // fetch the whole row final GetRequest get = new GetRequest(tsdb.treeTable(), idToBytes(tree_id)); get.family(TREE_FAMILY); /** * Called from the GetRequest with results from storage. Loops through the * columns and loads the tree definition and rules */ final class FetchTreeCB implements Callback<Deferred<Tree>, ArrayList<KeyValue>> { @Override public Deferred<Tree> call(ArrayList<KeyValue> row) throws Exception { if (row == null || row.isEmpty()) { return Deferred.fromResult(null); } final Tree tree = new Tree(); // WARNING: Since the JSON in storage doesn't store the tree ID, we need // to loadi t from the row key. tree.setTreeId(bytesToId(row.get(0).key())); for (KeyValue column : row) { if (Bytes.memcmp(TREE_QUALIFIER, column.qualifier()) == 0) { // it's *this* tree. We deserialize to a new object and copy // since the columns could be in any order and we may get a rule // before the tree object final Tree local_tree = JSON.parseToObject(column.value(), Tree.class); tree.created = local_tree.created; tree.description = local_tree.description; tree.name = local_tree.name; tree.notes = local_tree.notes; tree.strict_match = local_tree.strict_match; tree.enabled = local_tree.enabled; tree.store_failures = local_tree.store_failures; // Tree rule } else if (Bytes.memcmp(TreeRule.RULE_PREFIX(), column.qualifier(), 0, TreeRule.RULE_PREFIX().length) == 0) { final TreeRule rule = TreeRule.parseFromStorage(column); tree.addRule(rule); } } return Deferred.fromResult(tree); } } // issue the get request return tsdb.getClient().get(get).addCallbackDeferring(new FetchTreeCB()); }
From source file:net.robotmedia.billing.BillingController.java
/** * Called after the response to a/*from w w w. j a va 2 s .co m*/ * {@link net.robotmedia.billing.request.GetPurchaseInformation} request is * received. Registers all transactions in local memory and confirms those * who can be confirmed automatically. * * @param context * @param signedData * signed JSON data received from the Market Billing service. * @param signature * data signature. */ protected static void onPurchaseStateChanged(Context context, String signedData, String signature) { debug("Purchase state changed"); if (TextUtils.isEmpty(signedData)) { Log.w(LOG_TAG, "Signed data is empty"); return; } else { debug(signedData); } if (!debug) { if (TextUtils.isEmpty(signature)) { Log.w(LOG_TAG, "Empty signature requires debug mode"); return; } final ISignatureValidator validator = BillingController.validator != null ? BillingController.validator : new DefaultSignatureValidator(BillingController.configuration); if (!validator.validate(signedData, signature)) { Log.w(LOG_TAG, "Signature does not match data."); return; } } List<Transaction> purchases; try { JSONObject jObject = new JSONObject(signedData); if (!verifyNonce(jObject)) { Log.w(LOG_TAG, "Invalid nonce"); return; } purchases = parsePurchases(jObject); } catch (JSONException e) { Log.e(LOG_TAG, "JSON exception: ", e); return; } ArrayList<String> confirmations = new ArrayList<String>(); for (Transaction p : purchases) { if (p.notificationId != null && automaticConfirmations.contains(p.productId)) { confirmations.add(p.notificationId); } else { // TODO: Discriminate between purchases, cancellations and // refunds. addManualConfirmation(p.productId, p.notificationId); } storeTransaction(context, p); notifyPurchaseStateChange(p.productId, p.purchaseState); } if (!confirmations.isEmpty()) { final String[] notifyIds = confirmations.toArray(new String[confirmations.size()]); confirmNotifications(context, notifyIds); } }
From source file:org.sasabus.export2Freegis.network.DataReadyManager.java
@Override public void handle(HttpExchange httpExchange) throws IOException { long start = System.currentTimeMillis(); BufferedReader in = new BufferedReader(new InputStreamReader(httpExchange.getRequestBody(), "UTF-8")); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(httpExchange.getResponseBody())); try {/*w w w . j a v a 2 s . com*/ StringBuilder requestStringBuff = new StringBuilder(); int b; while ((b = in.read()) != -1) { requestStringBuff.append((char) b); } Scanner sc = new Scanner(new File(DATAACKNOWLEDGE)); String rdyackstring = ""; while (sc.hasNextLine()) { rdyackstring += sc.nextLine(); } sc.close(); SimpleDateFormat date_date = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat date_time = new SimpleDateFormat("HH:mm:ssZ"); Date d = new Date(); String timestamp = date_date.format(d) + "T" + date_time.format(d); timestamp = timestamp.substring(0, timestamp.length() - 2) + ":" + timestamp.substring(timestamp.length() - 2); rdyackstring = rdyackstring.replaceAll(":timestamp", timestamp); httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, rdyackstring.length()); out.write(rdyackstring); out.flush(); long before_elab = System.currentTimeMillis() - start; DataRequestManager teqrequest = new DataRequestManager(this.hostname, this.portnumber); String datarequest = teqrequest.datarequest(); ArrayList<TeqObjects> requestelements = TeqXMLUtils.extractFromXML(datarequest); int vtcounter = 0; if (!requestelements.isEmpty()) { Iterator<TeqObjects> iterator = requestelements.iterator(); System.out.println("Sending List of Elements!"); String geoJson = "{\"type\":\"FeatureCollection\",\"features\":["; while (iterator.hasNext()) { TeqObjects object = iterator.next(); if (object instanceof VehicleTracking) { geoJson += ((VehicleTracking) object).toGeoJson() + ","; ++vtcounter; } } if (geoJson.charAt(geoJson.length() - 1) == ',') { geoJson = geoJson.substring(0, geoJson.length() - 1); } geoJson += "]}"; System.out.println( "GeoJson sent! (Nr of elements: " + vtcounter + "/" + requestelements.size() + " )"); HttpPost subrequest = new HttpPost(DATASEND); StringEntity requestEntity = new StringEntity(geoJson, ContentType.create("application/json", "UTF-8")); CloseableHttpClient httpClient = HttpClients.createDefault(); subrequest.setEntity(requestEntity); long after_elab = System.currentTimeMillis() - start; CloseableHttpResponse response = httpClient.execute(subrequest); //System.out.println("Stauts JsonSend Response: " + response.getStatusLine().getStatusCode()); //System.out.println("Status JsonSend Phrase: " + response.getStatusLine().getReasonPhrase()); httpClient.close(); long before_db = System.currentTimeMillis() - start; dbmanager.insertIntoDatabase(requestelements); System.out.format( "Thread time (ms) : Before elab: %d, After Elab (before http sending): %d, Before db: %d, Total: %d, Thread name: %s, Objects elaborated: %d", before_elab, after_elab, before_db, (System.currentTimeMillis() - start), Thread.currentThread().getName(), requestelements.size()); System.out.println(""); } } catch (IOException e) { System.err.println(e.getMessage()); e.printStackTrace(); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(-1); return; } finally { if (in != null) in.close(); if (out != null) out.close(); if (httpExchange != null) httpExchange.close(); } }
From source file:com.pinterest.deployservice.scm.PhabricatorManager.java
@Override public CommitBean getCommit(String repo, String sha) throws Exception { String input = String.format(QUERY_COMMITS_HISTORY_PARAMETER, sha, 1, repo); Map<String, Object> json = queryCLI(input); @SuppressWarnings("unchecked") Map<String, Object> response = (Map<String, Object>) json.get("response"); @SuppressWarnings("unchecked") ArrayList<Map<String, Object>> commitsArray = (ArrayList<Map<String, Object>>) response.get("pathChanges"); if (!commitsArray.isEmpty()) { return toCommitBean(commitsArray.get(0), repo); } else {//from ww w. ja v a2 s . c o m throw new Exception("Invalid SHA or branch name passed to Phabricator getCommitBean!"); } }
From source file:net.opentsdb.tree.Tree.java
/** * Returns the not-matched set from storage for the given tree, optionally for * only the list of TSUIDs provided.//from w w w . j a v a 2 s .com * <b>Note:</b> This can potentially be a large list if the rule set was * written poorly and there were many timeseries so only call this * without a list of TSUIDs if you feel confident the number is small. * @param tsdb TSDB to use for storage access * @param tree_id ID of the tree to fetch non matches for * @param tsuids An optional list of TSUIDs to fetch non-matches for. This may * be empty or null, in which case all non-matches for the tree will be * returned. * @return A list of not-matched mappings or null if nothing was found * @throws HBaseException if there was an issue * @throws IllegalArgumentException if the tree ID was invalid */ public static Deferred<Map<String, String>> fetchNotMatched(final TSDB tsdb, final int tree_id, final List<String> tsuids) { if (tree_id < 1 || tree_id > 65535) { throw new IllegalArgumentException("Invalid Tree ID"); } final byte[] row_key = new byte[TREE_ID_WIDTH + 1]; System.arraycopy(idToBytes(tree_id), 0, row_key, 0, TREE_ID_WIDTH); row_key[TREE_ID_WIDTH] = NOT_MATCHED_ROW_SUFFIX; final GetRequest get = new GetRequest(tsdb.treeTable(), row_key); get.family(TREE_FAMILY); // if the caller provided a list of TSUIDs, then we need to compile a list // of qualifiers so we only fetch those columns. if (tsuids != null && !tsuids.isEmpty()) { final byte[][] qualifiers = new byte[tsuids.size()][]; int index = 0; for (String tsuid : tsuids) { final byte[] qualifier = new byte[NOT_MATCHED_PREFIX.length + (tsuid.length() / 2)]; System.arraycopy(NOT_MATCHED_PREFIX, 0, qualifier, 0, NOT_MATCHED_PREFIX.length); final byte[] tsuid_bytes = UniqueId.stringToUid(tsuid); System.arraycopy(tsuid_bytes, 0, qualifier, NOT_MATCHED_PREFIX.length, tsuid_bytes.length); qualifiers[index] = qualifier; index++; } get.qualifiers(qualifiers); } /** * Called after issuing the row get request to parse out the results and * compile the list of collisions. */ final class GetCB implements Callback<Deferred<Map<String, String>>, ArrayList<KeyValue>> { @Override public Deferred<Map<String, String>> call(final ArrayList<KeyValue> row) throws Exception { if (row == null || row.isEmpty()) { final Map<String, String> empty = new HashMap<String, String>(0); return Deferred.fromResult(empty); } Map<String, String> not_matched = new HashMap<String, String>(row.size()); for (KeyValue column : row) { final byte[] parsed_tsuid = Arrays.copyOfRange(column.qualifier(), NOT_MATCHED_PREFIX.length, column.qualifier().length); not_matched.put(UniqueId.uidToString(parsed_tsuid), new String(column.value(), CHARSET)); } return Deferred.fromResult(not_matched); } } return tsdb.getClient().get(get).addCallbackDeferring(new GetCB()); }
From source file:net.opentsdb.tree.Tree.java
/** * Returns the collision set from storage for the given tree, optionally for * only the list of TSUIDs provided.// w w w .j a va 2s .c o m * <b>Note:</b> This can potentially be a large list if the rule set was * written poorly and there were many timeseries so only call this * without a list of TSUIDs if you feel confident the number is small. * @param tsdb TSDB to use for storage access * @param tree_id ID of the tree to fetch collisions for * @param tsuids An optional list of TSUIDs to fetch collisions for. This may * be empty or null, in which case all collisions for the tree will be * returned. * @return A list of collisions or null if nothing was found * @throws HBaseException if there was an issue * @throws IllegalArgumentException if the tree ID was invalid */ public static Deferred<Map<String, String>> fetchCollisions(final TSDB tsdb, final int tree_id, final List<String> tsuids) { if (tree_id < 1 || tree_id > 65535) { throw new IllegalArgumentException("Invalid Tree ID"); } final byte[] row_key = new byte[TREE_ID_WIDTH + 1]; System.arraycopy(idToBytes(tree_id), 0, row_key, 0, TREE_ID_WIDTH); row_key[TREE_ID_WIDTH] = COLLISION_ROW_SUFFIX; final GetRequest get = new GetRequest(tsdb.treeTable(), row_key); get.family(TREE_FAMILY); // if the caller provided a list of TSUIDs, then we need to compile a list // of qualifiers so we only fetch those columns. if (tsuids != null && !tsuids.isEmpty()) { final byte[][] qualifiers = new byte[tsuids.size()][]; int index = 0; for (String tsuid : tsuids) { final byte[] qualifier = new byte[COLLISION_PREFIX.length + (tsuid.length() / 2)]; System.arraycopy(COLLISION_PREFIX, 0, qualifier, 0, COLLISION_PREFIX.length); final byte[] tsuid_bytes = UniqueId.stringToUid(tsuid); System.arraycopy(tsuid_bytes, 0, qualifier, COLLISION_PREFIX.length, tsuid_bytes.length); qualifiers[index] = qualifier; index++; } get.qualifiers(qualifiers); } /** * Called after issuing the row get request to parse out the results and * compile the list of collisions. */ final class GetCB implements Callback<Deferred<Map<String, String>>, ArrayList<KeyValue>> { @Override public Deferred<Map<String, String>> call(final ArrayList<KeyValue> row) throws Exception { if (row == null || row.isEmpty()) { final Map<String, String> empty = new HashMap<String, String>(0); return Deferred.fromResult(empty); } final Map<String, String> collisions = new HashMap<String, String>(row.size()); for (KeyValue column : row) { if (column.qualifier().length > COLLISION_PREFIX.length && Bytes.memcmp(COLLISION_PREFIX, column.qualifier(), 0, COLLISION_PREFIX.length) == 0) { final byte[] parsed_tsuid = Arrays.copyOfRange(column.qualifier(), COLLISION_PREFIX.length, column.qualifier().length); collisions.put(UniqueId.uidToString(parsed_tsuid), new String(column.value(), CHARSET)); } } return Deferred.fromResult(collisions); } } return tsdb.getClient().get(get).addCallbackDeferring(new GetCB()); }
From source file:eulermind.MindDB.java
static public void setContainerProperty(Vertex source, String propName, ArrayList container) { if (container.isEmpty()) { source.removeProperty(propName); } else {/*from w ww . ja v a2s .com*/ source.setProperty(propName, container); } }