List of usage examples for java.lang Comparable equals
public boolean equals(Object obj)
From source file:org.jfree.data.KeyToGroupMap.java
/** * Returns the number of keys mapped to the specified group. This method * won't always return an accurate result for the default group, since * explicit mappings are not required for this group. * * @param group the group (<code>null</code> not permitted). * * @return The key count.// w w w .java 2s .c o m */ public int getKeyCount(Comparable group) { ParamChecks.nullNotPermitted(group, "group"); int result = 0; Iterator iterator = this.keyToGroupMap.values().iterator(); while (iterator.hasNext()) { Comparable g = (Comparable) iterator.next(); if (group.equals(g)) { result++; } } return result; }
From source file:de.ingrid.iplug.excel.service.SheetsService.java
/** * Create sheets./*from ww w. j a v a 2 s. c om*/ * * @param inputStream * @return Created sheets. * @throws IOException */ public static Sheets createSheets(final InputStream inputStream) throws IOException { // sheets final Sheets sheets = new Sheets(); // create workbook final Workbook workbook = new HSSFWorkbook(inputStream); final FormulaEvaluator eval = new HSSFFormulaEvaluator((HSSFWorkbook) workbook); for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) { final org.apache.poi.ss.usermodel.Sheet poiSheet = workbook.getSheetAt(sheetNum); // ingrid sheet final Sheet sheet = new Sheet(); sheet.setSheetIndex(sheetNum); sheets.addSheet(sheet); final Values values = new Values(); sheet.setValues(values); for (final org.apache.poi.ss.usermodel.Row poiRow : poiSheet) { boolean hasValues = false; final Map<Point, Comparable<? extends Object>> valuesInCell = new HashMap<Point, Comparable<? extends Object>>(); for (final Cell poiCell : poiRow) { Comparable<? extends Object> value = null; switch (poiCell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: value = new Boolean(poiCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(poiCell)) { value = getFormattedDateString(poiCell); } else { value = new Double(poiCell.getNumericCellValue()); } break; case Cell.CELL_TYPE_STRING: value = poiCell.getStringCellValue(); break; case Cell.CELL_TYPE_FORMULA: value = calculateFormula(poiCell, eval); break; default: value = ""; break; } // trim strings if (value instanceof String) { value = ((String) value).trim(); } // only add if at least one value does exist in row if (!value.equals("")) { hasValues = true; // ingrid column if (sheet.getColumn(poiCell.getColumnIndex()) == null) { final Column column = new Column(poiCell.getColumnIndex()); sheet.addColumn(column); } } // ingrid point and value final Point point = new Point(poiCell.getColumnIndex(), poiCell.getRowIndex()); valuesInCell.put(point, value); } // ingrid row // ! only add if at least one value does exist if (hasValues) { final Row row = new Row(poiRow.getRowNum()); sheet.addRow(row); for (final Point point : valuesInCell.keySet()) { // if (sheet.getColumn(point.getX()) != null) { values.addValue(point, valuesInCell.get(point)); } } } } } return sheets; }
From source file:edu.dlnu.liuwenpeng.Time.TimeSeriesCollection.java
/** * Returns the series with the specified key, or <code>null</code> if * there is no such series. /*w ww . ja va2s . c om*/ * * @param key the series key (<code>null</code> permitted). * * @return The series with the given key. */ public TimeSeries getSeries(Comparable key) { TimeSeries result = null; Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { TimeSeries series = (TimeSeries) iterator.next(); Comparable k = series.getKey(); if (k != null && k.equals(key)) { result = series; } } return result; }
From source file:org.kuali.test.runner.execution.AbstractOperationExecution.java
/** * //from w w w .j a v a 2 s .c o m * @param testWrapper * @param cp * @return * @throws TestException */ protected boolean evaluateCheckpointProperty(KualiTestWrapper testWrapper, CheckpointProperty cp) throws TestException { boolean retval = false; try { Object comparisonValue = getComparisonValue(cp); ComparisonOperator.Enum comparisonOperator = cp.getOperator(); Object value = getValueForType(cp.getActualValue(), cp.getValueType()); if (ComparisonOperator.NULL.equals(cp.getOperator())) { retval = ((value == null) && (comparisonValue == null)); } else if ((value == null) || (comparisonValue == null)) { if (((cp.getOperator() == null) || ComparisonOperator.EQUAL_TO.equals(cp.getOperator())) && (value == null) && (comparisonValue == null)) { retval = true; } else { throw new TestException("input value is null, comparison value = " + comparisonValue, op, cp.getOnFailure()); } } else { ValueType.Enum type = cp.getValueType(); if (type == null) { type = ValueType.STRING; } ValueType.Enum inputType = getInputValueType(value); if (type.equals(inputType)) { if (ComparisonOperator.IN.equals(cp.getOperator()) && (comparisonValue instanceof List)) { Iterator<Comparable> it = ((List) comparisonValue).iterator(); while (it.hasNext()) { if (it.next().equals(value)) { retval = true; break; } } } else { if (ValueType.STRING.equals(type)) { String s1 = (String) comparisonValue; String s2 = (String) value; if (StringUtils.isNotBlank(s1)) { comparisonValue = s1.trim(); } if (StringUtils.isNotBlank(s2)) { value = s2.trim(); } } Comparable c1 = (Comparable) comparisonValue; Comparable c2 = (Comparable) value; switch (comparisonOperator.intValue()) { case ComparisonOperator.INT_EQUAL_TO: retval = c1.equals(c2); break; case ComparisonOperator.INT_GREATER_THAN: retval = (c1.compareTo(c2) < 0); break; case ComparisonOperator.INT_GREATER_THAN_OR_EQUAL: retval = (c1.compareTo(c2) <= 0); break; case ComparisonOperator.INT_LESS_THAN: retval = (c1.compareTo(c2) > 0); break; case ComparisonOperator.INT_LESS_THAN_OR_EQUAL: retval = (c1.compareTo(c2) >= 0); break; case ComparisonOperator.INT_BETWEEN: break; case ComparisonOperator.INT_NOT_NULL: retval = true; break; } } } else { throw new TestException("input type (" + inputType + ") comparison type (" + type + ") mismatch" + comparisonValue, op, cp.getOnFailure()); } } } catch (ParseException ex) { throw new TestException( "Exception occurred while parsing data for checkpoint comparison - " + ex.toString(), op, ex); } return retval; }
From source file:org.jfree.data.category.DefaultIntervalCategoryDataset.java
/** * Returns a series index./*from ww w . j av a2 s .c o m*/ * * @param seriesKey the series key. * * @return The series index. * * @see #getRowIndex(Comparable) * @see #getSeriesKey(int) */ public int getSeriesIndex(Comparable seriesKey) { int result = -1; for (int i = 0; i < this.seriesKeys.length; i++) { if (seriesKey.equals(this.seriesKeys[i])) { result = i; break; } } return result; }
From source file:org.jfree.data.category.DefaultIntervalCategoryDataset.java
/** * Returns the index for the given category. * * @param category the category (<code>null</code> not permitted). * * @return The index./*from ww w . j ava 2s . c o m*/ * * @see #getColumnIndex(Comparable) */ public int getCategoryIndex(Comparable category) { int result = -1; for (int i = 0; i < this.categoryKeys.length; i++) { if (category.equals(this.categoryKeys[i])) { result = i; break; } } return result; }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns a series from the collection. * * @param key the key (<code>null</code> not permitted). * * @return The series with the specified key. * * @throws UnknownKeyException if <code>key</code> is not found in the * collection.//from w ww .j av a2 s.c o m * * @since 1.0.9 */ public XYSeries getSeries(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { XYSeries series = (XYSeries) iterator.next(); if (key.equals(series.getKey())) { return series; } } throw new UnknownKeyException("Key not found: " + key); }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns the index of the series with the specified key, or -1 if no * series has that key./* ww w .j av a 2 s . c om*/ * * @param key the key (<code>null</code> not permitted). * * @return The index. * * @since 1.0.14 */ public int getSeriesIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { XYSeries series = (XYSeries) this.data.get(i); if (key.equals(series.getKey())) { return i; } } return -1; }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Returns the index of the series with the specified key, or -1 if no * series has that key./*w ww .ja v a 2s . c o m*/ * * @param key the key (<code>null</code> not permitted). * * @return The index. * * @since 1.0.17 */ public int getSeriesIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { TimeSeries series = (TimeSeries) this.data.get(i); if (key.equals(series.getKey())) { return i; } } return -1; }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private AbstractDataset getCategoryDataset(Report report) { List<Stat> reportData = report.getReportData(); // fill dataset DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String dataSource = report.getReportDefinition().getReportParams().getHowChartSource(); String categorySource = report.getReportDefinition().getReportParams().getHowChartCategorySource(); if (StatsManager.T_NONE.equals(categorySource)) { categorySource = null;// w w w. j av a 2 s . com } if (categorySource == null) { // without categories Set<Comparable> usedKeys = new HashSet<Comparable>(); for (Stat s : reportData) { Comparable key = getStatValue(s, dataSource); if (key != null) { if (usedKeys.contains(key)) { dataSet.incrementValue(getTotalValue(s, report).doubleValue(), key, key); } else { dataSet.addValue(getTotalValue(s, report), key, key); usedKeys.add(key); } } } } else { // with categories Map<Comparable, Comparable> usedKeys = new HashMap<Comparable, Comparable>(); for (Stat s : reportData) { Comparable key = getStatValue(s, dataSource); Comparable cat = getStatValue(s, categorySource); if (key != null && cat != null) { if (usedKeys.containsKey(cat) && key.equals(usedKeys.get(cat))) { dataSet.incrementValue(getTotalValue(s, report).doubleValue(), key, cat); } else { dataSet.addValue(getTotalValue(s, report), key, cat); usedKeys.put(cat, key); } } } // fill missing values with zeros for (Comparable c : usedKeys.keySet()) { for (Comparable k : usedKeys.values()) { if (dataSet.getValue(k, c) == null) { dataSet.addValue(0, k, c); } } } } return dataSet; }