All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.innovativeastrosolutions.astrosoftcore.beans.PlanetaryInfo Maven / Gradle / Ivy

The newest version!
/**
 * PlanetaryInfo.java
 * Created On 2006, Feb 18, 2006 8:47:04 PM
 * @author E. Rajasekar
 */

package com.innovativeastrosolutions.astrosoftcore.beans;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;

import com.innovativeastrosolutions.astrosoftcore.beans.HousePosition.Bhava;
import com.innovativeastrosolutions.astrosoftcore.consts.Paksha;
import com.innovativeastrosolutions.astrosoftcore.consts.Varga;
import com.innovativeastrosolutions.astrosoftcore.consts.Karaka;
import com.innovativeastrosolutions.astrosoftcore.consts.Planet;
import com.innovativeastrosolutions.astrosoftcore.consts.Rasi;
import com.innovativeastrosolutions.astrosoftcore.core.VargaCharts;
import com.innovativeastrosolutions.astrosoftcore.util.AstroUtil;
import com.innovativeastrosolutions.astrosoftcore.util.ComparableEntry;
import com.innovativeastrosolutions.astrosoftcore.util.Mod;
import com.innovativeastrosolutions.astrosoftcore.util.Utils;

public class PlanetaryInfo {

	private static final Logger log = Logger.getLogger(PlanetaryInfo.class.getName());
	
	/*
	 * public static enum Info{ Position, Direction, Rasi, Location,
	 * BhavaLocation, Nakshathra, Karaka; }
	 */
	private EnumMap planetPosition;

	private EnumMap planetRasiPosition;

	private EnumMap planetDirection;

	private EnumMap planetRasi;

	private EnumMap planetLocation;

	private EnumMap planetBhava;

	private EnumMap planetNakshathra;

	private EnumMap planetKaraka;

	private EnumMap> divChart;
	
	// True means benefic... false means malefic
	private Map planetCharacter;

	private Mod mod = new Mod(12);

	public PlanetaryInfo(EnumMap planetPosition,
			EnumMap planetDirection, HousePosition housePosition) {
		
		this.planetPosition = planetPosition;
		this.planetDirection = planetDirection;
		planetPosition.put(Planet.Ascendant, housePosition
				.getAscendantPosition());

		VargaCharts vc = new VargaCharts(planetPosition, housePosition);

		divChart = vc.getAllCharts();

		planetRasi = new EnumMap(Planet.class);

		planetNakshathra = new EnumMap(Planet.class);

		planetBhava = new EnumMap(Planet.class);

		planetLocation = new EnumMap(Planet.class);

		planetRasiPosition = new EnumMap(Planet.class);

		planetKaraka = new EnumMap(Planet.class);

		List> rasiPositions = new ArrayList>();

		int lagna = housePosition.getAscendant().ordinal() + 1;

		for (Planet p : Planet.planetsAsc()) {

			planetRasi.put(p, Rasi.ofIndex(divChart.get(Varga.Rasi).get(p) - 1));
			planetNakshathra.put(p, new NakshathraPada(planetPosition.get(p)));
			planetLocation.put(p, mod.sub(divChart.get(Varga.Rasi).get(p), lagna) + 1);
			planetBhava.put(p, housePosition.getBhava(mod.sub(divChart.get(Varga.Bhava).get(p), lagna) + 1));
			planetRasiPosition.put(p, planetPosition.get(p) % 30);
			if (!p.isNode() && !p.isAsc()) {
				rasiPositions.add(new ComparableEntry(p,
						planetRasiPosition.get(p)));
			}
		}

		rasiPositions = Utils.sortEntryList(rasiPositions, true);

		int i = 0;
		for (ComparableEntry entry : rasiPositions) {

			planetKaraka.put(entry.getKey(), Karaka.ofIndex(i++));
		}
		
		calcPlanetCharacter();

	}

	

	/**
	 * @return Returns the planetPosition.
	 */
	public EnumMap getPlanetPosition() {
		return planetPosition;
	}

	/**
	 * @return Returns the planetDirection.
	 */
	public EnumMap getPlanetDirection() {
		return planetDirection;
	}

