- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
package psorter;
import java.util.Vector;
public class CArray extends Vector {
String type="";
/**
* constructor of /array/
* @param i set capacity increment
*/
public CArray(int i) {
this.capacityIncrement=i;
}
/**
* add object to end of vector with check of type
* if type same as @ first added - add this object
* safer than add
* @param o object to add
*/
public void append(Object o) {
if ( this.type.equals("") )
this.type=o.getClass().toString();
if ( o.getClass().toString().equals(this.type) ){
this.add(o);
} else {
if ( this.type.contains("Float") && o.getClass().toString().contains("Integer") )
this.add( Float.valueOf(o.toString()) );
if ( this.type.contains("Double") && o.getClass().toString().contains("Integer") )
this.add( Double.valueOf(o.toString()) );
if ( this.type.contains("Double") && o.getClass().toString().contains("Float") )
this.add( Double.valueOf(o.toString()) );
if ( this.type.contains("String") && o.getClass().toString().contains("Char") )
this.add( o.toString() );
}
}
public byte compare(int i, int j) throws Exception {
if (type.contains("Integer")) {
if ((Integer) (this.get(i)) > (Integer) (this.get(j)))
return 1;
if ((Integer) (this.get(i)) < (Integer) (this.get(j)))
return -1;
return 0;
}
if (type.contains("Float")) {
if ((Float) (this.get(i)) > (Float) (this.get(j)))
return 1;
if ((Float) (this.get(i)) < (Float) (this.get(j)))
return -1;
return 0;
}
if (type.contains("Double")) {
if ((Double) (this.get(i)) > (Double) (this.get(j)))
return 1;
if ((Double) (this.get(i)) < (Double) (this.get(j)))
return -1;
return 0;
}
if (type.contains("Char")) {
if ((Character) (this.get(i)) > (Character) (this.get(j)))
return 1;
if ((Character) (this.get(i)) < (Character) (this.get(j)))
return -1;
return 0;
}
if (type.contains("String")) {
if ( this.get(i).toString().compareTo(this.get(j).toString())>0 )
return 1;
if ( this.get(i).toString().compareTo(this.get(j).toString())<0 )
return -1;
return 0;
}
return 0;
}
}
сел писать 3 лабы естественно в последнюю ночь. начал в 11. эта была около 3х. самому потом стыдно было нести такое