@Nonnull public Address toAddress() { return Address.builder().withStreet(street) .withCity(city) .withZip(zip) .withState(state) .withCountry(country) .create(); } }
public AddressXml (final @Nonnull Address address) { this.street = address.getStreet(); this.city = address.getCity(); this.zip = address.getZip(); this.state = address.getState(); this.country = address.getCountry(); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ protected Address (final @Nonnull Builder builder) { this.street = builder.getStreet(); this.city = builder.getCity(); this.zip = builder.getZip(); this.state = builder.getState(); this.country = builder.getCountry(); } }
@Test public void greaterThan_and_lowerThan_must_work_at_the_opposite() { final Money greater = new Money(349, "EUR"); final Money lower = new Money(130, "EUR"); assertThat(greater.greaterThan(lower), is(true)); assertThat(greater.lowerThan(lower) , is(false)); assertThat(lower.greaterThan(greater), is(false)); assertThat(lower.lowerThan(greater), is(true)); }
@Nonnull public Money subtract (final @Nonnull Money other) { checkCurrencies(other); return new Money(amount.subtract(other.amount), currency); }
public boolean isEqualTo (final @Nonnull Money other) { return compareTo(other) == 0; }
@Override @Nonnull public String marshal (final @Nonnull Money money) { return money.toString(); } }
@Override public int compareTo (final @Nonnull Money other) { checkCurrencies(other); return this.amount.compareTo(other.amount); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull public static Builder builder() { return new Builder("", "", "", "", ""); }
@Nonnull public Address create() { return new Address(this); } }
@Override @Nonnull public Money unmarshal (final @Nonnull String string) throws ParseException { return Money.parse(string); }
@Override @Nonnull public String toString() { return String.format("%s %s", getFormat().format(amount), currency); }
@Test public void toString_must_return_all_the_fields() { final Address a1 = Address.builder().withStreet("Foo Bar rd 20") .withCity("San Francisco") .withZip("12345") .withState("CA") .withCountry("USA") .create(); assertThat(a1.toString(), is("Address(street=Foo Bar rd 20, city=San Francisco, state=CA, country=USA, zip=12345)")); } }
@Test public void greaterThan_and_lowerThan_must_be_false_when_equality() { final Money m1 = new Money(349, "EUR"); final Money m2 = new Money(349, "EUR"); assertThat(m1.greaterThan(m2), is(false)); assertThat(m1.lowerThan(m2), is(false)); assertThat(m2.greaterThan(m1), is(false)); assertThat(m2.lowerThan(m1), is(false)); } }
@Nonnull public Money add (final @Nonnull Money other) { checkCurrencies(other); return new Money(amount.add(other.amount), currency); }
public boolean greaterThan (final @Nonnull Money other) { return compareTo(other) > 0; }
@Test public void toString_for_ZERO_must_be_properly_computed() { assertThat(Money.ZERO.toString(), is("0.00 EUR")); }
@Nonnegative public double divided (final @Nonnull Money other) { checkCurrencies(other); // Can fail with ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. // return amount.divide(other.amount).doubleValue(); return amount.doubleValue() / other.amount.doubleValue(); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull private Address getAddress (final @Nonnull Contact contact) { Address.Builder addressBuilder = Address.builder(); if (contact.getAddress() != null) { final corny.addressbook.data.Address addr = contact.getAddress().getFirstHomeValue(); addressBuilder = addressBuilder.withCity(addr.getCity()) .withState(addr.getCountry()) .withStreet(addr.getStreet()) .withZip("" + addr.getZip()); } return addressBuilder.create(); }
public boolean lowerThan (final @Nonnull Money other) { return compareTo(other) < 0; }