Skip to content
Browse files

- minor changes to EuroFormatter

  • Loading branch information...
1 parent 6419cbc commit dca1146195fd9905b932d66109c7cc41ccb060fc @alexbiehl alexbiehl committed Mar 27, 2013
View
11 src/main/java/org/fhw/asta/kasse/client/common/EuroFormatter.java
@@ -12,18 +12,13 @@ public static String format(EuroAmount euroAmount) {
return format(euroAmount.getCentAmount());
}
- public static String format(int euroAmount){
+ private static String format(int euroAmount){
return EURO_NUMBER_FORMAT.format(euroAmount / 100.0);
}
- public static String formatWithDiscount(int euroAmount, int discount)
- {
- return format((int)Math.round((euroAmount *((100-discount)/100.0))));
- }
-
public static String formatWithDiscount(EuroAmount euroAmount, int discount)
{
- return formatWithDiscount(euroAmount.getCentAmount(),discount);
+ return format(euroAmount.withDiscount(discount));
}
-
+
}
View
4 src/main/java/org/fhw/asta/kasse/client/widget/basket/BasketWidgetImpl.java
@@ -131,8 +131,8 @@ public PriceTextColumn() {
}
@Override
- public String getValue(BasketItem object) {
- return EuroFormatter.formatWithDiscount(object.getItemPrice().getCentAmount() * object.getAmount(),object.getDiscount());
+ public String getValue(BasketItem bi) {
+ return EuroFormatter.formatWithDiscount(bi.getItemPrice().times(bi.getAmount()), bi.getDiscount());
}
}
View
3 src/main/java/org/fhw/asta/kasse/server/dao/ArticleDao.java
@@ -18,8 +18,7 @@
public Article mapRow(final ResultSet arg0, final int arg1)
throws SQLException {
return new Article(arg0.getInt(1), arg0.getInt(2),
- arg0.getString(3), arg0.getString(4), new EuroAmount(
- arg0.getInt(5)), arg0.getString(6), arg0.getInt(7),
+ arg0.getString(3), arg0.getString(4), EuroAmount.create(arg0.getInt(5)), arg0.getString(6), arg0.getInt(7),
arg0.getBoolean(8));
}
}
View
3 src/main/java/org/fhw/asta/kasse/server/dao/BillOrderDao.java
@@ -42,8 +42,7 @@ public BillOrder mapRow(final ResultSet arg0, final int arg1)
@Override
public BasketItem mapRow(ResultSet arg0, int arg1) throws SQLException {
// TODO Auto-generated method stub
- return new BasketItem(arg0.getString(1), new EuroAmount(
- arg0.getInt(2)), arg0.getInt(3), arg0.getInt(4),
+ return new BasketItem(arg0.getString(1), EuroAmount.create(arg0.getInt(2)), arg0.getInt(3), arg0.getInt(4),
arg0.getInt(5));
}
}
View
27 src/main/java/org/fhw/asta/kasse/shared/common/EuroAmount.java
@@ -9,23 +9,29 @@
public static final EuroAmount ZERO_AMOUNT = new EuroAmount(0);
private int cents;
-
+
+ public static EuroAmount create(EuroAmount euroAmount) {
+ return new EuroAmount(euroAmount.cents);
+ }
+
+ public static EuroAmount create(int cents) {
+ return new EuroAmount(cents);
+ }
public EuroAmount()
{
this(0);
};
-
- public EuroAmount(final int cents)
+
+ private EuroAmount(final int cents)
{
this.cents = cents;
}
- public int getCentAmount()
- {
- return this.cents;
+ public int getCentAmount() {
+ return cents;
}
-
+
public EuroAmount plus(final EuroAmount summand)
{
return new EuroAmount(this.cents + summand.cents);
@@ -36,11 +42,6 @@ public EuroAmount minus(final EuroAmount subtrahend)
return new EuroAmount(this.cents - subtrahend.cents);
}
- public EuroAmount times(final float factor)
- {
- return new EuroAmount((int) (this.cents * factor));
- }
-
public EuroAmount times(final int factor)
{
return new EuroAmount(this.cents * factor);
@@ -49,5 +50,5 @@ public EuroAmount times(final int factor)
public EuroAmount withDiscount(int discount) {
return new EuroAmount((int) Math.round(cents * ((double)(100.0 - discount) / 100)));
}
-
+
}

0 comments on commit dca1146

Please sign in to comment.
Something went wrong with that request. Please try again.