List of usage examples for java.lang Integer compareTo
public int compareTo(Integer anotherInteger)
From source file:com.espertech.esper.core.deploy.EPDeploymentAdminImpl.java
public synchronized DeploymentOrder getDeploymentOrder(Collection<Module> modules, DeploymentOrderOptions options) throws DeploymentOrderException { if (options == null) { options = new DeploymentOrderOptions(); }/*from w w w . j a va 2s. co m*/ String[] deployments = deploymentStateService.getDeployments(); List<Module> proposedModules = new ArrayList<Module>(); proposedModules.addAll(modules); Set<String> availableModuleNames = new HashSet<String>(); for (Module proposedModule : proposedModules) { if (proposedModule.getName() != null) { availableModuleNames.add(proposedModule.getName()); } } // Collect all uses-dependencies of existing modules Map<String, Set<String>> usesPerModuleName = new HashMap<String, Set<String>>(); for (String deployment : deployments) { DeploymentInformation info = deploymentStateService.getDeployment(deployment); if (info == null) { continue; } if ((info.getModule().getName() == null) || (info.getModule().getUses() == null)) { continue; } Set<String> usesSet = usesPerModuleName.get(info.getModule().getName()); if (usesSet == null) { usesSet = new HashSet<String>(); usesPerModuleName.put(info.getModule().getName(), usesSet); } usesSet.addAll(info.getModule().getUses()); } // Collect uses-dependencies of proposed modules for (Module proposedModule : proposedModules) { // check uses-dependency is available if (options.isCheckUses()) { if (proposedModule.getUses() != null) { for (String uses : proposedModule.getUses()) { if (availableModuleNames.contains(uses)) { continue; } if (isDeployed(uses)) { continue; } String message = "Module-dependency not found"; if (proposedModule.getName() != null) { message += " as declared by module '" + proposedModule.getName() + "'"; } message += " for uses-declaration '" + uses + "'"; throw new DeploymentOrderException(message); } } } if ((proposedModule.getName() == null) || (proposedModule.getUses() == null)) { continue; } Set<String> usesSet = usesPerModuleName.get(proposedModule.getName()); if (usesSet == null) { usesSet = new HashSet<String>(); usesPerModuleName.put(proposedModule.getName(), usesSet); } usesSet.addAll(proposedModule.getUses()); } Map<String, SortedSet<Integer>> proposedModuleNames = new HashMap<String, SortedSet<Integer>>(); int count = 0; for (Module proposedModule : proposedModules) { SortedSet<Integer> moduleNumbers = proposedModuleNames.get(proposedModule.getName()); if (moduleNumbers == null) { moduleNumbers = new TreeSet<Integer>(); proposedModuleNames.put(proposedModule.getName(), moduleNumbers); } moduleNumbers.add(count); count++; } DependencyGraph graph = new DependencyGraph(proposedModules.size(), false); int fromModule = 0; for (Module proposedModule : proposedModules) { if ((proposedModule.getUses() == null) || (proposedModule.getUses().isEmpty())) { fromModule++; continue; } SortedSet<Integer> dependentModuleNumbers = new TreeSet<Integer>(); for (String use : proposedModule.getUses()) { SortedSet<Integer> moduleNumbers = proposedModuleNames.get(use); if (moduleNumbers == null) { continue; } dependentModuleNumbers.addAll(moduleNumbers); } dependentModuleNumbers.remove(fromModule); graph.addDependency(fromModule, dependentModuleNumbers); fromModule++; } if (options.isCheckCircularDependency()) { Stack<Integer> circular = graph.getFirstCircularDependency(); if (circular != null) { String message = ""; String delimiter = ""; for (int i : circular) { message += delimiter; message += "module '" + proposedModules.get(i).getName() + "'"; delimiter = " uses (depends on) "; } throw new DeploymentOrderException( "Circular dependency detected in module uses-relationships: " + message); } } List<Module> reverseDeployList = new ArrayList<Module>(); Set<Integer> ignoreList = new HashSet<Integer>(); while (ignoreList.size() < proposedModules.size()) { // seconardy sort according to the order of listing Set<Integer> rootNodes = new TreeSet<Integer>(new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { return -1 * o1.compareTo(o2); } }); rootNodes.addAll(graph.getRootNodes(ignoreList)); if (rootNodes.isEmpty()) { // circular dependency could cause this for (int i = 0; i < proposedModules.size(); i++) { if (!ignoreList.contains(i)) { rootNodes.add(i); break; } } } for (Integer root : rootNodes) { ignoreList.add(root); reverseDeployList.add(proposedModules.get(root)); } } Collections.reverse(reverseDeployList); return new DeploymentOrder(reverseDeployList); }
From source file:com.ephesoft.dcma.workflow.service.common.DeploymentServiceImpl.java
private void sortBatchClassModulesListByOrderNumber(List<BatchClassModule> batchClassModulesList) { Collections.sort(batchClassModulesList, new Comparator<BatchClassModule>() { @Override/* ww w . j ava 2s .c o m*/ public int compare(BatchClassModule batchClassModule1, BatchClassModule batchClassModule2) { int result; Integer orderNumberOne = batchClassModule1.getOrderNumber(); Integer orderNumberTwo = batchClassModule2.getOrderNumber(); if (orderNumberOne != null && orderNumberTwo != null) { result = orderNumberOne.compareTo(orderNumberTwo); } else if (orderNumberOne == null && orderNumberTwo == null) { result = 0; } else if (orderNumberOne == null) { result = -1; } else { result = 1; } return result; } }); }
From source file:com.ephesoft.dcma.workflow.service.common.DeploymentServiceImpl.java
private void sortBatchClassPluginsListByOrderNumber(List<BatchClassPlugin> batchClassPluginsList) { Collections.sort(batchClassPluginsList, new Comparator<BatchClassPlugin>() { @Override//from ww w . j a va 2 s . co m public int compare(BatchClassPlugin batchClassPlugin1, BatchClassPlugin batchClassPlugin2) { int result; Integer orderNumberOne = batchClassPlugin1.getOrderNumber(); Integer orderNumberTwo = batchClassPlugin2.getOrderNumber(); if (orderNumberOne != null && orderNumberTwo != null) { result = orderNumberOne.compareTo(orderNumberTwo); } else if (orderNumberOne == null && orderNumberTwo == null) { result = 0; } else if (orderNumberOne == null) { result = -1; } else { result = 1; } return result; } }); }
From source file:org.akaza.openclinica.bean.extract.odm.ClinicalDataReportBean.java
@SuppressWarnings("unchecked") private void sortImportItemGroupDataBeanList(ArrayList<ImportItemGroupDataBean> igs) { Collections.sort(igs, new Comparator() { public int compare(Object o1, Object o2) { String x1 = ((ImportItemGroupDataBean) o1).getItemGroupOID(); String x2 = ((ImportItemGroupDataBean) o2).getItemGroupOID(); int sComp = x1.compareTo(x2); if (sComp != 0) { return sComp; } else { Integer i1 = Integer.valueOf(((ImportItemGroupDataBean) o1).getItemGroupRepeatKey()); Integer i2 = Integer.valueOf(((ImportItemGroupDataBean) o2).getItemGroupRepeatKey()); return i1.compareTo(i2); }//from w w w.j a va2s. c o m } }); }
From source file:org.kuali.rice.kns.web.struts.form.pojo.PojoFormBase.java
/** * Populates the form with values from the current request. Uses instances of Formatter to convert strings to the Java types of * the properties to which they are bound. Values that can't be converted are cached in a map of unconverted values. Returns an * ActionErrors containing ActionMessage instances for each conversion error that occured, if any. *//* w w w. j ava2 s. co m*/ @Override public void populate(HttpServletRequest request) { StopWatch watch = null; if (LOG.isDebugEnabled()) { watch = new StopWatch(); watch.start(); LOG.debug(WATCH_NAME + ": started"); } unconvertedValues.clear(); unknownKeys = new ArrayList(); addRequiredNonEditableProperties(); Map params = request.getParameterMap(); String contentType = request.getContentType(); String method = request.getMethod(); if ("POST".equalsIgnoreCase(method) && contentType != null && contentType.startsWith("multipart/form-data")) { Map fileElements = (HashMap) request.getAttribute(KRADConstants.UPLOADED_FILE_REQUEST_ATTRIBUTE_KEY); Enumeration names = Collections.enumeration(fileElements.keySet()); while (names.hasMoreElements()) { String name = (String) names.nextElement(); params.put(name, fileElements.get(name)); } } postprocessRequestParameters(params); /** * Iterate through request parameters, if parameter matches a form variable, get the property type, formatter and convert, * if not add to the unknowKeys map. */ Comparator<String> nestedPathComparator = new Comparator<String>() { public int compare(String prop1, String prop2) { Integer i1 = new Integer(prop1.split("\\.").length); Integer i2 = new Integer(prop2.split("\\.").length); return (i1.compareTo(i2)); } }; List<String> pathKeyList = new ArrayList<String>(params.keySet()); Collections.sort(pathKeyList, nestedPathComparator); for (String keypath : pathKeyList) { if (shouldPropertyBePopulatedInForm(keypath, request)) { Object param = params.get(keypath); //LOG.debug("(keypath,paramType)=(" + keypath + "," + param.getClass().getName() + ")"); populateForProperty(keypath, param, params); } } this.registerIsNewForm(false); if (LOG.isDebugEnabled()) { watch.stop(); LOG.debug(WATCH_NAME + ": " + watch.toString()); } }
From source file:org.pentaho.di.core.util.StringEvaluator.java
public StringEvaluationResult getAdvicedResult() { if (evaluationResults.isEmpty()) { ValueMetaInterface adviced = new ValueMetaString("adviced"); adviced.setLength(maxLength);//from w w w . j a v a2s. c o m int nrNulls = 0; String min = null; String max = null; for (String string : values) { if (string != null) { if (min == null || min.compareTo(string) > 0) { min = string; } if (max == null || max.compareTo(string) < 0) { max = string; } } else { nrNulls++; } } StringEvaluationResult result = new StringEvaluationResult(adviced); result.setNrNull(nrNulls); result.setMin(min); result.setMax(max); return result; } else { // If there are Numbers and Integers, pick the integers... // if (containsInteger() && containsNumber()) { for (Iterator<StringEvaluationResult> iterator = evaluationResults.iterator(); iterator .hasNext();) { StringEvaluationResult result = iterator.next(); if (maxPrecision == 0 && result.getConversionMeta().isNumber()) { // no precision, don't bother with a number iterator.remove(); } else if (maxPrecision > 0 && result.getConversionMeta().isInteger()) { // precision is needed, can't use integer iterator.remove(); } } } // If there are Dates and Integers, pick the dates... // if (containsInteger() && containsDate()) { for (Iterator<StringEvaluationResult> iterator = evaluationResults.iterator(); iterator .hasNext();) { StringEvaluationResult result = iterator.next(); if (result.getConversionMeta().isInteger()) { iterator.remove(); } } } Comparator<StringEvaluationResult> compare = null; if (containsDate()) { // want the longest format for dates compare = new Comparator<StringEvaluationResult>() { @Override public int compare(StringEvaluationResult r1, StringEvaluationResult r2) { Integer length1 = r1.getConversionMeta().getConversionMask() == null ? 0 : r1.getConversionMeta().getConversionMask().length(); Integer length2 = r2.getConversionMeta().getConversionMask() == null ? 0 : r2.getConversionMeta().getConversionMask().length(); return length2.compareTo(length1); } }; } else { // want the shortest format mask for numerics & integers compare = new Comparator<StringEvaluationResult>() { @Override public int compare(StringEvaluationResult r1, StringEvaluationResult r2) { Integer length1 = r1.getConversionMeta().getConversionMask() == null ? 0 : r1.getConversionMeta().getConversionMask().length(); Integer length2 = r2.getConversionMeta().getConversionMask() == null ? 0 : r2.getConversionMeta().getConversionMask().length(); return length1.compareTo(length2); } }; } Collections.sort(evaluationResults, compare); StringEvaluationResult result = evaluationResults.get(0); ValueMetaInterface conversionMeta = result.getConversionMeta(); if (conversionMeta.isNumber() && conversionMeta.getCurrencySymbol() == null) { conversionMeta.setPrecision(maxPrecision); if (maxPrecision > 0 && maxLength > 0) { conversionMeta.setLength(maxLength); } } return result; } }
From source file:org.openmrs.module.ModuleFactory.java
/** * Returns all modules found/loaded into the system (started and not started), with the core * modules at the start of that list// ww w . j ava 2s .c o m * * @return <code>List<Module></code> of the modules loaded into the system, with the core * modules first. */ public static List<Module> getLoadedModulesCoreFirst() { List<Module> list = new ArrayList<Module>(getLoadedModules()); final Collection<String> coreModuleIds = ModuleConstants.CORE_MODULES.keySet(); Collections.sort(list, new Comparator<Module>() { @Override public int compare(Module left, Module right) { Integer leftVal = coreModuleIds.contains(left.getModuleId()) ? 0 : 1; Integer rightVal = coreModuleIds.contains(right.getModuleId()) ? 0 : 1; return leftVal.compareTo(rightVal); } }); return list; }
From source file:at.ac.tuwien.dsg.quelle.elasticityQuantification.engines.RequirementsMatchingEngine.java
private Set<RequirementsMatchingReport<Quality>> matchOptionalQualityConfiguration( List<Unit> optionalConfiguration, List<Requirement> requirementsToMatch) { //the results will be sorted after the nr of matched stuff Set<RequirementsMatchingReport<Quality>> matchedReportSet = new TreeSet<RequirementsMatchingReport<Quality>>( new Comparator<RequirementsMatchingReport>() { public int compare(RequirementsMatchingReport o1, RequirementsMatchingReport o2) { Integer matched1 = o1.getMatchedResourceCountForMetricType(Metric.MetricType.QUALITY); Integer matched2 = o2.getMatchedResourceCountForMetricType(Metric.MetricType.QUALITY); return -1 * matched1.compareTo(matched2); //multiplied by -1 to have the largest number first }/*from w w w .ja v a 2 s. c o m*/ }); //1 go trough each optional Resource and match their requirements for (Unit entity : optionalConfiguration) { if (!(entity instanceof Quality)) { continue; } else { Quality quality = (Quality) entity; Map<Metric, MetricValue> resourceProperties = quality.getProperties(); //match as many requirements to resource properties as possible List<Requirement> requirementsMatchedForThisResource = matchRequirementsToProperties( resourceProperties, requirementsToMatch); if (requirementsMatchedForThisResource.size() > 0) { //create the report entry Map<Metric.MetricType, List<Requirement>> matchedRequirementsMap = new EnumMap<Metric.MetricType, List<Requirement>>( Metric.MetricType.class); matchedRequirementsMap.put(Metric.MetricType.QUALITY, requirementsMatchedForThisResource); RequirementsMatchingReport<Quality> matchingReport = new RequirementsMatchingReport<Quality>( matchedRequirementsMap, quality); //add report entry to the report matchedReportSet.add(matchingReport); } } } return matchedReportSet; }
From source file:org.asqatasun.crawler.CrawlerImpl.java
/** * Some resources may have been downloaded by the crawler component but they * are not linked with any webresource. They have to be removed from the * contentList./* ww w . ja va 2s . co m*/ */ @SuppressWarnings("element-type-mismatch") private void removeOrphanContent() { List<Content> emptyContentSet; Integer nbOfContent = contentDataService.getNumberOfOrphanRelatedContent(mainWebResource).intValue(); Integer i = 0; Logger.getLogger(CrawlerImpl.class.getName()) .debug("remove Orphan related contents " + nbOfContent + " elements"); while (i.compareTo(nbOfContent) < 0) { emptyContentSet = contentDataService.getOrphanRelatedContentList(mainWebResource, 0, RETRIEVE_WINDOW); for (Content content : emptyContentSet) { Logger.getLogger(CrawlerImpl.class.getName()).debug("Removing " + content.getURI()); contentDataService.delete(content.getId()); } i = i + RETRIEVE_WINDOW; } nbOfContent = contentDataService.getNumberOfOrphanContent(mainWebResource).intValue(); i = 0; Logger.getLogger(CrawlerImpl.class.getName()).debug("remove Orphan SSPs " + nbOfContent + " elements"); while (i.compareTo(nbOfContent) < 0) { emptyContentSet = contentDataService.getOrphanContentList(mainWebResource, i, RETRIEVE_WINDOW); for (Content content : emptyContentSet) { contentDataService.delete(content.getId()); } i = i + RETRIEVE_WINDOW; } }
From source file:at.ac.tuwien.dsg.quelle.elasticityQuantification.engines.RequirementsMatchingEngine.java
/** * Does set cover to match any optional configuration. Sorts the optional * elements after the number of matched properties * * @param unit/*from w ww . j a va 2 s .c o m*/ * @param requirementsToMatch * @return */ private Set<RequirementsMatchingReport<Resource>> matchOptionalResourceConfiguration( List<Unit> optionalConfiguration, List<Requirement> requirementsToMatch) { //the results will be sorted after the nr of matched stuff Set<RequirementsMatchingReport<Resource>> matchedReportSet = new TreeSet<RequirementsMatchingReport<Resource>>( new Comparator<RequirementsMatchingReport>() { public int compare(RequirementsMatchingReport o1, RequirementsMatchingReport o2) { Integer matched1 = o1.getMatchedResourceCountForMetricType(Metric.MetricType.RESOURCE); Integer matched2 = o2.getMatchedResourceCountForMetricType(Metric.MetricType.RESOURCE); return -1 * matched1.compareTo(matched2); //multiplied by -1 to have the largest number first } }); //1 go trough each optional Resource and match their requirements for (Unit entity : optionalConfiguration) { if (!(entity instanceof Resource)) { continue; } else { Resource resource = (Resource) entity; Map<Metric, MetricValue> resourceProperties = resource.getProperties(); //match as many requirements to resource properties as possible List<Requirement> requirementsMatchedForThisResource = matchRequirementsToProperties( resourceProperties, requirementsToMatch); //create the report entry if (requirementsMatchedForThisResource.size() > 0) { Map<Metric.MetricType, List<Requirement>> matchedRequirementsMap = new EnumMap<Metric.MetricType, List<Requirement>>( Metric.MetricType.class); matchedRequirementsMap.put(Metric.MetricType.RESOURCE, requirementsMatchedForThisResource); RequirementsMatchingReport<Resource> matchingReport = new RequirementsMatchingReport<Resource>( matchedRequirementsMap, resource); //add report entry to the report matchedReportSet.add(matchingReport); } } } return matchedReportSet; }