Address.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * blueHour: open source accounting
  5.  * http://tidalwave.it/projects/bluehour
  6.  *
  7.  * Copyright (C) 2013 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/bluehour-src
  22.  * git clone https://github.com/tidalwave-it/bluehour-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.accounting.model.types;

  27. import javax.annotation.Nonnull;
  28. import javax.annotation.concurrent.Immutable;
  29. import lombok.AllArgsConstructor;
  30. import lombok.EqualsAndHashCode;
  31. import lombok.Getter;
  32. import lombok.ToString;
  33. import lombok.With;
  34. import static lombok.AccessLevel.PRIVATE;

  35. /***************************************************************************************************************************************************************
  36.  *
  37.  * This class models the address of a customer.
  38.  *
  39.  * @author Fabrizio Giudici
  40.  *
  41.  **************************************************************************************************************************************************************/
  42. @Immutable @Getter @EqualsAndHashCode @ToString
  43. public class Address
  44.   {
  45.     public static final Address EMPTY = builder().create();

  46.     @AllArgsConstructor(access = PRIVATE)
  47.     @Immutable @With @Getter @ToString
  48.     public static class Builder
  49.       {
  50.         private final String street;
  51.         private final String city;
  52.         private final String zip;
  53.         private final String state;
  54.         private final String country;

  55.         @Nonnull
  56.         public Address create()
  57.           {
  58.             return new Address(this);
  59.           }
  60.       }

  61.     @Nonnull
  62.     private final String street;

  63.     @Nonnull
  64.     private final String city;

  65.     @Nonnull
  66.     private final String state;

  67.     @Nonnull
  68.     private final String country;

  69.     @Nonnull
  70.     private final String zip;

  71.     /***********************************************************************************************************************************************************
  72.      *
  73.      **********************************************************************************************************************************************************/
  74.     @Nonnull
  75.     public static Builder builder()
  76.       {
  77.         return new Builder("", "", "", "", "");
  78.       }

  79.     /***********************************************************************************************************************************************************
  80.      *
  81.      **********************************************************************************************************************************************************/
  82.     protected Address (@Nonnull final Builder builder)
  83.       {
  84.         this.street = builder.getStreet();
  85.         this.city = builder.getCity();
  86.         this.zip = builder.getZip();
  87.         this.state = builder.getState();
  88.         this.country = builder.getCountry();
  89.       }
  90.   }