/** * Tests if this object is equal to another * * @param a_obj the other object * @return true: this object is equal to the other one * @author Klaus Meffert * @since 2.3 */ public boolean equals(final Object a_obj) { if (a_obj == null) { return false; } if (a_obj == this) { return true; } if (!(a_obj instanceof KeyedValues)) { return false; } final KeyedValues kvs = (KeyedValues) a_obj; final int count = size(); if (count != kvs.size()) { return false; } for (int i = 0; i < count; i++) { final Comparable k1 = getKey(i); final Comparable k2 = kvs.getKey(i); if (!k1.equals(k2)) { return false; } final Number v1 = getValue(i); final Number v2 = kvs.getValue(i); if (v1 == null) { if (v2 != null) { return false; } } else { if (!v1.equals(v2)) { return false; } } } return true; }
@Override public boolean equals(Object o) { if (o == null) { return false; } if (o == this) { return true; } if (!(o instanceof Edge)) { return false; } Edge other = (Edge) o; if (address == null && other.address != null) { return false; } if (address != null && !address.equals(other.address)) { return false; } if (tag == null && other.tag != null) { return false; } if (tag != null && !tag.equals(other.tag)) { return false; } if (weight == null && other.weight != null) { return false; } if (weight != null && !weight.equals(other.weight)) { return false; } return true; }
// returns index of first instance of c in SuperArray, -1 if not found public int linSearch(Comparable c) { for (int x = 0; x < _size; x++) { if (c.equals(get(x))) { return x; } } return -1; }
/** * Returns the index of the series with the specified key, or -1 if there is no such series in the * dataset. * * @param seriesKey the series key (<code>null</code> permitted). * @return The index, or -1. */ public int indexOf(Comparable seriesKey) { if (null == seriesKey) return -1; int i; for (i = 0; i < mp_sSeriesKeys.length; i++) { if (seriesKey.equals(mp_sSeriesKeys[i])) { return i; } } return -1; }
/** * Returns the index for the given category. * * @param category the category (<code>null</code> not permitted). * @return The index. * @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; }
/** * Returns a series index. * * @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; }
/** * Called to add the current image to the training set * * @param event The event */ @SuppressWarnings("unchecked") void add_actionPerformed(final java.awt.event.ActionEvent event) { int i; final String letter = JOptionPane.showInputDialog( "Please enter a letter you would like to assign this sample to."); if (letter == null) { return; } if (letter.length() > 1) { JOptionPane.showMessageDialog( this, "Please enter only a single letter.", "Error", JOptionPane.ERROR_MESSAGE); return; } this.entry.downSample(); final SampleData sampleData = (SampleData) this.sample.getData().clone(); sampleData.setLetter(letter.charAt(0)); for (i = 0; i < this.letterListModel.size(); i++) { final Comparable str = (Comparable) this.letterListModel.getElementAt(i); if (str.equals(letter)) { JOptionPane.showMessageDialog( this, "That letter is already defined, delete it first!", "Error", JOptionPane.ERROR_MESSAGE); return; } if (str.compareTo(sampleData) > 0) { this.letterListModel.add(i, sampleData); return; } } this.letterListModel.add(this.letterListModel.size(), sampleData); this.letters.setSelectedIndex(i); this.entry.clear(); this.sample.repaint(); }
/** * Quickly finds the index of the given object in the list. If the object can not be found, it * returns the point where the element should be added. */ public static int sortedIndexOf(Comparable[] list, Comparable val, int lower, int higher) { if (lower >= higher) { if (val.compareTo(list[lower]) > 0) { return lower + 1; } else { return lower; } } int mid = (lower + higher) / 2; Comparable mid_val = list[mid]; if (val.equals(mid_val)) { return mid; } else if (val.compareTo(mid_val) < 0) { return sortedIndexOf(list, val, lower, mid - 1); } else { return sortedIndexOf(list, val, mid + 1, higher); } }
@SuppressWarnings({"ForLoopReplaceableByForEach"}) @Override public boolean equals(Object object) { if (!(object instanceof Tuple)) return false; Tuple other = (Tuple) object; if (this.elements.size() != other.elements.size()) return false; for (int i = 0; i < this.elements.size(); i++) { Comparable lhs = this.elements.get(i); Comparable rhs = other.elements.get(i); if (lhs == null && rhs == null) continue; if (lhs == null || rhs == null) return false; if (!lhs.equals(rhs)) return false; } return true; }
/** * Tests if this object is equal to another. * * @param obj the object (<code>null</code> permitted). * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof KeyedValues)) { return false; } KeyedValues that = (KeyedValues) obj; int count = getItemCount(); if (count != that.getItemCount()) { return false; } for (int i = 0; i < count; i++) { Comparable k1 = getKey(i); Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; } Number v1 = getValue(i); Number v2 = that.getValue(i); if (v1 == null) { if (v2 != null) { return false; } } else { if (!v1.equals(v2)) { return false; } } } return true; }
/** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw( Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); drawOutline(g2, area); // check that there is some data to display... if (DatasetUtilities.isEmptyOrNull(getDataset())) { drawNoDataMessage(g2, area); return; } int pieCount = 0; if (getDataExtractOrder() == TableOrder.BY_ROW) { pieCount = getDataset().getRowCount(); } else { pieCount = getDataset().getColumnCount(); } // the columns variable is always >= rows int displayCols = (int) Math.ceil(Math.sqrt(pieCount)); int displayRows = (int) Math.ceil((double) pieCount / (double) displayCols); // swap rows and columns to match plotArea shape if (displayCols > displayRows && area.getWidth() < area.getHeight()) { int temp = displayCols; displayCols = displayRows; displayRows = temp; } prefetchSectionPaints(); int x = (int) area.getX(); int y = (int) area.getY(); int width = ((int) area.getWidth()) / displayCols; int height = ((int) area.getHeight()) / displayRows; int row = 0; int column = 0; int diff = (displayRows * displayCols) - pieCount; int xoffset = 0; Rectangle rect = new Rectangle(); for (int pieIndex = 0; pieIndex < pieCount; pieIndex++) { rect.setBounds(x + xoffset + (width * column), y + (height * row), width, height); String title = null; if (getDataExtractOrder() == TableOrder.BY_ROW) { title = getDataset().getRowKey(pieIndex).toString(); } else { title = getDataset().getColumnKey(pieIndex).toString(); } getPieChart().setTitle(title); PieDataset piedataset = null; PieDataset dd = new CategoryToPieDataset(getDataset(), getDataExtractOrder(), pieIndex); if (getLimit() > 0.0) { piedataset = DatasetUtilities.createConsolidatedPieDataset(dd, getAggregatedItemsKey(), getLimit()); } else { piedataset = dd; } PiePlot piePlot = (PiePlot) getPieChart().getPlot(); piePlot.setDataset(piedataset); piePlot.setPieIndex(pieIndex); // update the section colors to match the global colors... for (int i = 0; i < piedataset.getItemCount(); i++) { Comparable key = piedataset.getKey(i); Paint p; if (key.equals(getAggregatedItemsKey())) { p = getAggregatedItemsPaint(); } else { p = (Paint) this.sectionPaints.get(key); } piePlot.setSectionPaint(key, p); } ChartRenderingInfo subinfo = null; if (info != null) { subinfo = new ChartRenderingInfo(); } getPieChart().draw(g2, rect, subinfo); if (info != null) { info.getOwner().getEntityCollection().addAll(subinfo.getEntityCollection()); info.addSubplotInfo(subinfo.getPlotInfo()); } ++column; if (column == displayCols) { column = 0; ++row; if (row == displayRows - 1 && diff != 0) { xoffset = (diff * width) / 2; } } } }
/** * Changes the upper bound for numbers in this sequence. If <code>maximum</code> is <code>null * </code>, then there is no upper bound. No bounds checking is done here; the new <code>maximum * </code> value may invalidate the <code>(minimum <= value < maximum)</code> invariant enforced * by the constructors. This is to simplify updating the model, naturally one should ensure that * the invariant is true before calling the <code>next</code>, <code>previous</code>, or <code> * setValue</code> methods. * * <p>Typically this property is a <code>Number</code> of the same type as the <code>value</code> * however it's possible to use any <code>Comparable</code> with a <code>compareTo</code> method * for a <code>Number</code> with the same type as the value. See <a * href="#setMinimum(java.lang.Comparable)"><code>setMinimum</code></a> for an example. * * <p>This method fires a <code>ChangeEvent</code> if the <code>maximum</code> has changed. * * @param maximum a <code>Comparable</code> that has a <code>compareTo</code> method for <code> * Number</code>s with the same type as <code>value</code> * @see #getMaximum * @see #setMinimum * @see SpinnerModel#addChangeListener */ public void setMaximum(Comparable maximum) { if ((maximum == null) ? (this.maximum != null) : !maximum.equals(this.maximum)) { this.maximum = maximum; fireStateChanged(); } }