Android Open Source - AstroPhysCalc Unit Spinner Item






From Project

Back to project page AstroPhysCalc.

License

The source code is released under:

Apache License

If you think the Android project AstroPhysCalc listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.astrophyscalc;
//from  w w  w. ja  v a 2s .c  o  m
public class UnitSpinnerItem {


  /**** Constants *****/

  // Orbits

  public static final UnitSpinnerItem[] ORBIT_MASS = {
        UnitSpinnerItem.create(UnitExpression.createFromUnit(MassUnit.M_EARTH), "Earths"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(MassUnit.M_JUP), "Jupiters"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(MassUnit.M_SUN), "Suns")
  };

  public static final UnitSpinnerItem[] ORBIT_RADIUS = {
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.KM), "km"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.AU), "AU"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.LY), "ly")
  };

  public static final UnitSpinnerItem[] ORBIT_PERIOD = {
        UnitSpinnerItem.create(UnitExpression.createFromUnit(TimeUnit.S), "s"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(TimeUnit.MIN), "minutes"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(TimeUnit.HR), "hours"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(TimeUnit.DAYS), "days"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(TimeUnit.YEARS), "years")
  };


  // Kinetic energy

  public static final UnitSpinnerItem[] KE_MASS = {
        UnitSpinnerItem.create(UnitExpression.createFromUnit(MassUnit.G), "g"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(MassUnit.KG), "kg")
    };

  public static final UnitSpinnerItem[] KE_ENERGY = {
        UnitSpinnerItem.create(UnitExpression.create(UnitAndDim.create(MassUnit.KG),
            UnitAndDim.create(LengthUnit.M, 2),
            UnitAndDim.create(TimeUnit.S, -2)), "J")
    };

  public static final UnitSpinnerItem[] KE_VELOCITY = {
        UnitSpinnerItem.create(UnitExpression.create(UnitAndDim.create(LengthUnit.M),
            UnitAndDim.create(TimeUnit.S, -1)), "m/s")
    };


  // Flux

  public static final UnitSpinnerItem[] FLUX_POWER = {
        UnitSpinnerItem.create(UnitExpression.create(
            UnitAndDim.create(MassUnit.KG),
            UnitAndDim.create(LengthUnit.M, 2),
            UnitAndDim.create(TimeUnit.S, -3)), "W"),
        UnitSpinnerItem.create(UnitExpression.create(
            UnitAndDim.create(MassUnit.T),
            UnitAndDim.create(LengthUnit.M, 2),
            UnitAndDim.create(TimeUnit.S, -3)), "KW"),
        UnitSpinnerItem.create(UnitExpression.create(
            UnitAndDim.create(MassUnit.KG),
            UnitAndDim.create(LengthUnit.KM, 2),
            UnitAndDim.create(TimeUnit.S, -3)), "MW"),
        UnitSpinnerItem.create(Constants.L_SUN, "Solar")
  };

  public static final UnitSpinnerItem[] FLUX_DISTANCE = {
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.M), "m"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.KM), "km"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.AU), "AU"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.LY), "ly"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.KLY), "kly"),
        UnitSpinnerItem.create(UnitExpression.createFromUnit(LengthUnit.MLY), "mly")
    };

  public static final UnitSpinnerItem[] FLUX = {
        UnitSpinnerItem.create(UnitExpression.create(
            UnitAndDim.create(MassUnit.KG),
            UnitAndDim.create(TimeUnit.S, -3)), "W/m^2"),
        UnitSpinnerItem.create(Constants.FS_EARTH, "Sun_Earth")
    };

  /****** End constants ******/


  private final ValueAndUnits vu;
  private final String label;

  public static UnitSpinnerItem create(final UnitExpression expr, final String label) {
    return new UnitSpinnerItem(1d, expr, label);
  }

  public static UnitSpinnerItem create(final double value, final UnitExpression expr, final String label) {
    return new UnitSpinnerItem(value, expr, label);
  }

  public static UnitSpinnerItem create(final ValueAndUnits vu, final String label) {
    return new UnitSpinnerItem(vu, label);
  }

  private UnitSpinnerItem(final double value, final UnitExpression expr, final String label) {
    this.vu = ValueAndUnits.create(value, expr);
    this.label = label;
  }

  private UnitSpinnerItem(final ValueAndUnits vu, final String label) {
    this.vu = vu;
    this.label = label;
  }

  public UnitExpression getUnitExpression() {
    return vu.getUnitExpression();
  }

  public ValueAndUnits getValueAndUnits() {
    return vu;
  }

  @Override
  public String toString() {
    return label;
  }

}




Java Source Code List

org.astrophyscalc.AstroPhysCalcActivity.java
org.astrophyscalc.CalcPage.java
org.astrophyscalc.CalcRow.java
org.astrophyscalc.Calculator.java
org.astrophyscalc.Constants.java
org.astrophyscalc.DimensionTest.java
org.astrophyscalc.Dimension.java
org.astrophyscalc.FractionTest.java
org.astrophyscalc.Fraction.java
org.astrophyscalc.LengthUnit.java
org.astrophyscalc.MassUnit.java
org.astrophyscalc.TimeUnitTest.java
org.astrophyscalc.TimeUnit.java
org.astrophyscalc.UnitAndDimTest.java
org.astrophyscalc.UnitAndDim.java
org.astrophyscalc.UnitExpressionTest.java
org.astrophyscalc.UnitExpression.java
org.astrophyscalc.UnitSelectionRule.java
org.astrophyscalc.UnitSelector.java
org.astrophyscalc.UnitSpinnerItem.java
org.astrophyscalc.UnitUtilTest.java
org.astrophyscalc.UnitUtil.java
org.astrophyscalc.Unit.java
org.astrophyscalc.ValueAndUnitsTest.java
org.astrophyscalc.ValueAndUnits.java