List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:com.cloudera.oryx.ml.param.GridSearch.java
/** * @param ranges ranges of hyperparameters to try, one per hyperparameters * @param candidates minimum number of candidates to be built * @return smallest value such that picking that many values from each hyperparameter would result * in at least the requested minimum number of candidate combinations *//* w w w . j a v a 2 s . c o m*/ private static int chooseValuesPerHyperParam(List<? extends HyperParamValues<?>> ranges, int candidates) { if (ranges.isEmpty()) { return 0; } int valuesPerHyperParam = 0; long lastTotal; long total = 0; do { valuesPerHyperParam++; lastTotal = total; total = 1; for (HyperParamValues<?> range : ranges) { total *= Math.min(valuesPerHyperParam, range.getNumDistinctValues()); } // Keep going until values-per-hyperparam is enough to generate enough candidates, // but stop early if it won't increase anyway because there aren't enough distinct values } while (total < candidates && total > lastTotal); return valuesPerHyperParam; }
From source file:Main.java
/** * Checks the availability of the DownloadManager. * * @param context used to update the device version and DownloadManager information * @return true if the download manager is available *//* w w w .j av a 2 s . co m*/ public static boolean isDownloadManagerAvailable(Context context) { try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { return false; } Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList"); List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return !list.isEmpty(); } catch (Exception e) { return false; } }
From source file:com.vrem.util.EnumUtils.java
public static <T extends Enum> T find(@NonNull Class<T> enumType, @NonNull Predicate<T> predicate, @NonNull T defaultValue) {//from w w w . j a v a2 s. c o m List<T> results = new ArrayList<>(CollectionUtils.select(values(enumType), predicate)); return results.isEmpty() ? defaultValue : results.get(0); }
From source file:it.vige.greenarea.gtg.webservice.auth.LDAPauth.java
public static String doAuthentication(WebServiceContext wsContext) throws LDAPException { String result;//from w ww . ja va 2s . c o m MessageContext mctx = wsContext.getMessageContext(); Map<String, Object> http_headers = (Map) mctx.get(MessageContext.HTTP_REQUEST_HEADERS); List<Object> list = (List) http_headers.get("Authorization"); if (list == null || list.isEmpty()) { result = "Authentication failed! This WS needs BASIC Authentication!"; throw new LDAPException(ResultCode.AUTH_METHOD_NOT_SUPPORTED, result); } String userpass = (String) list.get(0); userpass = userpass.substring(5); byte[] buf = Base64.decodeBase64(userpass.getBytes());// decodeBase64(userpass.getBytes()); String credentials = StringUtils.newStringUtf8(buf); String username; String password; int p = credentials.indexOf(":"); if (p > -1) { username = credentials.substring(0, p); password = credentials.substring(p + 1); } else { result = "There was an error while decoding the Authentication!"; throw new LDAPException(ResultCode.DECODING_ERROR, result); } /* * Creazione di una "Identity" Se non mi serve un sottodominio, posso * anche usare il costruttore Identity(usr,pwd) */ logger.debug("*** LOG *** username: " + username + " pwd: " + password); logger.debug("*** LOG *** username: " + username + " AUTHORIZED!"); return username; }
From source file:Main.java
public static boolean isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return resolveInfo != null && !resolveInfo.isEmpty(); }
From source file:fr.wirth.web.service.SecurityService.java
private static List<GrantedAuthority> toGrantedAutorithy(List<Role> roles) { List<GrantedAuthority> res = new ArrayList<GrantedAuthority>(); if (roles != null && !roles.isEmpty()) { for (Role r : roles) { res.add(new SimpleGrantedAuthority(r.getName())); }/* www. j a v a 2 s . c o m*/ } return res; }
From source file:org.edgexfoundry.EdgeXConfigWatcherApplication.java
public static List<CatalogService> getApplicationServices(Consul consul) { List<CatalogService> services = consul.catalogClient().getService(serviceName).getResponse(); if (services.isEmpty()) { LOGGER.info("This service hasn't started up"); System.exit(0);//from ww w . j a v a 2 s .c o m } return services; }
From source file:Main.java
public static String param(String name, Container c) { List<JTextField> filter = new ArrayList<JTextField>(); searchFor(c, JTextField.class, filter, name.replaceAll("\\[", "\\[").replaceAll("\\]", "\\]")); return filter.isEmpty() ? null : filter.get(0).getText(); }
From source file:edu.usu.sdl.openstorefront.service.manager.ReportManager.java
public static void cleanup() { ServiceProxy serviceProxy = ServiceProxy.getProxy(); List<Report> allReports = getInprogessReports(); if (!allReports.isEmpty()) { log.log(Level.WARNING, MessageFormat.format( "Reports are currently in progress. Attempting to cancel and put back on queue. Reports in progress: {0}", allReports.size()));/* w w w .j ava 2 s. c om*/ List<TaskFuture> taskFutures = AsyncTaskManager.getTasksByName(TaskRequest.TASKNAME_REPORT); for (TaskFuture taskFuture : taskFutures) { String reportId = (String) taskFuture.getTaskData().get(TaskRequest.DATAKEY_REPORT_ID); if (StringUtils.isNotBlank(reportId)) { if (taskFuture.cancel(true)) { Report report = serviceProxy.getPersistenceService().findById(Report.class, reportId); report.setRunStatus(RunStatus.PENDING); report.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER); report.populateBaseUpdateFields(); serviceProxy.getPersistenceService().persist(report); } else { log.log(Level.WARNING, MessageFormat.format( "Unable to cancel report id: {0} it likely be in a fail state upon restart. It can be safely deleted.", reportId)); } } else { log.log(Level.WARNING, "Unable to find report id for a report task. Unable to cleanly cancel. Report can be clean up upon restart."); } } } }
From source file:examples.mail.IMAPImportMbox.java
/** * Is the message wanted?/*from ww w. j av a 2 s . com*/ * * @param msgNum the message number * @param line the From line * @param msgNums the list of wanted message numbers * @param contains the list of strings to be contained * @return true if the message is wanted */ private static boolean wanted(int msgNum, String line, BitSet msgNums, List<String> contains) { return (msgNums.isEmpty() && contains.isEmpty()) // no selectors || msgNums.get(msgNum) // matches message number || listContains(contains, line); // contains string }