List of usage examples for org.apache.commons.collections4 MapUtils isEmpty
public static boolean isEmpty(final Map<?, ?> map)
From source file:com.ebay.myriad.scheduler.SchedulerUtils.java
public static boolean isMatchSlaveAttributes(Offer offer, Map<String, String> requestAttributes) { boolean match = true; Map<String, String> offerAttributes = new HashMap<String, String>(); for (Attribute attribute : offer.getAttributesList()) { offerAttributes.put(attribute.getName(), attribute.getText().getValue()); }/*from ww w .j a va 2 s . c o m*/ // Match with offer attributes only if request has attributes. if (!MapUtils.isEmpty(requestAttributes)) { match = offerAttributes.equals(requestAttributes); } LOGGER.info("Match status: {} for offer: {} and requestAttributes: {}", match, offer, requestAttributes); return match; }
From source file:com.sojw.ahnchangho.core.util.UriUtils.java
/** * Multi value map.// ww w . j a v a2 s . co m * * @param map the map * @return the multi value map */ public static MultiValueMap<String, String> multiValueMap(Map<String, String> map) { if (MapUtils.isEmpty(map)) { return null; } MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); for (Map.Entry<String, String> entry : map.entrySet()) { params.add(entry.getKey(), entry.getValue()); } return params; }
From source file:com.fredhopper.core.connector.index.generate.writer.ProductCsvWriter.java
@Override public void print(final FhProductData source) throws IOException { Preconditions.checkArgument(source != null); Preconditions.checkArgument(!MapUtils.isEmpty(source.getCategories())); final Map<Locale, Set<String>> categories = source.getCategories(); for (final Entry<Locale, Set<String>> entry : categories.entrySet()) { final Set<String> categoriesSet = source.getCategories().get(entry.getKey()); printLine(source.getProductId(), entry.getKey().toString(), buildCategoriesString(categoriesSet)); }/*from www . j a va 2 s .c o m*/ }
From source file:com.kumarvv.setl.utils.Interpolator.java
public String interpolate(final String str, final Map<String, Object> values) { if (str == null || MapUtils.isEmpty(values)) { return str; }// www. j a v a 2 s . c om String istr = str; for (String col : values.keySet()) { istr = interpolate(istr, Constants.COLON + col, values.get(col)); } return istr.trim(); }
From source file:com.sojw.ahnchangho.core.util.UriUtils.java
/** * Multi value map.// ww w .ja v a 2 s. c o m * * @param <T> the generic type * @param request the request * @return the string */ public static <T> MultiValueMap<String, String> multiValueMap(final T request) { if (request == null) { return null; } Map<String, Object> requestMap = JsonUtils.convertValue(request, new TypeReference<Map<String, Object>>() { }); if (MapUtils.isEmpty(requestMap)) { return null; } MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>(); for (Entry<String, Object> entry : requestMap.entrySet()) { if (entry.getValue() instanceof List) { ((List) entry.getValue()).forEach(each -> { parameters.add(entry.getKey(), each.toString()); }); } else { parameters.add(entry.getKey(), entry.getValue().toString()); } } return parameters; }
From source file:com.mirth.connect.server.api.servlets.DatabaseTaskServlet.java
@Override public DatabaseTask getDatabaseTask(String databaseTaskId) { Map<String, DatabaseTask> tasks; try {//w w w. j a v a 2 s . c o m tasks = databaseTaskController.getDatabaseTasks(); } catch (Exception e) { throw new MirthApiException(e); } if (MapUtils.isEmpty(tasks) || !tasks.containsKey(databaseTaskId)) { throw new MirthApiException(Status.NOT_FOUND); } return tasks.get(databaseTaskId); }
From source file:com.movies.jsf.JsfUtil.java
public static String getReturnUrl(String adress, Map<String, Object> parameterMap) { StringBuilder builder = new StringBuilder().append(adress); if (MapUtils.isEmpty(parameterMap)) { throw new IllegalArgumentException("Parameter map can not be empty!"); } else {/*www. j a v a 2s . c o m*/ Set<Entry<String, Object>> set = parameterMap.entrySet(); set.stream().forEach((entry) -> { builder.append(QUESTION).append(REDIRECT).append(AND).append(entry.getKey()).append(EQUALS) .append(entry.getValue()); }); } return builder.toString(); }
From source file:com.movies.bean.DirectorListBean.java
@Override public void searchPeople(ActionEvent event) { try {/*from www . jav a 2 s. c om*/ createParameterMap(); if (MapUtils.isEmpty(parameterMap)) { directors = directorService.getAllDirectorsWithMovies(); } else { directors = directorService.getDirectorsByCriteria(parameterMap); } } catch (Exception e) { e.printStackTrace(); JsfUtil.addErrorMessage("Error : " + e.getMessage()); } }
From source file:com.ebay.myriad.scheduler.Rebalancer.java
@Override public void run() { Map<String, Cluster> clusters = this.schedulerState.getClusters(); if (MapUtils.isEmpty(clusters)) { LOGGER.info("Nothing to rebalance, as there are no clusters registered"); return;//from w w w.j ava2s . co m } clusters.values().stream().forEach(cluster -> { String clusterId = cluster.getClusterId(); boolean acquireLock = this.schedulerState.acquireLock(clusterId); if (!acquireLock) { LOGGER.info("Rebalancer was unable to acquire lock for cluster {}", clusterId); return; } LOGGER.info("Analyzing cluster: {}", clusterId); String host = cluster.getResourceManagerHost(); String port = cluster.getResourceManagerPort(); double minQuota = cluster.getMinQuota(); RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://" + host + ":" + port) .setLogLevel(LogLevel.FULL).build(); YARNResourceManagerService service = restAdapter.create(YARNResourceManagerService.class); ClusterMetrics metrics = service.metrics().getClusterMetrics(); AppsResponse appsResponse = service.apps("ACCEPTED"); int acceptedApps = 0; if (appsResponse == null || appsResponse.getApps() == null || appsResponse.getApps().getApps() == null) { acceptedApps = 0; } else { acceptedApps = appsResponse.getApps().getApps().size(); } LOGGER.info("Metrics: {}", metrics); LOGGER.info("Apps: {}", appsResponse); long availableMB = metrics.getAvailableMB(); long allocatedMB = metrics.getAllocatedMB(); long reservedMB = metrics.getReservedMB(); int activeNodes = metrics.getActiveNodes(); int unhealthyNodes = metrics.getUnhealthyNodes(); int appsPending = metrics.getAppsPending(); int appsRunning = metrics.getAppsRunning(); if (activeNodes == 0 && appsPending > 0) { LOGGER.info("Flexing up for condition: activeNodes ({}) == 0 && appsPending ({}) > 0", activeNodes, appsPending); this.myriadOperations.flexUpCluster(clusterId, 1, "small"); } else if (appsPending == 0 && appsRunning == 0 && activeNodes > 0) { LOGGER.info( "Flexing down for condition: appsPending ({}) == 0 && appsRunning ({}) == 0 && activeNodes ({}) > 0", appsPending, appsRunning, activeNodes); this.myriadOperations.flexDownCluster(cluster, 1); } else if (acceptedApps > 0) { LOGGER.info("Flexing up for condition: acceptedApps ({}) > 0", acceptedApps); this.myriadOperations.flexUpCluster(clusterId, 1, "small"); } else { LOGGER.info("Nothing to rebalance"); this.schedulerState.releaseLock(clusterId); } }); }
From source file:io.cloudslang.lang.tools.build.tester.parse.TestCasesYamlParser.java
public Map<String, SlangTestCase> parseTestCases(SlangSource source) { if (StringUtils.isEmpty(source.getContent())) { loggingService.logEvent(Level.INFO, "No tests cases were found in: " + source.getName()); return new HashMap<>(); }/*w w w.jav a 2 s. co m*/ Validate.notEmpty(source.getContent(), "Source " + source.getName() + " cannot be empty"); try { @SuppressWarnings("unchecked") Map<String, Map> parsedTestCases = yaml.loadAs(source.getContent(), Map.class); if (MapUtils.isEmpty(parsedTestCases)) { loggingService.logEvent(Level.INFO, "No tests cases were found in: " + source.getName()); return new HashMap<>(); } return parseTestCases(parsedTestCases, source.getFilePath()); } catch (Throwable e) { throw new RuntimeException( "There was a problem parsing the YAML source: " + source.getName() + ".\n" + e.getMessage(), e); } }