/*********** Diese Klasse stellt eines Wert in der auszufhrenden Rechnung dar. Ein Wert kann ein Scalar oder ein Vektor sein. Methoden zur Verknpfung von Werten sind implementiert (add, sub, mult), wobei zu beachten ist, dass das Objekt auf dem die Operation ausgefhrt wird nachher das Ergebnis tr„gt. Zur Ausgabe ist die Methode getString() vorgesehen ***********/ public class CalcValue { protected static final int TUNDEF=-1; protected static final int TSCALAR=0; protected static final int TVERTEX=1; protected int type; protected Vertex vertex; protected double scalar; CalcValue() //Undefiniert { init(TUNDEF); } CalcValue(double scalar) { setContent(scalar); } CalcValue(Vertex v) { setContent(v); } protected void init(int _type) { type=_type; vertex=null; } public boolean isScalar() { return type==TSCALAR; } public boolean isVertex() { return type==TVERTEX; } public void invert() { if(type==TSCALAR) { scalar=-scalar; } if(type==TVERTEX) { vertex.invert(); } } public void setContent(double value) { init(TSCALAR); scalar=value; } public void setContent(Vertex v) { init(TVERTEX); vertex=new Vertex(v); } public void add(CalcValue op) throws ProcessException { if(op.type != type) throw new ProcessException("cannot add different types"); if(op.type==TVERTEX) { if(vertex==null)throw new ProcessException("Vertex pointer invalid"); try { vertex.add(op.vertex); } catch(VertexException e) {//Diese Exception darf theoretisch nie auftreten } return; } if(op.type==TSCALAR) { scalar+=op.scalar; return; } throw new ProcessException("cannot add: unknown calc type"); } public void sub(CalcValue op) throws ProcessException { if(op.type != type) throw new ProcessException("cannot substract different types"); if(op.type==TVERTEX) { if(vertex==null) throw new ProcessException("Vertex pointer invalid"); try { vertex.sub(op.vertex); } catch(VertexException e) { } return; } if(op.type==TSCALAR) { scalar-=op.scalar; return; } throw new ProcessException("cannot substract: unknown calc type"); } public void mult(CalcValue op) throws ProcessException { try { if(op.type == type) { if(type==TVERTEX) { if(vertex==null)throw new ProcessException("Vertex pointer invalid"); vertex.mult(op.vertex); return; } if(type==TSCALAR) { scalar*=op.scalar; return; } throw new ProcessException("cannot multiply: unknown calc type"); } else { if(type==TVERTEX) { if(op.type==TSCALAR) { if(vertex==null)throw new ProcessException("Vertex pointer invalid"); vertex.mult(op.scalar); } else throw new ProcessException("cannot multiply: unknow calc type"); } if(type==TSCALAR) { if(op.type==TVERTEX) { Vertex temp; temp=new Vertex(op.vertex); temp.mult(scalar); setContent(temp); } else throw new ProcessException("cannot multiply: unknown calc type"); } } } catch(VertexException e) { } }// mult public String getString() throws ProcessException { switch(type) { case TVERTEX: if(vertex==null)throw new ProcessException("Vertex pointer invalid"); return vertex.getString(); case TSCALAR: return FloatUtil.getString(scalar); default: throw new ProcessException("unknown type"); } } };