Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Hotfix: Gestione degli zeri dei decimali
Browse files Browse the repository at this point in the history
  • Loading branch information
EvaristeGalois11 committed Dec 12, 2018
1 parent 9423902 commit f7ff364
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.fxbuild
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ASCII"?>
<anttasks:AntTask xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:anttasks="http://org.eclipse.fx.ide.jdt/1.0" buildDirectory="${project}/build">
<deploy packagingFormat="none">
<application name="MathSupport" mainclass="it.nave.math.Main" version="1.1"/>
<application name="MathSupport" mainclass="it.nave.math.Main" version="1.2"/>
<info title="MathSupport" vendor="Navesoft"/>
</deploy>
<signjar/>
Expand Down
13 changes: 6 additions & 7 deletions src/it/nave/math/controller/FrazioniController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ private void genera() {

private void scriviFrazione(Fraction f) {
if (!f.getPeriodo().isPresent()) {
String numeratore = (f.getIntera().get().matches("0+") ? "" : f.getIntera().get())
+ f.getAntiperiodo().orElse("");
String intera = f.getIntera().get().replaceAll("^0+", "");
String antiperiodo = f.getAntiperiodo().orElse("").replaceAll("0+$", "");
String numeratore = intera + ((intera.isEmpty()) ? antiperiodo.replaceAll("^0+", "") : antiperiodo);
String denominatore = "1";
if (f.getAntiperiodo().isPresent()) {
long zero = f.getAntiperiodo().get().chars().count();
for (int i = 0; i < zero; i++) {
denominatore += "0";
}
long zero = antiperiodo.chars().count();
for (int i = 0; i < zero; i++) {
denominatore += "0";
}
numeratore1.setText(numeratore);
denominatore1.setText(denominatore);
Expand Down
21 changes: 10 additions & 11 deletions src/it/nave/math/data/Fraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ public class Fraction {
private Optional<String> periodo = Optional.empty();

public Fraction(String n) {
if (n.matches("\\d+")) {
n = n.trim().replace(",", ".").replace("(", "[").replace(")", "]");
if (n.matches("^\\d+$")) {
intera = Optional.of(n);
} else if (n.matches("\\d+[,.]\\d+")) {
String separator = (n.contains(".")) ? "\\." : ",";
String split[] = n.split(separator);
} else if (n.matches("^\\d+\\.\\d+$")) {
String split[] = n.split("\\.");
intera = Optional.of(split[0]);
antiperiodo = Optional.of(split[1]);
periodo = Optional.empty();
} else if (n.matches("\\d+[,.]\\[\\d+\\]$")) {
String separator = (n.contains(".")) ? "\\." : ",";
String split1[] = n.split(separator);
} else if (n.matches("^\\d+\\.\\[\\d+\\]$")) {
String split1[] = n.split("\\.");
intera = Optional.of(split1[0]);
String split2[] = split1[1].split("\\[");
antiperiodo = Optional.empty();
periodo = Optional.of(split2[1].replaceAll("\\]", ""));
} else if (n.matches("\\d+[,.]\\d+\\[\\d+\\]$")) {
String separator = (n.contains(".")) ? "\\." : ",";
String split1[] = n.split(separator);
} else if (n.matches("^\\d+\\.\\d+\\[\\d+\\]$")) {
String split1[] = n.split("\\.");
intera = Optional.of(split1[0]);
String split2[] = split1[1].split("\\[");
antiperiodo = Optional.of(split2[0]);
periodo = Optional.of(split2[1].replaceAll("\\]", ""));
String temp = split2[1].replaceAll("\\]", "");
periodo = (temp.matches("0+")) ? Optional.empty() : Optional.of(temp);
} else {
throw new IllegalArgumentException();
}
Expand Down

0 comments on commit f7ff364

Please sign in to comment.