package AstroOL; import java.text.ParseException; import java.util.StringTokenizer; /** Eine einzelne Direktion. Diese Klasse wird im wesentlichen als strukturierter Datentyp für die Informationen verwendet, die zusammen eine einzelne Direktion ausmachen, Hierin ist sie der Klasse {@link AspectPoint AspectPoint} ähnlich: Wie diese dient sie als Zeilentyp einer Liste. */ public class Direction implements Comparable { /** Nummer des Signifikators */ public int sig; /** Koordinaten des Signifikators */ public double ls, bs; /** Promissor. Der Promissor ist nicht, wie der Signifikator, ein elementarer Faktor des Horoskops, sondern ein sensitiver Punkt der Ekliptik: Eine Aspektstelle, eine Halbdistanz oder ein Spiegelpunkt. Der Promissor kann daher nicht durch eine blosse Nummer ausgedrückt werden, sondern ist vom Datentyp {@link AspectPoint AspectPoint}. */ public AspectPoint prom; /** Flag für direkt/convers. Der Wert <code>true</code> steht für eine direkte, <code>false</code> für eine converse Direktion. */ public boolean direct; /** Direktionsbogen in Grad. */ public double db; /** Ereignisdatum. Das Datum, zu dem die Direktion fällig wird. */ public double jd; /** Der RAMC-Wert, bei dem die Direktion sich auslöst (RAMCd oder RAMCc). */ public double ramc; public static void main(String[] args) { Direction dir = null; System.out.println("Input:"+args[0]); try { dir = parseForm( args[0] ); if (dir != null) System.out.println("Output:" + dir ); } catch (ParseException ex) { System.out.println(ex.getMessage()); } } /** Standard-Vergleichsmethode für die Sortierung nach Fälligkeit. */ public int compareTo( Object o) { Direction d1 = (Direction) o; if (this.jd < d1.jd) return -1; else if (this.jd == d1.jd) return 0; else return 1; } /** Textförmige Ausgabe der Direktion als Direktionsformel */ public String toString() { StringBuffer s; // Direktionsformel s = new StringBuffer(Horoscope.planetTextShort(sig) + " "); if (prom.planet2 >= 0) s.append( "= " +Horoscope.planetTextShort(prom.planet1)+"/"+Horoscope.planetTextShort(prom.planet2)+" " ); else if (prom.aspect < 100) { s.append( Horoscope.aspectTextShort[prom.aspect]); if ((prom.aspect > 0) && (prom.aspect < Horoscope.aspect.length-1)) s.append( prom.aspectSign ); s.append(" "+Horoscope.planetTextShort(prom.planet1)+" " ); } else if (prom.aspect == Horoscope.azm) s.append("azm "+Horoscope.planetTextShort(prom.planet1)); else if (prom.aspect == Horoscope.aaz) s.append("azm "+Horoscope.planetTextShort(prom.planet1)); else if (prom.aspect == Horoscope.fra) if (prom.aspectSign == '-') s.append( prom.angle + "- " + Horoscope.planetTextShort(prom.planet1)); else s.append(prom.angle + " " + Horoscope.planetTextShort(prom.planet1)); else if (prom.aspect == Horoscope.frp) s.append("= " + Calculator.dms(prom.lon,Calculator.ECL).replaceAll(" ","")); // Direkt oder convers s.append( direct ? " dir " : " conv " ); return s.toString(); } /** Eine Direktionsformel einlesen und ein Direction-Objekt erzeugen @param dirForm Direktionsformel, zum Beispiel "JU SXT- SA CONV" */ public static Direction parseForm( String dirForm ) throws ParseException { StringTokenizer st = new StringTokenizer( dirForm ); int i; String s,s1; Direction dir= new Direction(); if (!st.hasMoreTokens()) throw new ParseException("Bitte eine Direktionsformel eingeben",0); else { // Signifikator bestimmen s = st.nextToken(); s1 = s.toUpperCase(); dir.sig = -1; // Zuerst nach Planetenkürzel suchen for (i = 0; i < Horoscope.planetTextShort.length; i++) if (Horoscope.planetTextShort[i].equals(s1)) { dir.sig = i; break; } if (dir.sig == -1) // Dann nach Hauskürzel for (i = 0; i < Horoscope.houseTextShort.length; i++) if (Horoscope.houseTextShort[i].equals(s1)) { dir.sig = i + 1 + Horoscope.houseRange; break; } if (dir.sig==-1) // Alternative Abkürzungen für Aszendent if (s1.equals("AC")||s1.equals("AS")) dir.sig = Horoscope.houseRange+1; // Alternative Abkürzung für MC else { if (s1.equals("X")) dir.sig = Horoscope.houseRange+10; else throw new ParseException("\""+s+"\" kann nicht als Signifikator interpretiert werden",1 ); } } if (!st.hasMoreTokens()) throw new ParseException("Direktionsformel ist zu kurz",1); else { // Aspekt bestimmen s = st.nextToken(); dir.prom = new AspectPoint(); dir.prom.aspectSign = ' '; dir.prom.aspect = -1; if (s.endsWith("+")) { dir.prom.aspectSign = '+'; s1 = s.substring(0,s.length()-1).toUpperCase(); } else if (s.endsWith("-")) { dir.prom.aspectSign = '-'; s1 = s.substring(0,s.length()-1).toUpperCase(); } else s1 = s.toUpperCase(); dir.prom.aspect = -1; for (i = 0; i < Horoscope.aspectTextShort.length; i++) if (Horoscope.aspectTextShort[i].equals(s1)) { dir.prom.aspect = i; break; } if (dir.prom.aspect == -1) if (s1.equals("QUA")) dir.prom.aspect = Horoscope.squ; // Freie Aspekt- oder Ekliptikstelle if (dir.prom.aspect == -1) if (s1.equals("=")) dir.prom.aspect = Horoscope.frp; if (dir.prom.aspect == -1) try { dir.prom.aspect = Horoscope.fra; dir.prom.angle = Double.parseDouble(s1); if (dir.prom.angle < 0) { dir.prom.aspectSign = '-'; dir.prom.angle = - dir.prom.angle; } else dir.prom.aspectSign = '+'; } catch (java.lang.NumberFormatException ex) { throw new ParseException("\""+s+"\" kann nicht als Aspekt interpretiert werden",2 ); } } if (!st.hasMoreTokens()) throw new ParseException("Bitte den Promissor eingeben",2); else { // Promissor bestimmen s = st.nextToken(); s1 = s.toUpperCase(); dir.prom.planet1 = dir.prom.planet2 = -1; if (dir.prom.aspect == Horoscope.frp) dir.prom.lon = Degree.getValue(s1); else { for (i = 0; i < Horoscope.planetTextShort.length; i++) if (Horoscope.planetTextShort[i].equals(s1)) { dir.prom.planet1 = i; break; } // Dann nach Hauskürzel for (i = 0; i < Horoscope.houseTextShort.length; i++) if (Horoscope.houseTextShort[i].equals(s1)) { dir.prom.planet1 = i + 1 + Horoscope.houseRange; break; } if (dir.prom.planet1==-1) // Alternative Abkürzungen für Aszendent if (s1.equals("AC")||s1.equals("AS")) dir.prom.planet1 = Horoscope.houseRange + 1; // Alternative Abkürzung für MC else { if (s1.equals("X")) dir.prom.planet1 = Horoscope.houseRange+10; else throw new ParseException("\""+s+"\" kann nicht als Promissor interpretiert werden",1 ); } } } dir.direct = true; if (st.hasMoreTokens()) { s = st.nextToken(); s1 = s.toUpperCase(); if (s1.equals("CONV")||s1.equals("C")||s1.equals("C.")||s1.equals("CONV.")) dir.direct = false; else if (s1.equals("DIR")||s1.equals("D")||s1.equals("D.")) dir.direct = true; else throw new ParseException("Kann \""+s+"\" nicht verstehen",4 ); } return dir; } public static Direction parseForm( String dirForm, Horoscope h) throws ParseException { Direction dir = parseForm( dirForm ); dir.ls = h.pl( dir.sig ); dir.bs = h.pb( dir.sig ); dir.prom.lon = AspectPoint.getLon(dir.prom,h); dir.prom.lat = 0d; return dir; } }