List of usage examples for java.util ArrayList isEmpty
public boolean isEmpty()
From source file:com.concursive.connect.web.modules.members.portlets.InviteMembersPortlet.java
private void checkDuplicates(LinkedHashMap<String, String> members, String member, String userId) { Iterator<String> memIterator = members.keySet().iterator(); while (memIterator.hasNext()) { String keyName = memIterator.next(); String idValue = members.get(keyName); //check only previous values and not entire list if (keyName.equals(member)) { return; }//from w ww .ja v a 2 s . c om //check if valid ids if (NO_MATCH_FOUND.equals(idValue) || !StringUtils.hasText(idValue)) { continue; } //convert comma separated string to ArrayList and remove duplicates ArrayList<String> lstIds = new ArrayList<String>(Arrays.asList(idValue.split(","))); while (lstIds.contains(userId)) { lstIds.remove(userId); } //convert the id list to comma separated string and assign it to members list if there ids remaining if (!lstIds.isEmpty()) { String ids = lstIds.toString(); ids = ids.replace("[", ""); ids = ids.replace("]", ""); ids = ids.replace(" ", ""); members.put(keyName, ids); } else { memIterator.remove(); } } }
From source file:co.nerdart.ourss.activity.EditFeedActivity.java
public void onClickSearch(View view) { final View dialogView = getLayoutInflater().inflate(R.layout.search_feed, null); final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText); final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup); new AlertDialog.Builder(EditFeedActivity.this) // .setIcon(R.drawable.action_search) // .setTitle(R.string.feed_search) // .setView(dialogView) // .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() { @Override/*from ww w. j a v a 2 s . c o m*/ public void onClick(DialogInterface dialog, int which) { if (searchText.getText().length() > 0) { String tmp = searchText.getText().toString(); try { tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } final String text = tmp; switch (radioGroup.getCheckedRadioButtonId()) { case R.id.byWebSearch: final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this); pd.setMessage(getString(R.string.loading)); pd.setCancelable(true); pd.setIndeterminate(true); pd.show(); getLoaderManager().restartLoader(1, null, new LoaderCallbacks<ArrayList<HashMap<String, String>>>() { @Override public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) { return new GetFeedSearchResultsLoader(EditFeedActivity.this, text); } @Override public void onLoadFinished( Loader<ArrayList<HashMap<String, String>>> loader, final ArrayList<HashMap<String, String>> data) { pd.cancel(); if (data == null) { Crouton.makeText(EditFeedActivity.this, R.string.error, Style.INFO); } else if (data.isEmpty()) { Crouton.makeText(EditFeedActivity.this, R.string.no_result, Style.INFO); } else { AlertDialog.Builder builder = new AlertDialog.Builder( EditFeedActivity.this); builder.setTitle(R.string.feed_search); // create the grid item mapping String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC }; int[] to = new int[] { android.R.id.text1, android.R.id.text2 }; // fill in the grid_item layout SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data, R.layout.search_result_item, from, to); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mNameEditText.setText( data.get(which).get(FEED_SEARCH_TITLE)); mUrlEditText.setText( data.get(which).get(FEED_SEARCH_URL)); } }); builder.show(); } } @Override public void onLoaderReset( Loader<ArrayList<HashMap<String, String>>> loader) { } }).forceLoad(); break; case R.id.byTopic: mUrlEditText.setText("http://www.faroo.com/api?q=" + text + "&start=1&length=10&l=en&src=news&f=rss"); break; case R.id.byYoutube: mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "") + "/videos.rss"); break; } } } }).setNegativeButton(android.R.string.cancel, null).show(); }
From source file:com.github.jberkel.pay.me.IabHelper.java
private int querySkuDetails(ItemType itemType, Inventory inv, List<String> moreSkus) throws RemoteException, JSONException { logDebug("Querying SKU details."); ArrayList<String> skuList = new ArrayList<String>(); skuList.addAll(inv.getAllOwnedSkus(itemType)); if (moreSkus != null) { for (String sku : moreSkus) { if (!skuList.contains(sku)) { skuList.add(sku);/*from w w w . j av a 2 s . c o m*/ } } } if (skuList.isEmpty()) { logDebug("querySkuDetails: nothing to do because there are no SKUs."); return OK.code; } // TODO: check for 20 SKU limit + add batching ? Bundle querySkus = new Bundle(); querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList); Bundle skuDetails = mService.getSkuDetails(API_VERSION, mContext.getPackageName(), itemType.toString(), querySkus); if (skuDetails == null) return IABHELPER_BAD_RESPONSE.code; if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) { int response = getResponseCodeFromBundle(skuDetails); if (response != OK.code) { logWarn("getSkuDetails() failed: " + getDescription(response)); return response; } else { logError("getSkuDetails() returned a bundle with neither an error nor a detail list."); return IABHELPER_BAD_RESPONSE.code; } } ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST); for (String json : responseList) { inv.addSkuDetails(new SkuDetails(json)); } return OK.code; }
From source file:cpsControllers.ConversionController.java
/** * Bd redniokwadratowy (MSE, ang. <i>Mean Squared Error</i>) * // w ww . j a v a 2s . com * @param punktyY * @param _doPorownania * * @return */ public double obl_MSE(ArrayList<Double> punktyY, ArrayList<Double> _doPorownania) { double wynik = 0; try { if (!punktyY.isEmpty() && !_doPorownania.isEmpty()) { for (int i = 0; i < _doPorownania.size(); i++) { wynik = wynik + (punktyY.get(i) - _doPorownania.get(i)) * (punktyY.get(i) - _doPorownania.get(i)); } wynik = (1.0D / _doPorownania.size()) * wynik; } else { if (punktyY.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } else if (_doPorownania.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak konwersji sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } } } catch (Exception exc_MSE) { // JOptionPane.showMessageDialog(null, "Nie mona obliczy:\n" + exc_MSE.getMessage(), // "Bd", JOptionPane.ERROR_MESSAGE); } System.out.println("MSE = " + wynik); return wynik; }
From source file:de.nec.nle.siafu.model.World.java
/** * Get a random place out of all the places known for the given type. * // w ww .j av a 2 s . c o m * @param type * the type of place we need * @return a random place of type "type" * @throws PlaceNotFoundException * if there are no places of that type */ public Place getRandomPlaceOfType(final String type) throws PlaceNotFoundException { ArrayList<Place> typedPlaces = new ArrayList<Place>(); typedPlaces.addAll(getPlacesOfType(type)); if (typedPlaces.isEmpty()) { throw new PlacesTypeIsEmptyException(type); } return (Place) typedPlaces.get(rand.nextInt(typedPlaces.size())); }
From source file:cpsControllers.ConversionController.java
/** * Maksymalna rnica (MD, ang. <i>Maximum Difference</i>) * /*from ww w. jav a2 s.co m*/ * @return */ public double obl_MD(ArrayList<Double> punktyY, ArrayList<Double> _doPorownania) { double wynik = 0; try { if (!punktyY.isEmpty() && !_doPorownania.isEmpty()) { double tmp; wynik = Math.abs(punktyY.get(0) - _doPorownania.get(0)); for (int i = 1; i < _doPorownania.size(); i++) { tmp = Math.abs(punktyY.get(i) - _doPorownania.get(i)); if (wynik < tmp) { wynik = tmp; } } } else { if (punktyY.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } else if (_doPorownania.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak konwersji sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } } } catch (Exception exc_MSE) { // JOptionPane.showMessageDialog(null, "Nie mona obliczy:\n" + exc_MSE.getMessage(), // "Bd", JOptionPane.ERROR_MESSAGE); } System.out.println("MD = " + wynik); return wynik; }
From source file:cpsControllers.ConversionController.java
/** * Szczytowy stosunek sygna - szum (PSNR, ang. <i>Peak Signal to Noise * Ratio</i>)/*from www. j a v a 2 s . c o m*/ * * @return */ public double obl_PSNR(ArrayList<Double> pynktyY, ArrayList<Double> _doPorownania) { double wynik = 0; try { if (!pynktyY.isEmpty() && !_doPorownania.isEmpty()) { double licznik = pynktyY.get(0), mianownik = 0; for (int i = 1; i < _doPorownania.size(); i++) { if (licznik < pynktyY.get(i)) { licznik = pynktyY.get(i); } } mianownik = this.obl_MSE(pynktyY, _doPorownania); wynik = licznik / mianownik; wynik = 10.0D * Math.log10(wynik); } else { if (pynktyY.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } else if (_doPorownania.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak zapisanej konwersji sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } } } catch (Exception exc_MSE) { // JOptionPane.showMessageDialog(null, "Nie mona obliczy:\n" + exc_MSE.getMessage(), // "Bd", JOptionPane.ERROR_MESSAGE); } System.out.println("PSNR = " + wynik); return wynik; }
From source file:cpsControllers.ConversionController.java
/** * Stosunek sygna - szum (SNR, ang. <i>Signal to Noise Ratio</i>) * //from w ww . j a v a 2 s .c om * @param punktyY * @return */ public double obl_SNR(ArrayList<Double> punktyY, ArrayList<Double> _doPorownania) { double wynik = 0; try { if (!punktyY.isEmpty() && !_doPorownania.isEmpty()) { double licznik = 0, mianownik = 0; for (int i = 0; i < _doPorownania.size(); i++) { licznik = licznik + (punktyY.get(i) * punktyY.get(i)); } for (int i = 0; i < _doPorownania.size(); i++) { mianownik = mianownik + (punktyY.get(i) - _doPorownania.get(i)) * (punktyY.get(i) - _doPorownania.get(i)); } wynik = licznik / mianownik; wynik = 10.0D * Math.log10(wynik); } else { if (punktyY.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } else if (_doPorownania.isEmpty()) { JOptionPane.showMessageDialog(null, "Brak konwersji sygnau.", "Bd", JOptionPane.ERROR_MESSAGE); } } } catch (Exception exc_MSE) { // JOptionPane.showMessageDialog(null, "Nie mona obliczy:\n" + exc_MSE.getMessage(), // "Bd", JOptionPane.ERROR_MESSAGE); wynik = -1; } System.out.println("SNR = " + wynik); return wynik; }
From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java
public void onClickSearch(View view) { final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null); final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText); final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup); new AlertDialog.Builder(EditFeedActivity.this) // .setIcon(R.drawable.action_search) // .setTitle(R.string.feed_search) // .setView(dialogView) // .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() { @Override// w w w . ja v a 2 s .co m public void onClick(DialogInterface dialog, int which) { if (searchText.getText().length() > 0) { String tmp = searchText.getText().toString(); try { tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } final String text = tmp; switch (radioGroup.getCheckedRadioButtonId()) { case R.id.byWebSearch: final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this); pd.setMessage(getString(R.string.loading)); pd.setCancelable(true); pd.setIndeterminate(true); pd.show(); getLoaderManager().restartLoader(1, null, new LoaderCallbacks<ArrayList<HashMap<String, String>>>() { @Override public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) { return new GetFeedSearchResultsLoader(EditFeedActivity.this, text); } @Override public void onLoadFinished( Loader<ArrayList<HashMap<String, String>>> loader, final ArrayList<HashMap<String, String>> data) { pd.cancel(); if (data == null) { Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show(); } else if (data.isEmpty()) { Toast.makeText(EditFeedActivity.this, R.string.no_result, Toast.LENGTH_SHORT).show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder( EditFeedActivity.this); builder.setTitle(R.string.feed_search); // create the grid item mapping String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC }; int[] to = new int[] { android.R.id.text1, android.R.id.text2 }; // fill in the grid_item layout SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data, R.layout.item_search_result, from, to); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mNameEditText.setText( data.get(which).get(FEED_SEARCH_TITLE)); mUrlEditText.setText( data.get(which).get(FEED_SEARCH_URL)); } }); builder.show(); } } @Override public void onLoaderReset( Loader<ArrayList<HashMap<String, String>>> loader) { } }).forceLoad(); break; case R.id.byTopic: mUrlEditText.setText("http://www.faroo.com/api?q=" + text + "&start=1&length=10&l=en&src=news&f=rss"); break; case R.id.byYoutube: mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "") + "/videos.rss"); break; } } } }).setNegativeButton(android.R.string.cancel, null).show(); }
From source file:org.squale.squaleweb.applicationlayer.action.IndexAction.java
/** * Action to do if the audit part is present in the homepage * /*w w w.ja v a 2 s . c om*/ * @param request The http request * @param form The form * @param compoList The list of HomepageComponent of the user * @throws JrafEnterpriseException Exception happen during the action */ private void audit(HttpServletRequest request, HashMap<String, HomepageComponentDTO> compoList, ActionForm form) throws JrafEnterpriseException { try { // List of the applications for which the current user is define as manager or reader ArrayList<ApplicationForm> applications = (ArrayList<ApplicationForm>) getUserNotPublicApplicationList( request); // If the list of application is not empty if (!applications.isEmpty()) { // Transform the list of applicationForm contain inside an applicationListForm into a list of // componentDTO ApplicationListForm appliForm = new ApplicationListForm(); appliForm.setList(applications); ArrayList<ComponentDTO> userApplicationsDTO = (ArrayList<ComponentDTO>) WTransformerFactory .formToObj(ApplicationListTransformer.class, appliForm)[0]; // The limit date for the search the audits Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -nbJours); // Definition of the list of excluded status. That means it's the list of the status of audits to not // display ArrayList<Integer> statusId = new ArrayList<Integer>(); statusId.add(AuditBO.DELETED); // Modify the list statusId according to what should be show for the audit done statudIdForAuditDone(statusId); // if auditDone and auditScheduled should be show separately, then a second audit collection is needed Collection separateAudits = new ArrayList(); // ApplicationComponent for "component" IApplicationComponent ac = AccessDelegateHelper.getInstance("Component"); // If auditDone and auditScheduled should be show separately if (isDisplayAuditDone && isDisplayAuditScheduled && isDisplaySeparately) { separateAudits = auditShowSeparetely(statusId, userApplicationsDTO, cal, ac); } // If auditDone and auditScheduled shouldn't be show separately else { // if the scheduled audits shouldn't be displayed if (!isDisplayAuditScheduled) { statusId.add(AuditBO.NOT_ATTEMPTED); } } // Creation of the first audit collection Integer[] status = new Integer[statusId.size()]; statusId.toArray(status); Object[] paramIn = { userApplicationsDTO, cal.getTime(), status }; Collection audits = (Collection) ac.execute("getAllAuditsAfterDate", paramIn); // Transform object to form SplitAuditsListForm temporaryForm = new SplitAuditsListForm(); WTransformerFactory.objToForm(SplitAuditsListTransformer.class, (WActionForm) temporaryForm, separateAudits, audits); HomepageForm currentForm = (HomepageForm) form; currentForm.setAudits(temporaryForm.getAudits()); currentForm.setScheduledAudits(temporaryForm.getPublicAudits()); } } catch (WTransformerException e) { throw new JrafEnterpriseException("WTransformerException", e); } }