1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.units.internal.deprecated;
14 import java.util.ArrayList;
16 import org.simantics.databoard.units.internal.UnitParseException;
17 import org.simantics.databoard.units.internal.parser.UnitParser;
23 public Unit(UnitPart ... parts) {
28 public String toString() {
29 StringBuilder b = new StringBuilder();
34 public void toString(StringBuilder b) {
38 for(int i=0;i<parts.length;++i) {
45 public static Unit parse(String string) throws UnitParseException {
46 final ArrayList<UnitPart> parts = new ArrayList<UnitPart>();
47 UnitParser parser = new UnitParser() {
50 public void visit(String baseUnit, int exponent) {
51 parts.add(new UnitPart(baseUnit, Magnitude.unscaled, exponent));
55 parser.unit(string, 1);
56 return new Unit(parts.toArray(new UnitPart[parts.size()]));
59 public static void main(String[] args) {
61 System.out.println(parse("m2/(s3/s)"));
62 } catch (UnitParseException e) {
63 // TODO Auto-generated catch block