Skip to content

Commit 9329d0f

Browse files
committed
UnitParser 1.0.9.0 branch creation.
1 parent b9fd3f5 commit 9329d0f

File tree

679 files changed

+307
-149445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

679 files changed

+307
-149445
lines changed

README.md

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,128 @@
1-
# FlexibleParser (Java)
1+
# UnitParser (Java)
22

3-
[![Build Status](https://travis-ci.org/varocarbas/FlexibleParser_Java.svg?branch=master)](https://travis-ci.org/varocarbas/FlexibleParser_Java)
3+
[Master source code](https://github.com/varocarbas/FlexibleParser_Java/tree/master/all_code/UnitParser) -- [Test program](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/Test/src/Parts/UnitParser.java)
44

5-
**NOTE:** this is the conversion to Java of the original C# code stored in the [FlexibleParser repository](https://github.com/varocarbas/FlexibleParser).
5+
[https://customsolvers.com/unit_parser_java/](https://customsolvers.com/unit_parser_java/) (ES: [https://customsolvers.com/unit_parser_java_es/](https://customsolvers.com/unit_parser_java_es/))
66

7-
FlexibleParser is a multi-purpose parsing library based upon the following ideas:
7+
## Introduction
8+
The main class is called ```UnitP``` (```UnitParser``` package). It can be instantiated in many different ways.
89

9-
- Intuitive, adaptable and easy to use.
10-
- Pragmatic, but aiming for the maximum accuracy and correctness.
11-
- Overall compatible and easily automatable.
12-
- Formed by independent JARs managing specific situations.
10+
```Java
11+
//1 N.
12+
UnitP unitP = new UnitP("1 N");
1313

14-
## Parts
14+
//1 N.
15+
unitP = new UnitP(1.0, UnitSymbols.Newton);
1516

16-
At the moment, FlexibleParser is formed by the following independent parts:
17+
//1 N.
18+
unitP = new UnitP(1.0, "nEwTon");
1719

18-
[UnitParser](https://customsolvers.com/unit_parser_java/) ([main code](https://github.com/varocarbas/FlexibleParser_Java/tree/master/all_code/UnitParser), [test program](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/Test/src/Parts/UnitParser.java), [readme file](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_readme/UnitParser_Java.md))<br/>
19-
It allows to easily deal with a wide variety of situations involving units of measurement.
20-
Among its most salient features are: user-defined exception triggering and gracefully managing numeric values of any size.
20+
//1 N.
21+
unitP = new UnitP(1.0, Units.Newton);
22+
```
2123

24+
```UnitP``` can be seen as an abstract concept including many specific types ([full list](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/UnitParser/src_Public/UnitParser/UnitTypes.java)). Same-type variables can be added/subtracted. Different-type variables can be multiplied/divided, but only in case of generating a valid-type output.
25+
26+
```Java
27+
//2 N.
28+
unitP = UnitP.Addition(new UnitP("1 N"), new UnitP(1.0, Units.Newton));
29+
30+
//1 J.
31+
unitP = UnitP.Multiplication(new UnitP("1 N"), new UnitP("1 m"));
32+
33+
//Error not triggering an exception.
34+
//The output unit N*m^2 doesn't match any supported type.
35+
unitP = UnitP.Multiplication
36+
(
37+
UnitP.Multiplication
38+
(
39+
new UnitP("1 N"), new UnitP("1 m")
40+
),
41+
new UnitP("1 m")
42+
);
43+
```
44+
45+
### Main Variable Information
46+
```UnitP``` variables are defined according to various ```final``` fields populated at instantiation.
47+
48+
```Unit``` - Corresponding [Units](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/UnitParser/src_Public/UnitParser/Units.java) member.<br>
49+
```UnitType``` - Corresponding [UnitTypes](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/UnitParser/src_Public/UnitParser/UnitTypes.java) member.<br>
50+
```UnitSystem``` - Corresponding [UnitSystems](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/UnitParser/src_Public/UnitParser/UnitSystems.java) member.<br>
51+
```UnitParts``` - Defining parts of the given unit.<br>
52+
```UnitPrefix``` - [Supported prefix](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/UnitParser/src_Public/UnitParser/Prefix.java) affecting all the unit parts.<br>
53+
```BaseTenExponent``` - Base-ten exponent used when dealing with too small/big values.<br>
54+
```Error``` - Variable storing all the error- and exception-related information.
55+
56+
## General Rules
57+
58+
All the functionalities are based upon the following ideas:
59+
- In case of incompatibility, the first element is always preferred.
60+
- By default, the formally-correct alternative is preferred. Some required modifications might be performed.
61+
- By default, all the errors are managed internally.
62+
63+
```Java
64+
//1.3048.
65+
unitP = UnitP.Addition(new UnitP("1 m"), new UnitP("1 ft"));
66+
67+
//Error not triggering an exception.
68+
//The parser expects "km" or a full-name-based version like "KiLom".
69+
unitP = new UnitP("1 Km");
70+
71+
//999999.9999999001*10^19 YSt.
72+
unitP = UnitP.Multiplication
73+
(
74+
999999999999999999999999999999999999.9,
75+
new UnitP("9999999999999 St")
76+
);
77+
```
78+
79+
## Unit String Parsing Format
80+
81+
The unit string parsing part is quite flexible, but there are some basic rules.
82+
- String multi-part units are expected to be exclusively formed by units, multiplication/division signs and integer exponents.
83+
- Only one division sign is expected. The parser understands that all what lies before/after it is the numerator/denominator.
84+
85+
```Java
86+
//1 W.
87+
unitP = new UnitP("1 J*J/s*J2*J-1*s*s-1");
88+
89+
//Error not triggering an exception.
90+
//The parser understands "J*J/(s*J2*s*J*s)", what doesn't represent a supported type.
91+
unitP = new UnitP("1 J*J/(s*J2*s)*J*s");
92+
```
93+
94+
## Numeric Support
95+
Formally, only the ```double``` type is supported. Practically, ```UnitP``` variables implement a mixed system delivering beyond-```double```-range support.
96+
97+
```Java
98+
//7.891011 ft.
99+
unitP = UnitP.Multiplication(new UnitP("1 ft"), 7.891011);
100+
101+
//1.213141516 Gs.
102+
unitP = UnitP.Multiplication(new UnitP("1 s"), 1213141516.0);
103+
104+
//0.0003094346047382587*10^-752 ym.
105+
unitP = UnitP.Division
106+
(
107+
UnitP.Division
108+
(
109+
UnitP.Division
110+
(
111+
UnitP.Multiplication
112+
(
113+
0.0000000000000000000000000000000000000000000000001,
114+
new UnitP(0.000000000000000000001, "ym2")
115+
),
116+
new UnitP("999999999999999999999 Ym")
117+
),
118+
Double.MAX_VALUE
119+
),
120+
Double.MAX_VALUE
121+
);
122+
```
123+
124+
## Further Code Samples
125+
The [test application](https://github.com/varocarbas/FlexibleParser_Java/blob/master/all_code/Test/src/Parts/UnitParser.java) includes a relevant number of descriptive code samples.
22126

23127
## Authorship & Copyright
24128

@@ -27,5 +131,4 @@ I, Alvaro Carballo Garcia (varocarbas), am the sole author of each single bit of
27131
Equivalently to what happens with all my other online contributions, this code can be considered public domain. For more information about my copyright/authorship attribution ideas, visit the corresponding pages of my sites:
28132
- https://customsolvers.com/copyright/<br/>
29133
ES: https://customsolvers.com/copyright_es/
30-
- https://varocarbas.com/copyright/<br/>
31-
ES: https://varocarbas.com/copyright_es/
134+
- https://varocarbas.com/copyright/<br/>ES: https://varocarbas.com/copyright_es/

0 commit comments

Comments
 (0)