List of usage examples for java.lang Integer compareTo
public int compareTo(Integer anotherInteger)
From source file:com.sonymobile.backlogtool.Theme.java
/** * Rebuilds the priority order of the children * in case one or more children were removed. *//*from w w w . j a v a2 s .c o m*/ public void rebuildChildrenOrder() { List<Epic> epicList = new ArrayList<Epic>(); epicList.addAll(children); Collections.sort(epicList, new Comparator<Epic>() { @Override public int compare(Epic epic1, Epic epic2) { Integer value1 = new Integer(epic1.getPrioInTheme()); Integer value2 = new Integer(epic2.getPrioInTheme()); return value1.compareTo(value2); } }); int prioCounter = 1; for (Epic epic : epicList) { epic.setPrioInTheme(prioCounter++); } }
From source file:whitelabel.cloud.webapp.impl.service.NewCloudServerService.java
/** * @param selectedHypervType/* w ww . jav a 2 s.c o m*/ * @param selectedTemplateProductId * @return */ public final NewCloudServer load() {//HypervisorTypes selectedHypervType, Integer selectedTemplateProductId) { AppVirtualDatacenter vdc = loadDatacenter(); VDCResourceBoundsConfig vdcConfig = UserUtil.getVDCResourceConfiguration(); NewCloudServer model = new NewCloudServer(); List<AppVLan> vlans = vdc.getVLans(); if (vlans != null && vlans.size() > 0) { model.setAvailableAppVLANs(vlans); } //Map<HypervisorTypes,HypervisorTypes> appHypervs = new HashMap<HypervisorTypes, HypervisorTypes>(); Map<String, HypervisorTypes> appHypervs = new HashMap<String, HypervisorTypes>(); AppHypervisor firstHyper = null; for (AppHypervisor rht : vdcConfig.getAllRegisteredHypervisors()) { appHypervs.put(rht.getHypervisorType().value(), rht.getHypervisorType()); if (firstHyper == null) { firstHyper = rht; } } model.setHypervisorTypes(appHypervs); // if (selectedHypervType == null) { model.setSelectedHypervisorType(firstHyper.getHypervisorType().value()); // } // else { // model.setSelectedHypervisorType(selectedHypervType.value()); // } Map<Long, String> templateOptions = new HashMap<Long, String>(); AppTemplateDetails firstTemplate = null; for (AppTemplateDetails osTemplate : vdcConfig.getTemplatesFor(model.getSelectedHypervisorType()) .values()) { templateOptions.put((long) osTemplate.getProductId(), osTemplate.getDescription()); if (firstTemplate == null) { firstTemplate = osTemplate; } } model.setTemplateList(templateOptions); // if (selectedTemplateProductId == null) { model.setSelectedTemplateProdId((long) firstTemplate.getProductId()); // } // else { // model.setSelectedTemplateProdId((long)selectedTemplateProductId); // } model.setAppCPUsBound(vdcConfig.getResourceBounds(model.getSelectedHypervisorType(), model.getSelectedTemplateProdId(), ResourceTypes.CPU)); model.setAppRAMsBound(vdcConfig.getResourceBounds(model.getSelectedHypervisorType(), model.getSelectedTemplateProdId(), ResourceTypes.RAM)); model.getAppHDxBound().put(0L, vdcConfig.getResourceBounds(model.getSelectedHypervisorType(), model.getSelectedTemplateProdId(), ResourceTypes.HARD_DISK_0)); model.getAppHDxBound().put(1L, vdcConfig.getResourceBounds(model.getSelectedHypervisorType(), model.getSelectedTemplateProdId(), ResourceTypes.HARD_DISK_1)); model.getAppHDxBound().put(2L, vdcConfig.getResourceBounds(model.getSelectedHypervisorType(), model.getSelectedTemplateProdId(), ResourceTypes.HARD_DISK_2)); model.getAppHDxBound().put(3L, vdcConfig.getResourceBounds(model.getSelectedHypervisorType(), model.getSelectedTemplateProdId(), ResourceTypes.HARD_DISK_3)); Integer def = model.getAppHDxBound().get(0L).getDefault(); if (def.compareTo(model.getSelectedDiskSize().get(0L)) > 0) { model.getSelectedDiskSize().put(0L, def); } return model; }
From source file:com.katropine.services.CustomUserDetailsService.java
public Collection<? extends GrantedAuthority> getAuthorities(Integer access) { // List<GrantedAuthority> authList = getGrantedAuthorities(getRoles(access)); // return authList; List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2); if (access.compareTo(1) == 0) { authList.add(new SimpleGrantedAuthority("ROLE_ADMIN")); } else {// w ww. j a va 2 s . c o m authList.add(new SimpleGrantedAuthority("ROLE_USER")); } return authList; }
From source file:com.bitranger.parknshop.buyer.controller.MakeComment.java
@RequestMapping("/makeComment") public String makeComment(HttpServletRequest req, Integer psItemId, Integer scoreItem, Integer scoreShop, String content) {/*from w w w .j a va2 s. c o m*/ if (psItemId == null || scoreItem == null || scoreShop == null || content == null) return Utility.error("Parameter Not Enough"); if (scoreItem.compareTo(0) < 0 || scoreItem.compareTo(5) > 0 || scoreShop.compareTo(0) < 0 || scoreShop.compareTo(5) > 0) return Utility.error("Wrong Parameter."); PsCustomer currentCustomer = (PsCustomer) req.getSession().getAttribute("currentCustomer"); if (currentCustomer == null) { return Utility.error("User haven't logged in."); } PsItem psItem = psItemDao.findById(psItemId); if (psItem == null) return Utility.error("PsItem Incorrect."); PsComment psComment = new PsComment(); psComment.setContent(content); psComment.setScoreItem(scoreItem); psComment.setScoreShop(scoreShop); psComment.setPsItem(psItem); psComment.setTimeCreated(new Timestamp(System.currentTimeMillis())); psComment.setPsCustomer(currentCustomer); psCommentDao.save(psComment); return "success"; }
From source file:com.linkedin.pinot.core.data.readers.MultiplePinotSegmentRecordReaderTest.java
@Test public void testMultiplePinotSegmentRecordReaderSortedColumn() throws Exception { List<String> sortOrder = new ArrayList<>(); sortOrder.add(D_SV_1);/*from w w w. ja va 2s . c o m*/ sortOrder.add(D_SV_2); List<GenericRow> outputRows = new ArrayList<>(); try (MultiplePinotSegmentRecordReader pinotSegmentRecordReader = new MultiplePinotSegmentRecordReader( _segmentIndexDirList, null, sortOrder)) { while (pinotSegmentRecordReader.hasNext()) { outputRows.add(pinotSegmentRecordReader.next()); } } Assert.assertEquals(outputRows.size(), NUM_SEGMENTS * NUM_ROWS, "Number of rows returned by PinotSegmentRecordReader is incorrect"); GenericRow prev = outputRows.get(0); for (int i = 1; i < outputRows.size(); i++) { GenericRow current = outputRows.get(i); String prevValue = (String) prev.getValue(D_SV_1); String currentValue = (String) current.getValue(D_SV_1); Assert.assertTrue(prevValue.compareTo(currentValue) <= 0); // Check secondary order if (prevValue.equals(currentValue)) { Integer prevSecondValue = (Integer) prev.getValue(D_SV_2); Integer currentSecondValue = (Integer) current.getValue(D_SV_2); Assert.assertTrue(prevSecondValue.compareTo(currentSecondValue) <= 0); } prev = current; } }
From source file:org.kuali.rice.kew.actionrequest.ActionRequestValue.java
/** * Allows comparison of action requests to see which is greater responsibility. -1 : indicates code 1 is lesser responsibility than code 2 0 : indicates the same responsibility 1 : indicates code1 is greater responsibility than code 2 The priority of action requests is as follows: fyi < acknowledge < (approve == complete) * * @param code1/*from w w w . j a v a 2s .c o m*/ * @param code2 * @param completeAndApproveTheSame * @return -1 if less than, 0 if equal, 1 if greater than */ public static int compareActionCode(String code1, String code2, boolean completeAndApproveTheSame) { int cutoff = Integer.MAX_VALUE; if (completeAndApproveTheSame) { // hacked so that APPROVE and COMPLETE are equal cutoff = ACTION_CODE_RANK.length() - 3; } Integer code1Index = Math.min(ACTION_CODE_RANK.indexOf(code1), cutoff); Integer code2Index = Math.min(ACTION_CODE_RANK.indexOf(code2), cutoff); return code1Index.compareTo(code2Index); }
From source file:com.mmnaseri.dragonfly.runtime.session.impl.SessionPostProcessorHandler.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { final ArrayList<SessionPostProcessor> postProcessors = new ArrayList<SessionPostProcessor>( beanFactory.getBeansOfType(SessionPostProcessor.class, false, true).values()); Collections.sort(postProcessors, new Comparator<SessionPostProcessor>() { @Override/*from www . j a v a 2 s . co m*/ public int compare(SessionPostProcessor first, SessionPostProcessor second) { Integer firstOrder = first instanceof Ordered ? ((Ordered) first).getOrder() : 0; Integer secondOrder = second instanceof Ordered ? ((Ordered) second).getOrder() : 0; return firstOrder.compareTo(secondOrder); } }); long time = System.nanoTime(); for (SessionPostProcessor postProcessor : postProcessors) { if (postProcessor instanceof EntityContextAware) { ((EntityContextAware) postProcessor).setEntityContext(getEntityContext(beanFactory)); } if (postProcessor instanceof TableMetadataRegistryAware) { ((TableMetadataRegistryAware) postProcessor) .setTableMetadataRegistry(getTableMetadataRegistry(beanFactory)); } if (postProcessor instanceof StatementRegistryAware) { ((StatementRegistryAware) postProcessor).setStatementRegistry(getStatementRegistry(beanFactory)); } if (postProcessor instanceof DatabaseDialectAware) { ((DatabaseDialectAware) postProcessor).setDatabaseDialect(getDatabaseDialect(beanFactory)); } postProcessor.postProcessSession(beanFactory); } time = System.nanoTime() - time; log.info("Session preparation took " + Math.round((double) time / 1000000d) / 1000d + " second(s)"); }
From source file:org.jnode.net.ipv4.udp.UDPProtocol.java
/** * Register a datagram socket//w w w . ja v a 2s .c o m * * @param socket */ protected synchronized void bind(UDPDatagramSocketImpl socket) throws SocketException { Integer lport = new Integer(socket.getLocalPort()); if (lport.compareTo(zero) != 0 && sockets.containsKey(lport)) { throw new SocketException("Port already bound (" + lport + ")"); } else { Integer ran; while (lport.compareTo(zero) == 0) { ran = new Integer(random.nextInt(stopRandom) + startRandom); if (!sockets.containsKey(ran)) { // hmmm..... should we have one stop condition more?? lport = ran; socket.setLocalPort(lport.intValue()); } } sockets.put(lport, socket); } }
From source file:org.kuali.test.comparators.CheckpointPropertyComparator.java
@Override public int compare(CheckpointProperty o1, CheckpointProperty o2) { String g1 = o1.getPropertyGroup(); String g2 = o2.getPropertyGroup(); if (StringUtils.isBlank(g1)) { g1 = Constants.DEFAULT_HTML_PROPERTY_GROUP; }// ww w.jav a2 s . c o m if (StringUtils.isBlank(g2)) { g2 = Constants.DEFAULT_HTML_PROPERTY_GROUP; } int retval = g1.compareTo(g2); if (retval == 0) { String s1 = o1.getPropertySection(); String s2 = o2.getPropertySection(); if (StringUtils.isBlank(s1)) { s1 = Constants.DEFAULT_HTML_PROPERTY_SECTION; } if (StringUtils.isBlank(s2)) { s2 = Constants.DEFAULT_HTML_PROPERTY_SECTION; } // handle section names that end with index values enclosed in square brackets int pos1 = s1.indexOf("["); int pos2 = s1.indexOf("]"); int pos3 = s2.indexOf("["); int pos4 = s2.indexOf("]"); if ((pos1 > -1) && (pos2 > pos1) && (pos3 > -1) && (pos4 > pos3)) { retval = s1.substring(0, pos1).compareTo(s2.substring(0, pos3)); if (retval == 0) { try { Integer indx1 = Integer.valueOf(s1.substring(pos1 + 1, pos2).trim()); Integer indx2 = Integer.valueOf(s1.substring(pos3 + 1, pos4).trim()); retval = indx1.compareTo(indx2); } catch (NumberFormatException ex) { } ; } } else { retval = s1.compareTo(s2); } } if (retval == 0) { String s1 = ""; String s2 = ""; if (StringUtils.isNotBlank(o1.getPropertyName())) { s1 = o1.getPropertyName().toLowerCase(); } if (StringUtils.isNotBlank(o2.getPropertyName())) { s2 = o2.getPropertyName().toLowerCase(); } retval = s1.compareTo(s2); } return retval; }
From source file:com.sonymobile.backlogtool.Epic.java
/** * Rebuilds the priority order of the children * in case one or more children were removed. *///from w w w . j a v a 2 s . c om public void rebuildChildrenOrder() { List<Story> storyList = new ArrayList<Story>(); storyList.addAll(children); Collections.sort(storyList, new Comparator<Story>() { @Override public int compare(Story story1, Story story2) { Integer value1 = new Integer(story1.getPrioInEpic()); Integer value2 = new Integer(story2.getPrioInEpic()); return value1.compareTo(value2); } }); int prioCounter = 1; for (Story story : storyList) { story.setPrioInEpic(prioCounter++); } }