List of usage examples for java.lang Integer compareTo
public int compareTo(Integer anotherInteger)
From source file:org.intermine.bio.dataconversion.SgdGffUtrConverter.java
private String getLength(String start, String end) throws NumberFormatException { Integer a = new Integer(start); Integer b = new Integer(end); // if the coordinates are on the crick strand, they need to be reversed // or they result in a negative number if (a.compareTo(b) > 0) { a = new Integer(end); b = new Integer(start); }/* www .j a v a 2 s .c o m*/ Integer length = new Integer(b.intValue() - a.intValue()); return length.toString(); }
From source file:org.sakaiproject.importer.impl.handlers.SamigoAssessmentHandler.java
public void handle(Importable thing, String siteId) { Assessment importAssessment = (Assessment) thing; AssessmentFacade assessment = null;//from ww w . j av a 2s. c o m try { assessment = as.createAssessmentWithoutDefaultSection(importAssessment.getTitle(), importAssessment.getDescription(), SamigoAssessmentHandler.QUIZ_TYPE, SamigoAssessmentHandler.QUIZ_TEMPLATE, siteId); AssessmentData data = new AssessmentData(new Long(SamigoAssessmentHandler.QUIZ_TEMPLATE), importAssessment.getTitle(), new Date()); data.setTypeId(new Long(SamigoAssessmentHandler.QUIZ_TYPE)); data.setTitle(importAssessment.getTitle()); data.setDescription(importAssessment.getDescription()); data.setAssessmentTemplateId(new Long(SamigoAssessmentHandler.QUIZ_TEMPLATE)); data.setCreatedBy(SessionManager.getCurrentSessionUserId()); data.setLastModifiedBy(SessionManager.getCurrentSessionUserId()); data.setLastModifiedDate(new Date()); // have no idea what the magic number 30 is for, but Samigo used it when I created a question pool in the tool data.setStatus(Integer.valueOf(1)); data.setIsTemplate(Boolean.valueOf(false)); data.setCreatedDate(new Date()); Set questionItems = new HashSet(); questionItems.addAll(doQuestions(importAssessment.getEssayQuestions(), siteId)); questionItems.addAll(doQuestions(importAssessment.getFillBlankQuestions(), siteId)); questionItems.addAll(doQuestions(importAssessment.getMatchQuestions(), siteId)); questionItems.addAll(doQuestions(importAssessment.getMultiAnswerQuestions(), siteId)); questionItems.addAll(doQuestions(importAssessment.getMultiChoiceQuestions(), siteId)); // Samigo doesn't have native support for ordering questions. Maybe there's a workaround? // questionItems.addAll(doQuestions(importPool.getOrderingQuestions())); questionItems.addAll(doQuestions(importAssessment.getTrueFalseQuestions(), siteId)); Set sectionSet = new HashSet(); SectionFacade section = new SectionFacade(); section.setTypeId(Long.valueOf(21)); section.setCreatedBy(SessionManager.getCurrentSessionUserId()); section.setCreatedDate(new Date()); section.setLastModifiedBy(SessionManager.getCurrentSessionUserId()); section.setLastModifiedDate(new Date()); section.setStatus(Integer.valueOf(1)); section.setSequence(Integer.valueOf(1)); section.setAssessmentId(assessment.getAssessmentId()); section.setAssessment(assessment); as.saveOrUpdateSection(section); Object[] questionItemsArray = questionItems.toArray(); Arrays.sort(questionItemsArray, new Comparator() { public int compare(Object o1, Object o2) { Integer i1 = ((ItemFacade) o1).getSequence(); Integer i2 = ((ItemFacade) o2).getSequence(); return i1.compareTo(i2); } }); for (int i = 0; i < questionItemsArray.length; i++) { ItemFacade item = (ItemFacade) questionItemsArray[i]; item.setSequence(Integer.valueOf(i + 1)); item.setSection(section); section.addItem(itemService.saveItem(item)); } data.setSectionSet(sectionSet); assessment.setData(data); assessment.setSectionSet(sectionSet); as.saveAssessment(assessment); } catch (Exception e) { // error creating this assessment e.printStackTrace(); } catch (AssessmentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.diversityarrays.dalclient.DalUtil.java
/** * Compare two version number strings and return * -1, 0, 1 if <code>a</code> is respectively less-than, equal to * or greater-than <code>b</code>. * @param a/*from ww w .j av a 2s .c o m*/ * @param b * @return -1, 0 or 1 */ static public int compareVersions(String a, String b) { Pattern pattern = Pattern.compile("^([0-9]+)"); //$NON-NLS-1$ StringTokenizer st_a = new StringTokenizer(a, "."); //$NON-NLS-1$ StringTokenizer st_b = new StringTokenizer(b, "."); //$NON-NLS-1$ while (st_a.hasMoreTokens() && st_b.hasMoreTokens()) { Matcher m = pattern.matcher(st_a.nextToken()); Integer anum = 0; if (m.matches()) { anum = new Integer(m.group(1)); } Integer bnum = 0; m = pattern.matcher(st_b.nextToken()); if (m.matches()) { bnum = new Integer(m.group(1)); } int result = anum.compareTo(bnum); if (result != 0) { return result; } } if (st_a.hasMoreTokens()) { // well then b doesn't return +1; } if (st_b.hasMoreTokens()) { return -1; } return 0; }
From source file:org.lockss.exporter.biblio.BibliographicUtil.java
/** * Compare two strings which are supposed to be representations of years. * Returns less than 0 if the first is less than the second, greater than 0 if * the first is greater than the second, and 0 if they are the same. If the * strings cannot be parsed the default NumberFormatException is propagated to * the caller./*w w w . ja v a 2s.co m*/ * * @param year1 a string representing a year * @param year2 a string representing a year * @return the value 0 if the years are the same; less than 0 if the first is less than the second; and greater than 0 if the first is greater than the second * @throws NumberFormatException if either of the strings does not parse as an integer * @deprecated no longer useful */ public static int compareStringYears(String year1, String year2) throws NumberFormatException { // Note that in practise if the strings do represent comparable publication years, // they should be 4 digits long and so comparable as strings with the same results. // Return zero if the strings are equal if (year1.equals(year2)) return 0; Integer i1 = NumberUtil.parseInt(year1); Integer i2 = NumberUtil.parseInt(year2); return i1.compareTo(i2); }
From source file:com.cloud.test.regression.ApiCommand.java
public static boolean verifyEvents(HashMap<String, Integer> expectedEvents, String level, String host, String parameters) {//from w w w . j a v a 2 s .co m boolean result = false; HashMap<String, Integer> actualEvents = new HashMap<String, Integer>(); try { // get actual events String url = host + "/?command=listEvents&" + parameters; HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); int responseCode = client.executeMethod(method); if (responseCode == 200) { InputStream is = method.getResponseBodyAsStream(); ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(is, new String[] { "event" }); for (int i = 0; i < eventValues.size(); i++) { HashMap<String, String> element = eventValues.get(i); if (element.get("level").equals(level)) { if (actualEvents.containsKey(element.get("type")) == true) { actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1); } else { actualEvents.put(element.get("type"), 1); } } } } method.releaseConnection(); } catch (Exception ex) { s_logger.error(ex); } // compare actual events with expected events Iterator<?> iterator = expectedEvents.keySet().iterator(); Integer expected; Integer actual; int fail = 0; while (iterator.hasNext()) { expected = null; actual = null; String type = iterator.next().toString(); expected = expectedEvents.get(type); actual = actualEvents.get(type); if (actual == null) { s_logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " + expected); fail++; } else if (expected.compareTo(actual) != 0) { fail++; s_logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected + ", actual number is " + actual); } } if (fail == 0) { result = true; } return result; }
From source file:managers.nodes.CombinationGroupManager.java
private Promise<List<List<String>>> getStringsBySlots(JsonNode properties) { Promise<List<JsonNode>> slots = slots(properties); Promise<List<List<JsonNode>>> partsBySlots = slots .flatMap(new Function<List<JsonNode>, Promise<List<List<JsonNode>>>>() { public Promise<List<List<JsonNode>>> apply(List<JsonNode> slots) { Collections.sort(slots, new Comparator<JsonNode>() { public int compare(JsonNode s1, JsonNode s2) { Integer pos1 = s1.get("position").asInt(); Integer pos2 = s2.get("position").asInt(); return pos1.compareTo(pos2); }//from w w w. j a va 2s . c o m }); List<Promise<? extends List<JsonNode>>> partsBySlots = new ArrayList<Promise<? extends List<JsonNode>>>(); for (JsonNode slot : slots) { partsBySlots.add(Slot.nodes.parts(slot)); } return Promise.sequence(partsBySlots); } }); Promise<List<List<String>>> stringsBySlots = partsBySlots .map(new Function<List<List<JsonNode>>, List<List<String>>>() { public List<List<String>> apply(List<List<JsonNode>> partsBySlots) { List<List<String>> stringsBySlots = new ArrayList<List<String>>(); for (List<JsonNode> partsBySlot : partsBySlots) { List<String> stringsBySlot = new ArrayList<String>(); for (JsonNode part : partsBySlot) { stringsBySlot.add(part.get("content").asText()); } stringsBySlots.add(stringsBySlot); } return stringsBySlots; } }); return stringsBySlots; }
From source file:org.sakaiproject.tool.assessment.ui.listener.author.ReorderQuestionsListener.java
/** ** shift sequence number down when inserting or reordering **//*ww w. j av a 2s .com*/ private void reorderSequences(SectionFacade sectfacade, Integer oldPos, Integer newPos) { ItemService delegate = new ItemService(); Set itemset = sectfacade.getItemFacadeSet(); Iterator iter = itemset.iterator(); while (iter.hasNext()) { ItemFacade itemfacade = (ItemFacade) iter.next(); Integer itemfacadeseq = itemfacade.getSequence(); if ((oldPos.compareTo(newPos) < 0) && (itemfacadeseq.compareTo(oldPos) > 0) && (itemfacadeseq.compareTo(newPos) <= 0)) { itemfacade.setSequence(Integer.valueOf(itemfacadeseq.intValue() - 1)); delegate.saveItem(itemfacade); } if ((oldPos.compareTo(newPos) > 0) && (itemfacadeseq.compareTo(newPos) >= 0) && (itemfacadeseq.compareTo(oldPos) < 0)) { itemfacade.setSequence(Integer.valueOf(itemfacadeseq.intValue() + 1)); delegate.saveItem(itemfacade); } if (itemfacadeseq.compareTo(oldPos) == 0) { itemfacade.setSequence(newPos); delegate.saveItem(itemfacade); } } }
From source file:ubic.gemma.loader.protein.string.StringProteinProteinInteractionFileParser.java
/** * Typical line of string file is of the following format: * //from ww w . j a va 2s.co m * <pre> * 882.DVU0001 882.DVU0002 707 0 0 0 0 0 172 742 * </pre> * * 882.DVU0001 and 882.DVU0002 refer to protein 1 and protein2 Note the 882 is the ncbi taxon id, the other part is * an external id (ensembl). Method takes the array representing a line of string file and creates a * StringProteinProteinInteraction object. * * @param fields Line split on delimiter * @return StringProteinProteinInteraction value object. */ public StringProteinProteinInteraction createStringProteinProteinInteraction(String[] fields) { // validate if (fields == null) { return null; } if (fields[0] == null || fields[1] == null || fields[0].isEmpty() || fields[1].isEmpty()) { return null; } String[] protein1AndTaxa = StringUtils.split(fields[0], "."); int taxonIdProtein1 = Integer.parseInt(protein1AndTaxa[0]); String[] protein2AndTaxa = StringUtils.split(fields[1], "."); int taxonIdProtein2 = Integer.parseInt(protein2AndTaxa[0]); // Check that the two proteins taxa match that is the taxon appended to protein name match if (taxonIdProtein1 != taxonIdProtein2) { throw new FileFormatException( "Protein 1 " + fields[0] + " protein 2 " + fields[1] + " do not contain matching taxons"); } // taxon not supported skip it if (!(getNcbiValidTaxon()).contains(taxonIdProtein1)) { return null; } // always ensure that protein 1 and protein 2 are set same alphabetical order makes matching much easier later // hashcode equality method relies on them being in consistent order. // use hashcode as mixed alphanumeric code Integer protein1Infile = Integer.valueOf(fields[0].hashCode()); Integer protein2InFile = Integer.valueOf(fields[1].hashCode()); StringProteinProteinInteraction stringProteinProteinInteraction = null; if (protein1Infile.compareTo(protein2InFile) < 0) { stringProteinProteinInteraction = new StringProteinProteinInteraction(fields[0], fields[1]); } else { stringProteinProteinInteraction = new StringProteinProteinInteraction(fields[1], fields[0]); } stringProteinProteinInteraction.setNcbiTaxonId(taxonIdProtein1); // validate the line make sure these fields are numeric for (int i = 2; i < fields.length; i++) { if (!StringUtils.isNumeric(fields[i])) { throw new FileFormatException("This line does not contain valid number "); } } stringProteinProteinInteraction.addEvidenceCodeScoreToMap( StringProteinInteractionEvidenceCodeEnum.NEIGHBORHOOD, Integer.valueOf(fields[2])); stringProteinProteinInteraction.addEvidenceCodeScoreToMap( StringProteinInteractionEvidenceCodeEnum.GENEFUSION, Integer.valueOf(fields[3])); stringProteinProteinInteraction.addEvidenceCodeScoreToMap( StringProteinInteractionEvidenceCodeEnum.COOCCURENCE, Integer.valueOf(fields[4])); stringProteinProteinInteraction.addEvidenceCodeScoreToMap( StringProteinInteractionEvidenceCodeEnum.COEXPRESSION, Integer.valueOf(fields[5])); stringProteinProteinInteraction.addEvidenceCodeScoreToMap( StringProteinInteractionEvidenceCodeEnum.EXPERIMENTAL, Integer.valueOf(fields[6])); stringProteinProteinInteraction.addEvidenceCodeScoreToMap(StringProteinInteractionEvidenceCodeEnum.DATABASE, Integer.valueOf(fields[7])); stringProteinProteinInteraction.addEvidenceCodeScoreToMap( StringProteinInteractionEvidenceCodeEnum.TEXTMINING, Integer.valueOf(fields[8])); stringProteinProteinInteraction.setCombined_score(Double.valueOf(fields[9])); return stringProteinProteinInteraction; }
From source file:com.sapienter.jbilling.server.process.AgeingBL.java
/** * Give a current step, finds the next one. If there's none next, then * it returns null. The current step can be missing (for the case that * it has been deleted by the admin).//ww w . j a v a 2 s . com * @param entity * @param statusId * @return * @throws SessionInternalError */ private Integer getNextStep(CompanyDTO entity, Integer statusId) throws SessionInternalError { // this will return the next step, even if statusId doesn // exists in the current set of steps. // The steps are returned order by status id. for (AgeingEntityStepDTO step : entity.getAgeingEntitySteps()) { Integer stepId = step.getUserStatus().getId(); if (stepId.compareTo(statusId) > 0) { return stepId; } } return null; }
From source file:org.opentaps.common.reporting.ChartViewHandler.java
/** * Encode chart as image/png and send it to browser * * @param chartContext/* w ww. j a va2s . c o m*/ * @param response * @throws IOException */ protected void sendChart(Map<String, Object> chartContext, HttpServletResponse response) throws IOException { JFreeChart chartObject = (JFreeChart) chartContext.get("chartObject"); Integer width = (Integer) chartContext.get("width"); Integer height = (Integer) chartContext.get("height"); Boolean encodeAlpha = (Boolean) chartContext.get("alphaCompression"); Integer compressRatio = (Integer) chartContext.get("compressRatio"); if (chartObject != null && width.compareTo(0) > 0 && height.compareTo(0) > 0) { response.setContentType("image/png"); if (encodeAlpha != null || (compressRatio != null && compressRatio.intValue() >= 0 && compressRatio.intValue() <= 9)) { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chartObject, width, height, encodeAlpha.booleanValue(), compressRatio.intValue()); } else { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chartObject, width, height); } } }