	/**
	 * @return Returns the planetRasi.
	 */
	public EnumMap getPlanetRasi() {
		return planetRasi;
	}
	
	/**
	 * @return Returns the planetRasi.
	 */
	public EnumMap getPlanetRasi(Varga varga) {
		
		if (varga.equals(Varga.Rasi)){
			return planetRasi;
		}
		EnumMap planetInRasi = new EnumMap(Planet.class);
		
		for (Planet p : Planet.planetsAsc()) {
			
			planetRasi.put(p, Rasi.ofIndex(divChart.get(varga).get(p) - 1));
		}
		
		return planetInRasi;
	}

	/**
	 * @return Returns the planetLocation.
	 */
	public EnumMap getPlanetLocation() {
		return planetLocation;
	}
	
	public EnumMap getPlanetLocation(Varga varga) {
		
		if (varga.equals(Varga.Rasi)){
			return planetLocation;
		}
		
		int lagna = divChart.get(varga).get(Planet.Ascendant);
		
		log.fine("Lagna "  + lagna);
		
		EnumMap location = new EnumMap(Planet.class);
		
		for (Planet p : Planet.planetsAsc()) {
			
			location.put(p, mod.sub(divChart.get(varga).get(p), lagna) + 1);
		}
		
		return location;
	}

	/**
	 * @return Returns the planetBhava.
	 */
	public EnumMap getPlanetBhava() {
		return planetBhava;
	}

	/**
	 *            The planetNakshathra to set.
	 */
	public void setPlanetNakshathra(EnumMap nakshathara) {
		this.planetNakshathra = nakshathara;
	}

	/**
	 * @return Returns the planetNakshathra.
	 */
	public EnumMap getPlanetNakshathra() {
		return planetNakshathra;
	}

	/**
	 * @return Returns the planetKaraka.
	 */
	public EnumMap getPlanetKaraka() {
		return planetKaraka;
	}

	public static EnumMap positionToRasiNum(EnumMap position){
		
		EnumMap planetRasiNum = new EnumMap(Planet.class);
		
		for(Entry e : position.entrySet()){
			planetRasiNum.put(e.getKey(), (int)(e.getValue() / 30) + 1);
		}
		
		return planetRasiNum;
	}
	
	private void calcPlanetCharacter() {
		
		planetCharacter = new EnumMap(Planet.class);
		for(Planet p : Planet.subaPlanets()){
			planetCharacter.put(p, true);
		}
		for(Planet p : Planet.papaPlanets()){
			planetCharacter.put(p, false);
		}
		
		Paksha pak = Paksha.ofDeg(getPlanetPosition(Planet.Sun),getPlanetPosition(Planet.Moon));
		planetCharacter.put(Planet.Moon, pak.isShukla());
		
		//System.out.println(planetCharacter);
	}
	
	public Double getPlanetPosition(Planet planet) {

		return planetPosition.get(planet);
	}

	/**
	 * @return Returns the planetRasiPosition.
	 */
	public EnumMap getPlanetRasiPosition() {
		return planetRasiPosition;
	}

	public Double getPlanetRasiPosition(Planet planet) {
		return planetRasiPosition.get(planet);
	}

	public EnumMap> getDivChart() {
		return divChart;
	}

	public EnumMap getDivChart(Varga varga) {
		return divChart.get(varga);
	}
	
	public Map getPlanetCharacter() {
		return planetCharacter;
	}



	@Override
	public String toString() {

		StringBuilder sb = new StringBuilder();

		for (Planet p : Planet.planetsAsc()) {
			sb.append(p + "\t" + AstroUtil.dms(planetPosition.get(p)) + "\t"
					+ planetRasiPosition.get(p) + "\t");
			if (planetKaraka.containsKey(p)) {
				sb.append(planetKaraka.get(p));
			}
			sb.append("\n");
		}

		sb.append("\n");
		sb.append("Charts\n" + VargaCharts.toString(divChart));
		sb.append("\n");
		return sb.toString();
	}





}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy