Started to add unit tests.
Refactored IntegerArrayList, which is now not needed anymore (who implemented this in the first place?) Auto-Formatted DPointSetMultiIcon -> it was just so badly formatted I had to do auto formatting to make it readable. Added test for eva2.tools.StringTools (partly at least)
This commit is contained in:
parent
dcbb488bb9
commit
af82e0e5a2
@ -8,7 +8,6 @@ import java.awt.Point;
|
|||||||
import java.awt.Stroke;
|
import java.awt.Stroke;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import eva2.tools.IntegerArrayList;
|
|
||||||
import eva2.tools.chart2d.DArray;
|
import eva2.tools.chart2d.DArray;
|
||||||
import eva2.tools.chart2d.DBorder;
|
import eva2.tools.chart2d.DBorder;
|
||||||
import eva2.tools.chart2d.DComponent;
|
import eva2.tools.chart2d.DComponent;
|
||||||
@ -37,7 +36,7 @@ public class DPointSetMultiIcon extends DComponent
|
|||||||
class JumpManager
|
class JumpManager
|
||||||
{
|
{
|
||||||
protected int index = -1;
|
protected int index = -1;
|
||||||
protected IntegerArrayList jumps = new IntegerArrayList();
|
protected ArrayList<Integer> jumps = new ArrayList<Integer>();
|
||||||
|
|
||||||
public void addJump()
|
public void addJump()
|
||||||
{
|
{
|
||||||
|
@ -1,161 +0,0 @@
|
|||||||
/**
|
|
||||||
* Filename: $RCSfile: IntegerArrayList.java,v $
|
|
||||||
* Purpose: This class is similar to 'java.util.ArrayList', except that it can
|
|
||||||
* only hold and manage integer values.
|
|
||||||
* Language: Java
|
|
||||||
* Compiler: JDK 1.2
|
|
||||||
* Authors: Fred Rapp
|
|
||||||
* Version: $Revision: 1.1.1.1 $
|
|
||||||
* $Date: 2003/07/03 14:59:40 $
|
|
||||||
* $Author: ulmerh $
|
|
||||||
* Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
|
|
||||||
*/
|
|
||||||
|
|
||||||
package eva2.tools;
|
|
||||||
|
|
||||||
/*==========================================================================*
|
|
||||||
* CLASS DECLARATION
|
|
||||||
*==========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is similar to 'java.util.ArrayList', except that it can
|
|
||||||
* only hold and manage integer values.
|
|
||||||
*/
|
|
||||||
public class IntegerArrayList
|
|
||||||
{
|
|
||||||
/*-------------------------------------------------------------------------*
|
|
||||||
* private member variables
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
private int[] integerArray = null;
|
|
||||||
private int integerCount = 0;
|
|
||||||
|
|
||||||
private int initialSize;
|
|
||||||
private int incrementFactor;
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*
|
|
||||||
* constructor
|
|
||||||
*------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
public IntegerArrayList()
|
|
||||||
{
|
|
||||||
// call other constructor with default values
|
|
||||||
this(100, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntegerArrayList(int initialSize, int incrementFactor)
|
|
||||||
{
|
|
||||||
this.initialSize = initialSize;
|
|
||||||
this.incrementFactor = incrementFactor;
|
|
||||||
|
|
||||||
// create new integer array of initial size
|
|
||||||
integerArray = new int[initialSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void destroy() { integerArray = null; integerCount = 0; }
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*
|
|
||||||
* public methods
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the contents of this integer list and sets it back to it's initial state.
|
|
||||||
*/
|
|
||||||
public void clear() { integerArray = new int[initialSize]; integerCount = 0; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of components in this list.
|
|
||||||
*/
|
|
||||||
public int size() { return integerCount; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses given string to integer and adds it to the integer list.
|
|
||||||
* @return true if parsing was successful, false if an error occured.
|
|
||||||
*/
|
|
||||||
public boolean add(String stringValue)
|
|
||||||
{
|
|
||||||
boolean success = false;
|
|
||||||
try {
|
|
||||||
int value = Integer.parseInt(stringValue);
|
|
||||||
add(value);
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
catch (Exception e) {}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new integer value to the integer list.
|
|
||||||
*/
|
|
||||||
public void add(int value)
|
|
||||||
{
|
|
||||||
// check integer array size
|
|
||||||
if (integerCount == integerArray.length)
|
|
||||||
{
|
|
||||||
// increase size of int array
|
|
||||||
int old_length = integerArray.length;
|
|
||||||
int new_length = incrementFactor * old_length;
|
|
||||||
int[] new_array = new int[new_length];
|
|
||||||
for (int i=0; i<old_length; i++) {
|
|
||||||
new_array[i] = integerArray[i];
|
|
||||||
}
|
|
||||||
integerArray = new_array;
|
|
||||||
}
|
|
||||||
// add given value to array
|
|
||||||
integerArray[integerCount++] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the integer value at the given position or 'min-value' if out of array bounds.
|
|
||||||
*/
|
|
||||||
public int get(int index)
|
|
||||||
{
|
|
||||||
if ((index < 0) || (index >= integerCount)) { return Integer.MIN_VALUE; }
|
|
||||||
|
|
||||||
return integerArray[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the contents of this list as an array of integer values.
|
|
||||||
* @param exactLength determines if the returned array should have the exactly right length, or if longer arrays are allowed
|
|
||||||
*/
|
|
||||||
public int[] getIntegerArray(boolean exactLength)
|
|
||||||
{
|
|
||||||
// check if we can simply return our internal integer array
|
|
||||||
if (!exactLength || (integerArray.length == integerCount)) { return integerArray; }
|
|
||||||
|
|
||||||
// make a copy of the array with the exactly right length
|
|
||||||
int size = integerCount;
|
|
||||||
int[] new_array = new int[ size];
|
|
||||||
for (int i=0; i< size; i++) { new_array[i] = integerArray[i]; }
|
|
||||||
return new_array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the contents of this list as an array of double values.
|
|
||||||
*/
|
|
||||||
public double[] getDoubleArray()
|
|
||||||
{
|
|
||||||
// make a copy of the array
|
|
||||||
int size = integerCount;
|
|
||||||
double[] new_array = new double[ size];
|
|
||||||
for (int i=0; i< size; i++) { new_array[i] = integerArray[i]; }
|
|
||||||
return new_array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the contents of this list as an array of strings.
|
|
||||||
*/
|
|
||||||
public String[] getStringArray()
|
|
||||||
{
|
|
||||||
// make a copy of the array
|
|
||||||
int size = integerCount;
|
|
||||||
String[] new_array = new String[ size];
|
|
||||||
for (int i=0; i<size; i++) { new_array[i] = "" + integerArray[i]; }
|
|
||||||
return new_array;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* END OF FILE
|
|
||||||
****************************************************************************/
|
|
@ -1,288 +1,299 @@
|
|||||||
/**
|
/**
|
||||||
* Filename: $RCSfile: DPointSet.java,v $
|
* Filename: $RCSfile: DPointSet.java,v $ Purpose: Language: Java Compiler: JDK 1.3 Authors: Fabian
|
||||||
* Purpose:
|
* Hennecke Version: $Revision: 1.1.1.1 $ $Date: 2003/07/03 14:59:42 $ $Author: ulmerh $ Copyright
|
||||||
* Language: Java
|
* (c) Dept. Computer Architecture, University of Tuebingen, Germany
|
||||||
* Compiler: JDK 1.3
|
|
||||||
* Authors: Fabian Hennecke
|
|
||||||
* Version: $Revision: 1.1.1.1 $
|
|
||||||
* $Date: 2003/07/03 14:59:42 $
|
|
||||||
* $Author: ulmerh $
|
|
||||||
* Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package eva2.tools.chart2d;
|
package eva2.tools.chart2d;
|
||||||
|
|
||||||
/*==========================================================================*
|
/*
|
||||||
* IMPORTS
|
* ==========================================================================* IMPORTS
|
||||||
*==========================================================================*/
|
*==========================================================================
|
||||||
|
*/
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
import java.awt.* ;
|
|
||||||
|
|
||||||
import eva2.tools.IntegerArrayList;
|
|
||||||
import eva2.tools.math.Mathematics;
|
import eva2.tools.math.Mathematics;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/*==========================================================================*
|
public class DPointSet extends DComponent {
|
||||||
* CLASS DECLARATION
|
|
||||||
*==========================================================================*/
|
|
||||||
|
|
||||||
public class DPointSet extends DComponent
|
protected DPointIcon icon = null;
|
||||||
{
|
|
||||||
protected DPointIcon icon = null;
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*
|
/*
|
||||||
* private member variables
|
* -------------------------------------------------------------------------* private member
|
||||||
*-------------------------------------------------------------------------*/
|
* variables
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
protected DIntDoubleMap x, y;
|
||||||
|
protected boolean connected;
|
||||||
|
protected Stroke stroke = new BasicStroke();
|
||||||
|
protected JumpManager jumper = new JumpManager();
|
||||||
|
|
||||||
protected DIntDoubleMap x, y;
|
/*
|
||||||
protected boolean connected;
|
* -------------------------------------------------------------------------* constructor
|
||||||
protected Stroke stroke = new BasicStroke();
|
*-------------------------------------------------------------------------
|
||||||
protected JumpManager jumper = new JumpManager();
|
*/
|
||||||
|
public DPointSet() {
|
||||||
|
this(10, 2);
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*
|
public DPointSet(int initial_capacity) {
|
||||||
* constructor
|
this(initial_capacity, 2);
|
||||||
*-------------------------------------------------------------------------*/
|
}
|
||||||
public DPointSet(){
|
|
||||||
this(10, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public DPointSet(int initial_capacity, int length_multiplier) {
|
||||||
|
this(new DArray(initial_capacity, length_multiplier),
|
||||||
|
new DArray(initial_capacity, length_multiplier));
|
||||||
|
}
|
||||||
|
|
||||||
public DPointSet( int initial_capacity ){
|
public DPointSet(DIntDoubleMap x_values, DIntDoubleMap y_values) {
|
||||||
this(initial_capacity, 2);
|
if (x_values.getSize() != y_values.getSize()) {
|
||||||
}
|
throw new IllegalArgumentException(
|
||||||
|
"The number of x-values has to be the same than the number of y-values");
|
||||||
|
}
|
||||||
|
x = x_values;
|
||||||
|
y = y_values;
|
||||||
|
restore();
|
||||||
|
setDBorder(new DBorder(1, 1, 1, 1));
|
||||||
|
}
|
||||||
|
|
||||||
public DPointSet( int initial_capacity, int length_multiplier ){
|
/*
|
||||||
this( new DArray(initial_capacity, length_multiplier),
|
* -------------------------------------------------------------------------* public methods
|
||||||
new DArray(initial_capacity, length_multiplier) );
|
*-------------------------------------------------------------------------
|
||||||
}
|
*/
|
||||||
|
public void paint(DMeasures m) {
|
||||||
|
Graphics2D g = (Graphics2D) m.getGraphics();
|
||||||
|
g.setStroke(stroke);
|
||||||
|
if (color != null) {
|
||||||
|
g.setColor(color);
|
||||||
|
}
|
||||||
|
int size = getSize();
|
||||||
|
if (connected && size > 1) {
|
||||||
|
jumper.restore();
|
||||||
|
while (jumper.hasMoreIntervals()) {
|
||||||
|
int[] interval = jumper.nextInterval();
|
||||||
|
Point p1 = null, p2;
|
||||||
|
for (int i = interval[0]; i < interval[1]; i++) {
|
||||||
|
p2 = m.getPoint(x.getImage(i), y.getImage(i));
|
||||||
|
if (p1 != null) {
|
||||||
|
g.drawLine(p1.x, p1.y, p2.x, p2.y);
|
||||||
|
}
|
||||||
|
if (icon != null) {
|
||||||
|
g.setStroke(new BasicStroke());
|
||||||
|
g.translate(p2.x, p2.y);
|
||||||
|
icon.paint(g);
|
||||||
|
g.translate(-p2.x, -p2.y);
|
||||||
|
g.setStroke(stroke);
|
||||||
|
}
|
||||||
|
p1 = p2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Point p;
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
p = m.getPoint(x.getImage(i), y.getImage(i));
|
||||||
|
if (icon == null) {
|
||||||
|
g.drawLine(p.x - 1, p.y - 1, p.x + 1, p.y + 1);
|
||||||
|
g.drawLine(p.x + 1, p.y - 1, p.x - 1, p.y + 1);
|
||||||
|
} else {
|
||||||
|
g.setStroke(new BasicStroke());
|
||||||
|
g.translate(p.x, p.y);
|
||||||
|
icon.paint(g);
|
||||||
|
g.translate(-p.x, -p.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.setStroke(new BasicStroke());
|
||||||
|
}
|
||||||
|
|
||||||
public DPointSet(DIntDoubleMap x_values, DIntDoubleMap y_values){
|
public void addDPoint(DPoint p) {
|
||||||
if( x_values.getSize() != y_values.getSize() ) throw
|
x.addImage(p.x);
|
||||||
new IllegalArgumentException(
|
y.addImage(p.y);
|
||||||
"The number of x-values has to be the same than the number of y-values"
|
rectangle.insert(p);
|
||||||
);
|
repaint();
|
||||||
x = x_values;
|
}
|
||||||
y = y_values;
|
|
||||||
restore();
|
|
||||||
setDBorder(new DBorder(1,1,1,1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*
|
public void addDPoint(double x, double y) {
|
||||||
* public methods
|
addDPoint(new DPoint(x, y));
|
||||||
*-------------------------------------------------------------------------*/
|
}
|
||||||
|
|
||||||
public void paint( DMeasures m ){
|
/**
|
||||||
Graphics2D g = (Graphics2D)m.getGraphics();
|
* method causes the DPointSet to interupt the connected painting at the current position
|
||||||
g.setStroke(stroke);
|
*/
|
||||||
if( color != null ) g.setColor( color );
|
public void jump() {
|
||||||
int size = getSize();
|
jumper.addJump();
|
||||||
if( connected && size > 1 ){
|
}
|
||||||
jumper.restore();
|
|
||||||
while( jumper.hasMoreIntervals() ){
|
|
||||||
int[] interval = jumper.nextInterval();
|
|
||||||
Point p1 = null, p2;
|
|
||||||
for( int i=interval[0]; i<interval[1]; i++ ){
|
|
||||||
p2 = m.getPoint( x.getImage(i), y.getImage(i) );
|
|
||||||
if( p1 != null)
|
|
||||||
g.drawLine( p1.x, p1.y, p2.x, p2.y );
|
|
||||||
if( icon != null ){
|
|
||||||
g.setStroke( new BasicStroke() );
|
|
||||||
g.translate(p2.x, p2.y);
|
|
||||||
icon.paint(g);
|
|
||||||
g.translate(-p2.x, -p2.y);
|
|
||||||
g.setStroke( stroke );
|
|
||||||
}
|
|
||||||
p1 = p2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Point p;
|
|
||||||
for( int i=0; i<size; i++ ){
|
|
||||||
p = m.getPoint( x.getImage(i), y.getImage(i) );
|
|
||||||
if( icon == null ){
|
|
||||||
g.drawLine(p.x - 1, p.y - 1, p.x + 1, p.y + 1);
|
|
||||||
g.drawLine(p.x + 1, p.y - 1, p.x - 1, p.y + 1);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
g.setStroke( new BasicStroke() );
|
|
||||||
g.translate(p.x, p.y);
|
|
||||||
icon.paint(g);
|
|
||||||
g.translate(-p.x, -p.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g.setStroke( new BasicStroke() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDPoint( DPoint p ){
|
/**
|
||||||
x.addImage(p.x);
|
* method removes all jump positions if the DPointSet is connected, all points will be painted
|
||||||
y.addImage(p.y);
|
* connected to their following point
|
||||||
rectangle.insert(p);
|
*/
|
||||||
repaint();
|
public void removeJumps() {
|
||||||
}
|
jumper.reset();
|
||||||
|
}
|
||||||
|
|
||||||
public void addDPoint( double x, double y ){
|
/**
|
||||||
addDPoint(new DPoint(x, y));
|
* method returns the DPoint at the given index
|
||||||
}
|
*
|
||||||
|
* @param index the index of the DPoint
|
||||||
|
* @return the DPoint at the given index
|
||||||
|
*/
|
||||||
|
public DPoint getDPoint(int index) {
|
||||||
|
if (index >= x.getSize()) {
|
||||||
|
System.out.println("getDPoint() index" + index);
|
||||||
|
System.out.println("x.getSize() " + x.getSize());
|
||||||
|
throw new ArrayIndexOutOfBoundsException(index);
|
||||||
|
}
|
||||||
|
DPoint p = new DPoint(x.getImage(index), y.getImage(index));
|
||||||
|
p.setIcon(icon);
|
||||||
|
p.setColor(color);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method causes the DPointSet to interupt the connected painting at the
|
* method puts the given DPoint at the given position in the set
|
||||||
* current position
|
*
|
||||||
*/
|
* @param index the index of the point
|
||||||
public void jump(){
|
* @param p the point to insert
|
||||||
jumper.addJump();
|
*/
|
||||||
}
|
public void setDPoint(int index, DPoint p) {
|
||||||
|
if (index >= x.getSize()) {
|
||||||
|
throw new ArrayIndexOutOfBoundsException(index);
|
||||||
|
}
|
||||||
|
rectangle.insert(p);
|
||||||
|
x.setImage(index, p.x);
|
||||||
|
y.setImage(index, p.y);
|
||||||
|
restore();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method removes all jump positions
|
* method sets an icon for a better displaying of the point set
|
||||||
* if the DPointSet is connected, all points will be painted connected to
|
*
|
||||||
* their following point
|
* @param icon the DPointIcon
|
||||||
*/
|
*/
|
||||||
public void removeJumps(){
|
public void setIcon(DPointIcon icon) {
|
||||||
jumper.reset();
|
this.icon = icon;
|
||||||
}
|
if (icon == null) {
|
||||||
|
setDBorder(new DBorder(1, 1, 1, 1));
|
||||||
|
} else {
|
||||||
|
setDBorder(icon.getDBorder());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method returns the DPoint at the given index
|
* method returns the current icon of the point set
|
||||||
*
|
*
|
||||||
* @param index the index of the DPoint
|
* @return the DPointIcon
|
||||||
* @return the DPoint at the given index
|
*/
|
||||||
*/
|
public DPointIcon getIcon() {
|
||||||
public DPoint getDPoint( int index ){
|
return icon;
|
||||||
if( index >= x.getSize() ) {
|
}
|
||||||
System.out.println("getDPoint() index"+index);
|
|
||||||
System.out.println("x.getSize() "+x.getSize());
|
|
||||||
throw new ArrayIndexOutOfBoundsException(index);
|
|
||||||
}
|
|
||||||
DPoint p = new DPoint( x.getImage( index ), y.getImage( index ) );
|
|
||||||
p.setIcon( icon );
|
|
||||||
p.setColor( color );
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method puts the given DPoint at the given position in the set
|
* method sets the stroke of the line if the points were not connected, they now will be
|
||||||
*
|
* connected
|
||||||
* @param index the index of the point
|
*
|
||||||
* @param p the point to insert
|
* @param s the new stroke
|
||||||
*/
|
*/
|
||||||
public void setDPoint( int index, DPoint p ){
|
public void setStroke(Stroke s) {
|
||||||
if( index >= x.getSize() ) throw new ArrayIndexOutOfBoundsException(index);
|
if (s == null) {
|
||||||
rectangle.insert(p);
|
s = new BasicStroke();
|
||||||
x.setImage(index,p.x);
|
}
|
||||||
y.setImage(index,p.y);
|
stroke = s;
|
||||||
restore();
|
repaint();
|
||||||
repaint();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method sets an icon for a better displaying of the point set
|
* method returns the current stroke of the line
|
||||||
*
|
*
|
||||||
* @param icon the DPointIcon
|
* @return the stroke
|
||||||
*/
|
*/
|
||||||
public void setIcon( DPointIcon icon ){
|
public Stroke getStroke() {
|
||||||
this.icon = icon;
|
return stroke;
|
||||||
if( icon == null ) setDBorder(new DBorder(1,1,1,1));
|
}
|
||||||
else setDBorder( icon.getDBorder() );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method returns the current icon of the point set
|
* Return the minimum y value in the point set.
|
||||||
*
|
*
|
||||||
* @return the DPointIcon
|
* @return the minimum y value in the point set
|
||||||
*/
|
*/
|
||||||
public DPointIcon getIcon(){
|
public double getMinYVal() {
|
||||||
return icon;
|
return y.getMinImageValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public double getMinPositiveYValue() {
|
||||||
* method sets the stroke of the line
|
return y.getMinPositiveImageValue();
|
||||||
* if the points were not connected, they now will be connected
|
}
|
||||||
*
|
|
||||||
* @param s the new stroke
|
|
||||||
*/
|
|
||||||
public void setStroke( Stroke s ){
|
|
||||||
if( s == null ) s = new BasicStroke();
|
|
||||||
stroke = s;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public void setConnected(boolean aFlag) {
|
||||||
* method returns the current stroke of the line
|
boolean changed = !(aFlag == connected);
|
||||||
*
|
connected = aFlag;
|
||||||
* @return the stroke
|
if (changed) {
|
||||||
*/
|
repaint();
|
||||||
public Stroke getStroke(){
|
}
|
||||||
return stroke;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the minimum y value in the point set.
|
|
||||||
*
|
|
||||||
* @return the minimum y value in the point set
|
|
||||||
*/
|
|
||||||
public double getMinYVal() {
|
|
||||||
return y.getMinImageValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getMinPositiveYValue() {
|
|
||||||
return y.getMinPositiveImageValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnected( boolean aFlag ){
|
public void removeAllPoints() {
|
||||||
boolean changed = !( aFlag == connected );
|
if (x.getSize() == 0) {
|
||||||
connected = aFlag;
|
return;
|
||||||
if( changed ) repaint();
|
}
|
||||||
}
|
x.reset();
|
||||||
|
y.reset();
|
||||||
|
jumper.reset();
|
||||||
|
repaint();
|
||||||
|
rectangle = DRectangle.getEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public void removeAllPoints(){
|
public String toString() {
|
||||||
if( x.getSize() == 0 ) return;
|
String text = "eva2.tools.chart2d.DPointSet[size:" + getSize();
|
||||||
x.reset();
|
for (int i = 0; i < x.getSize(); i++) {
|
||||||
y.reset();
|
text += ",(" + x.getImage(i) + "," + y.getImage(i) + ")";
|
||||||
jumper.reset();
|
}
|
||||||
repaint();
|
text += "]";
|
||||||
rectangle = DRectangle.getEmpty();
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
/**
|
||||||
String text = "eva2.tools.chart2d.DPointSet[size:"+getSize();
|
* method returns the index to the nearest
|
||||||
for( int i=0; i<x.getSize(); i++ )
|
* <code>DPoint</code> in this
|
||||||
text += ",("+x.getImage(i)+","+y.getImage(i)+")";
|
* <code>DPointSet</code>.
|
||||||
text += "]";
|
*
|
||||||
return text;
|
* @return the index to the nearest
|
||||||
}
|
* <code>DPoint</code>. -1 if no nearest
|
||||||
|
* <code>DPoint</code> was found.
|
||||||
|
*/
|
||||||
|
public int getNearestDPointIndex(DPoint point) {
|
||||||
|
double minValue = Double.MAX_VALUE;
|
||||||
|
int minIndex = -1;
|
||||||
|
for (int i = 0; i < x.getSize(); i++) {
|
||||||
|
double dx = point.x - x.getImage(i);
|
||||||
|
double dy = point.y - y.getImage(i);
|
||||||
|
double dummy = dx * dx + dy * dy;
|
||||||
|
if (dummy < minValue) {
|
||||||
|
minValue = dummy;
|
||||||
|
minIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minIndex;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method returns the index to the nearest <code>DPoint</code> in this <code>DPointSet</code>.
|
* method returns the nearest
|
||||||
*
|
* <code>DPoint</code> in this
|
||||||
* @return the index to the nearest <code>DPoint</code>. -1 if no nearest <code>DPoint</code> was found.
|
* <code>DPointSet</code>.
|
||||||
*/
|
*
|
||||||
public int getNearestDPointIndex(DPoint point){
|
* @return the nearest
|
||||||
double minValue = Double.MAX_VALUE;
|
* <code>DPoint</code>
|
||||||
int minIndex = -1;
|
*/
|
||||||
for( int i=0; i<x.getSize(); i++ ){
|
public DPoint getNearestDPoint(DPoint point) {
|
||||||
double dx = point.x - x.getImage(i);
|
int minIndex = getNearestDPointIndex(point);
|
||||||
double dy = point.y - y.getImage(i);
|
|
||||||
double dummy = dx*dx + dy*dy;
|
|
||||||
if (dummy < minValue){
|
|
||||||
minValue = dummy;
|
|
||||||
minIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return minIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (minIndex == -1) {
|
||||||
* method returns the nearest <code>DPoint</code> in this <code>DPointSet</code>.
|
return null;
|
||||||
*
|
} else {
|
||||||
* @return the nearest <code>DPoint</code>
|
return new DPoint(x.getImage(minIndex), y.getImage(minIndex));
|
||||||
*/
|
}
|
||||||
public DPoint getNearestDPoint(DPoint point){
|
}
|
||||||
int minIndex = getNearestDPointIndex(point);
|
|
||||||
|
|
||||||
if(minIndex == -1) return null;
|
|
||||||
else return new DPoint(x.getImage(minIndex), y.getImage(minIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
// public int getSize(){
|
// public int getSize(){
|
||||||
// int size = x.getSize();
|
// int size = x.getSize();
|
||||||
@ -293,76 +304,79 @@ public class DPointSet extends DComponent
|
|||||||
// );
|
// );
|
||||||
// return size;
|
// return size;
|
||||||
// }
|
// }
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public int getSize(){ // testhu
|
public int getSize() { // testhu
|
||||||
int size = x.getSize();
|
int size = x.getSize();
|
||||||
if( size <= y.getSize() )
|
if (size <= y.getSize()) {
|
||||||
return size;
|
return size;
|
||||||
return x.getSize();
|
}
|
||||||
}
|
return x.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void restore() {
|
||||||
|
if (getSize() == 0) {
|
||||||
|
rectangle = DRectangle.getEmpty();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double min_x = x.getMinImageValue(),
|
||||||
|
max_x = x.getMaxImageValue(),
|
||||||
|
min_y = y.getMinImageValue(),
|
||||||
|
max_y = y.getMaxImageValue();
|
||||||
|
if (Mathematics.areFinite(min_x, max_x, min_y, max_y) == -1) {
|
||||||
|
rectangle = new DRectangle(min_x, min_y, max_x - min_x, max_y - min_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void restore(){
|
/**
|
||||||
if( getSize() == 0){
|
* this class stores the jump positions (see this.jump)
|
||||||
rectangle = DRectangle.getEmpty();
|
*/
|
||||||
return;
|
class JumpManager {
|
||||||
}
|
|
||||||
double min_x = x.getMinImageValue(),
|
|
||||||
max_x = x.getMaxImageValue(),
|
|
||||||
min_y = y.getMinImageValue(),
|
|
||||||
max_y = y.getMaxImageValue();
|
|
||||||
if (Mathematics.areFinite(min_x, max_x, min_y, max_y) == -1)
|
|
||||||
rectangle = new DRectangle(min_x, min_y, max_x - min_x, max_y - min_y );
|
|
||||||
// else
|
|
||||||
// System.err.println("Warning, rectangle not restored due to invalid (infinite/NaN) values.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
protected ArrayList<Integer> jumps = new ArrayList<Integer>();
|
||||||
* this class stores the jump positions (see this.jump)
|
protected int index = -1;
|
||||||
*/
|
|
||||||
class JumpManager{
|
|
||||||
protected IntegerArrayList jumps = new IntegerArrayList();
|
|
||||||
protected int index = -1;
|
|
||||||
|
|
||||||
public void addJump(){
|
public void addJump() {
|
||||||
jumps.add(getSize());
|
jumps.add(getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] nextInterval(){
|
public int[] nextInterval() {
|
||||||
int no_jumps = jumps.size();
|
int noJumps = jumps.size();
|
||||||
if( index >= no_jumps ) throw
|
if (index >= noJumps) {
|
||||||
new ArrayIndexOutOfBoundsException("No more intervals in JumpManager");
|
throw new ArrayIndexOutOfBoundsException("No more intervals in JumpManager");
|
||||||
|
}
|
||||||
|
|
||||||
int[] inter = new int[2];
|
int[] inter = new int[2];
|
||||||
|
|
||||||
if( index == -1 ) inter[0] = 0;
|
if (index == -1) {
|
||||||
else inter[0] = jumps.get(index);
|
inter[0] = 0;
|
||||||
|
} else {
|
||||||
|
inter[0] = jumps.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if( index < no_jumps ) inter[1] = jumps.get(index);
|
if (index < noJumps) {
|
||||||
else inter[1] = getSize();
|
inter[1] = jumps.get(index);
|
||||||
|
} else {
|
||||||
|
inter[1] = getSize();
|
||||||
|
}
|
||||||
|
|
||||||
return inter;
|
return inter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMoreIntervals(){
|
public boolean hasMoreIntervals() {
|
||||||
return index < jumps.size();
|
return index < jumps.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restore(){
|
public void restore() {
|
||||||
index = -1;
|
index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(){
|
public void reset() {
|
||||||
index = -1;
|
index = -1;
|
||||||
jumps.clear();
|
jumps.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* END OF FILE
|
|
||||||
****************************************************************************/
|
|
||||||
|
59
test/eva2/tools/StringToolsTest.java
Normal file
59
test/eva2/tools/StringToolsTest.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package eva2.tools;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.After;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author becker
|
||||||
|
*/
|
||||||
|
public class StringToolsTest {
|
||||||
|
|
||||||
|
public StringToolsTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of humaniseCamelCase method, of class StringTools.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testHumaniseCamelCase() {
|
||||||
|
HashMap<String, String> map = new HashMap<String, String>();
|
||||||
|
map.put("camelCase", "Camel Case");
|
||||||
|
map.put("Camel Case", "Camel Case");
|
||||||
|
map.put("thisIsAwesome", "This Is Awesome");
|
||||||
|
map.put("THQIsNice", "THQ Is Nice");
|
||||||
|
map.put("iLikeABC", "I Like ABC");
|
||||||
|
|
||||||
|
String key, value;
|
||||||
|
Iterator iter = map.entrySet().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Map.Entry pairs = (Map.Entry) iter.next();
|
||||||
|
key = (String) pairs.getKey();
|
||||||
|
value = (String) pairs.getValue();
|
||||||
|
String result = StringTools.humaniseCamelCase(key);
|
||||||
|
assertEquals(value, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of upcaseFirst method, of class StringTools.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testUpcaseFirst() {
|
||||||
|
assertEquals("Camel", StringTools.upcaseFirst("camel"));
|
||||||
|
assertEquals("UpWeGo", StringTools.upcaseFirst("upWeGo"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user