2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altoslib_7;
22 public abstract class AltosUnits {
24 public abstract double value(double v, boolean imperial_units);
26 public abstract double inverse(double v, boolean imperial_units);
28 public abstract String show_units(boolean imperial_units);
30 public abstract String say_units(boolean imperial_units);
32 public abstract int show_fraction(int width, boolean imperial_units);
34 public double parse_locale(String s, boolean imperial_units) throws ParseException {
35 double v = AltosParse.parse_double_locale(s);
36 return inverse(v, imperial_units);
39 public double parse_net(String s, boolean imperial_units) throws ParseException {
40 double v = AltosParse.parse_double_net(s);
41 return inverse(v, imperial_units);
44 public double parse_locale(String s) throws ParseException {
45 return parse_locale(s, AltosConvert.imperial_units);
48 public double parse_net(String s) throws ParseException {
49 return parse_net(s, AltosConvert.imperial_units);
52 public double value(double v) {
53 return value(v, AltosConvert.imperial_units);
56 public double inverse(double v) {
57 return inverse(v, AltosConvert.imperial_units);
60 public String show_units() {
61 return show_units(AltosConvert.imperial_units);
64 public String say_units() {
65 return say_units(AltosConvert.imperial_units);
68 public int show_fraction(int width) {
69 return show_fraction(width, AltosConvert.imperial_units);
72 int say_fraction(boolean imperial_units) {
76 private String show_format(int width, boolean imperial_units) {
77 return String.format("%%%d.%df %s", width, show_fraction(width, imperial_units), show_units(imperial_units));
80 private String say_format(boolean imperial_units) {
81 return String.format("%%1.%df", say_fraction(imperial_units));
84 private String say_units_format(boolean imperial_units) {
85 return String.format("%%1.%df %s", say_fraction(imperial_units), say_units(imperial_units));
88 public String graph_format(int width, boolean imperial_units) {
89 return String.format(String.format("%%%d.%df", width, show_fraction(width, imperial_units)), 0.0);
92 public String graph_format(int width) {
93 return graph_format(width, AltosConvert.imperial_units);
96 public String show(int width, double v, boolean imperial_units) {
97 return String.format(show_format(width, imperial_units), value(v, imperial_units));
100 public String show(int width, double v) {
101 return show(width, v, AltosConvert.imperial_units);
104 public String say(double v, boolean imperial_units) {
105 return String.format(say_format(imperial_units), value(v, imperial_units));
108 public String say(double v) {
109 return say(v, AltosConvert.imperial_units);
112 public String say_units(double v, boolean imperial_units) {
113 return String.format(say_units_format(imperial_units), value(v, imperial_units));
116 public String say_units(double v) {
117 return say_units(v, AltosConvert.imperial_units);