Android Open Source - AstroPhysCalc Length Unit






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;
/*  w w w  .j av a2  s. co m*/
public enum LengthUnit implements Unit {

  A("A", 1E-10d),
  NM("nm", 1E-9d),
  MIC_M("mic_m", 1E-6d),
  MM("mm", 1E-3d),
  CM("cm", 1E-2d),
  M("m", 1d),
  KM("km", 1E3d),
  AU("AU", 1.49598E11d),
  LY("ly", 9.46E15),
  KLY("kly", 9.46E18),
  MLY("mly", 9.46E21),
  GLY("gly", 9.46E24);

  private final String name;
  private final double ratioToBase;
  private final static LengthUnit base = M;

  LengthUnit(final String name, final double ratioToBase) {
    this.name = name;
    this.ratioToBase = ratioToBase;
  }

  public static LengthUnit getUnit(final String name) {
    LengthUnit[] units = LengthUnit.values();
    for (LengthUnit unit : units) {
      if (unit.getName().equals(name)) {
        return unit;
      }
    }
    return null;
  }

  @Override
  public String getName() {
    return name;
  }

  @Override
  public double inBaseUnits() {
    return ratioToBase;
  }

  @Override
  public Unit getBase() {
    return base;
  }

  @Override
  public boolean isSameBaseAs(Unit unit) {
    return unit instanceof LengthUnit;
  }

}




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