Examples of BigDec


Examples of lipstone.joshua.parser.types.BigDec

    abbreviatedPrefixes = new HashMap<String, String>();
    unitAbbreviations = new TreeMap<String, String>(new LengthComparison());
    allUnits = new SortedList<String>(new LengthComparison());
   
    //I know, but it is slightly faster than using an array and iterating through while converting to BigDec
    prefixes.put("yocto", new BigDec(-8));
    prefixes.put("zepto", new BigDec(-7));
    prefixes.put("atto", new BigDec(-6));
    prefixes.put("femto", new BigDec(-5));
    prefixes.put("pico", new BigDec(-4));
    prefixes.put("nano", new BigDec(-3));
    prefixes.put("micro", new BigDec(-2));
    prefixes.put("milli", new BigDec(-1));
    prefixes.put("mili", new BigDec(-1));
    prefixes.put("centi", new BigDec(-2.0 / 3.0));
    prefixes.put("deci", new BigDec(-1.0 / 3.0));
    prefixes.put("deca", new BigDec(1.0 / 3.0));
    prefixes.put("hecto", new BigDec(2.0 / 3.0));
    prefixes.put("milli", BigDec.ONE);
    prefixes.put("kilo", BigDec.ONE);
    prefixes.put("mega", new BigDec(2));
    prefixes.put("giga", new BigDec(3));
    prefixes.put("tera", new BigDec(4));
    prefixes.put("peta", new BigDec(5));
    prefixes.put("exa", new BigDec(6));
    prefixes.put("zetta", new BigDec(7));
    prefixes.put("yotta", new BigDec(8));
   
    abbreviatedPrefixes.put("y", "yocto");
    abbreviatedPrefixes.put("z", "zepto");
    abbreviatedPrefixes.put("a", "atto");
    abbreviatedPrefixes.put("f", "femto");
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    return getFactor(leftUnits).divide(getFactor(rightUnits));
  }
 
  private BigDec getFactor(ConsCell units) throws ParserException {
    ConsCell current = units;
    BigDec factor = BigDec.ONE;
    do {
      boolean divide = current.getPreviousConsCell().getCarType() == ConsType.OPERATOR && (char) current.getPreviousConsCell().getCar() == '/';
      BigDec partial;
      if (current.getCarType() == ConsType.IDENTIFIER) {
        String[] unit = stripPrefix((String) current.getCar());
        partial = this.units.get(unit[1]).getFactor();
        if (partial == null)
          throw new InvalidUnitException(current.getCar() + " is not a valid unit.", nl);
        if (unit[0].length() > 0)
          partial = partial.multiply(prefixes.get(unit[0]));
      }
      else if (current.getCarType() == ConsType.CONS_CELL) {
        ConsCell fact = parser.run(parser.preProcess((ConsCell) current.getCar()));
        if (fact.getCarType() != ConsType.NUMBER || fact.length() != 1)
          throw new InvalidUnitException(current.getCar() + " is not a valid unit set.", nl);
        partial = (BigDec) fact.getCar();
      }
      else
        continue;
      if (current.getNextConsCell().getCarType() == ConsType.OPERATOR && (char) current.getNextConsCell().getCar() == '^') {
        current.getNextConsCell().remove();
        ConsCell power = current.getNextConsCell().singular();
        if (power.getCarType() == ConsType.OPERATOR)
          power.append(current.getNextConsCell().remove().singular());
        else if (power.getCarType() == ConsType.CONS_CELL)
          power = (ConsCell) power.getCar();
        current.getNextConsCell().remove();
        power = parser.run(parser.preProcess(power));
        if (power.getCarType() != ConsType.NUMBER || power.length() != 1)
          throw new InvalidUnitException(current.getCar() + " is raised to an invalid power.", nl);
        partial = partial.pow((BigDec) power.getCar());
      }
      factor = divide ? factor.divide(partial) : factor.multiply(partial);
    } while (!(current = current.getNextConsCell()).isNull());
    return factor;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   
    //SI abbreviations
    addUnit("amp", "ampere", BigDec.ONE);
   
    //angle
    addUnit("degree", "radian", new BigDec(Math.PI / 180));
    addUnit("grad", "radian", new BigDec(Math.PI / 200));
   
    //distance
    addUnit("mile", "meter", new BigDec(1609.34), "mi");
    addUnit("f(o|e)\\1t", "meter", new BigDec(0.3048), "ft");
    addUnit("inch", "meter", new BigDec(0.0254), "in");
    addUnit("yard", "meter", new BigDec(0.9144), "yd");
    //compensates for plural
    addUnit("inche", "meter", new BigDec(0.0254));
   
    //volume
    addUnit("liter", "centimeter^3", new BigDec(1000), "L");
    addUnit("litre", "centimeter^3", new BigDec(1000));
   
    //time
    addUnit("minute", "second", new BigDec(60));
    addUnit("hour", "minute", new BigDec(60), "hr");
    addUnit("day", "hour", new BigDec(24));
    addUnit("week", "day", new BigDec(7));
    addUnit("month", "day", new BigDec(30));
    addUnit("year", "day", new BigDec(365), "yr");
   
    //mass
    addUnit("slug", "gram", new BigDec(14593.9029));
   
    //temperature
    addUnit("rankine", "kelvin", new BigDec(1.8));
    //frequency
    addUnit("hertz", "second^(-1)", BigDec.ONE, "Hz");
    //force
    addUnit("newton", "kilogram meter per (second^2)", BigDec.ONE, "N");
    //pressure, stress
    addUnit("pascal", "newton per (meter^2)", BigDec.ONE, "Pa");
    addUnit("psi", "pascal", new BigDec(6894.75729));
   
    //energy, work, heat
    addUnit("joule", "newton meter", BigDec.ONE, "J");
    addUnit("calorie", "joule", new BigDec(4.184), "cal");
    addUnit("Calorie", "calorie", new BigDec(1000), "Cal");
   
    //power, radiant flux
    addUnit("watt", "joule per (second)", BigDec.ONE, "W");
    //electric charge, quantity of electricity
    addUnit("coulomb", "second ampere", BigDec.ONE, "C");
    //voltage, electrical potential difference, electromotive force
    addUnit("volt", "joule per (coulomb)", BigDec.ONE, "V");
    //electric capacitance
    addUnit("farad", "coulomb per (volt)", BigDec.ONE, "F");
    //electric resistance, impedance, reactance
    addUnit("ohm", "volt per (ampere)", BigDec.ONE);
    //electrical conductance
    addUnit("siemens", "ohm^(-1)", BigDec.ONE, "S");
    //magnetic flux
    addUnit("weber", "joule per (ampere)", BigDec.ONE, "Wb");
    //magnetic field strength, magnetic flux density
    addUnit("tesla", "volt second per (meter^2)", BigDec.ONE, "T");
    //inductance
    addUnit("henry", "volt second per (ampere)", BigDec.ONE, "H");
    //luminous flux
    addUnit("lumen", "candela", BigDec.ONE, "lm");
    //illuminance
    addUnit("lux", "lumen per (meter^2)", BigDec.ONE, "lx");
    //radioactivity (decays per unit time)
    addUnit("becquerel", "second^(-1)", BigDec.ONE, "Bq");
    //absorbed dose (of ionizing radiation)
    addUnit("gray", "joule per (kilogram)", BigDec.ONE, "Gy");
    //equivalent dose (of ionizing radiation)
    addUnit("sievert", "coulomb per (volt)", BigDec.ONE, "Sv");
    //catalytic activity
    addUnit("katal", "mole per (second)", BigDec.ONE, "kat");
   
    //data
    addUnit("bit", "byte", new BigDec(0.125));
    addUnit("nibble", "byte", new BigDec(0.5));
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    while (num.charAt(0) == '0' && num.charAt(1) != '.')
      num = num.substring(1);
    if (num.length() > 1) {
      for (int i = 0; i < num.length(); i++)
        if (parser.isNumber(num.charAt(i)) && num.charAt(i) != '0' && num.charAt(i) != '.') {
          parts[1] = new BigDec(num.indexOf('.') - i - 1).toString();
          break;
        }
      parts[0] = num.substring(0, 1) + "." + num.substring(1).replaceAll("\\Q.\\E", "");
    }
    else
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   *            an equivalent unit (preferably in the SI system)
   * @param factor
   *            the conversion factor between this unit and the unit in SI
   */
  public void addUnit(String name, String SI, String factor) {
    addUnit(name, SI, new BigDec(factor.trim()));
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   *            the conversion factor between this unit and the unit in SI
   * @param abbriviation
   *            the abbreviation for this unit
   */
  public void addUnit(String name, String SI, String factor, String... abbriviation) {
    addUnit(name, SI, new BigDec(factor.trim()), abbriviation);
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   * @throws ParserException
   */
  public NumberSet(String list) throws ParserException {
    ArrayList<String> items = Parser.fromCommaList(list);
    for (String item : items)
      set.add(new BigDec(item));
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   * @param items
   *            the values to initially add to this <tt>NumberSet</tt>
   */
  public NumberSet(Double[] items) {
    for (Double item : items)
      set.add(new BigDec(item.toString()));
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   * @param items
   *            the values to initially add to this <tt>NumberSet</tt>
   */
  public NumberSet(Integer[] items) {
    for (Integer item : items)
      set.add(new BigDec(item.toString()));
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   * @throws UndefinedResultException
   */
  public BigDec getMean() throws UndefinedResultException {
    if (set.size() <= 0)
      return BigDec.ZERO;
    BigDec total = BigDec.ZERO;
    for (BigDec d : set)
      total = total.add(d);
    return total.divide(new BigDec(set.size()));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.