Advertisement
ruiborges

Classe Cache

Jan 18th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.31 KB | None | 0 0
  1. import java.time.LocalDate;
  2.  
  3. public class Cache {
  4.     private String code;
  5.     private String name;
  6.     private String state;
  7.     private String owner;
  8.     private double latitude;
  9.     private double longitude;
  10.     private CacheType kind;
  11.     private CacheSize size;
  12.     private double difficulty;
  13.     private double terrain;
  14.     private boolean isAvailable;
  15.     private LocalDate hiddenDate;
  16.     private int encontrado;
  17.     private int naoEncontrado;
  18.     private int favoritos;
  19.     private int altitude;
  20.  
  21.     public Cache(String code, String name, String state, String owner, double latitude, double longitude, CacheType kind, CacheSize size, double difficulty, double terrain, boolean isAvailable, LocalDate hiddenDate, int encontrado, int naoEncontrado, int favoritos, int altitude) {
  22.         this.code = code;
  23.         this.name = name;
  24.         this.state = state;
  25.         this.owner = owner;
  26.         this.latitude = latitude;
  27.         this.longitude = longitude;
  28.         this.kind = kind;
  29.         this.size = size;
  30.         this.difficulty = difficulty;
  31.         this.terrain = terrain;
  32.         this.isAvailable = isAvailable;
  33.         this.hiddenDate = hiddenDate;
  34.         this.encontrado = encontrado;
  35.         this.naoEncontrado = nãoEncontrado;
  36.         this.favoritos = favoritos;
  37.         this.altitude = altitude;
  38.     }
  39.  
  40.     public String getCode() {
  41.         return code;
  42.     }
  43.  
  44.     public void setCode(String code) {
  45.         if (code.length() > 11) {
  46.             code = "XXXXXXXXXXX";
  47.         }
  48.         this.code = code;
  49.  
  50.     }
  51.  
  52.     public String getName() {
  53.         return name;
  54.     }
  55.  
  56.     public void setName(String name) {
  57.         if (name == null) throw new IllegalArgumentException("O nome não pode ser nulo");
  58.         this.name = name;
  59.     }
  60.  
  61.     public String getState() {
  62.         return state;
  63.     }
  64.  
  65.     public void setState(String state) {
  66.         if (state == null) throw new IllegalArgumentException("A localização não pode ser nulo");
  67.         this.state = state;
  68.     }
  69.  
  70.     public String getOwner() {
  71.         return owner;
  72.     }
  73.  
  74.     public void setOwner(String owner) {
  75.         if (owner == null) throw new IllegalArgumentException("O dono da cache não pode ser nulo");
  76.         this.owner = owner;
  77.     }
  78.  
  79.     public double getLatitude() {
  80.         return latitude;
  81.     }
  82.  
  83.     public void setLatitude(double latitude) {
  84.         if (latitude < -90 && latitude > 90) throw new IllegalArgumentException("Latitude inválida");
  85.         this.latitude = latitude;
  86.     }
  87.  
  88.     public double getLongitude() {
  89.         return longitude;
  90.     }
  91.  
  92.     public void setLongitude(double longitude) {
  93.         if (longitude < -180 && longitude > 180) throw new IllegalArgumentException("Longitude inválida");
  94.         this.longitude = longitude;
  95.     }
  96.  
  97.     public CacheType getKind() {
  98.         return kind;
  99.     }
  100.  
  101.     public void setKind(CacheType kind) {
  102.         if (kind == null) throw new IllegalArgumentException("Tipo de cache inválido");
  103.         this.kind = kind;
  104.     }
  105.  
  106.     public CacheSize getSize() {
  107.         return size;
  108.     }
  109.  
  110.     public void setSize(CacheSize size) {
  111.         if (size == null) throw new IllegalArgumentException("Tamanho de cache inválido");
  112.         this.size = size;
  113.     }
  114.  
  115.     public double getDifficulty() {
  116.         return difficulty;
  117.     }
  118.  
  119.     public void setDifficulty(double difficulty) {
  120.         if (difficulty < 0 || difficulty > 5.0)
  121.             if (kind == null) throw new IllegalArgumentException("Dificuldade inválida");
  122.         this.difficulty = difficulty;
  123.     }
  124.  
  125.     public double getTerrain() {
  126.         return terrain;
  127.     }
  128.  
  129.     public void setTerrain(double terrain) {
  130.         if (terrain < 0 || terrain > 5.0) if (kind == null) throw new IllegalArgumentException("Terreno inválido");
  131.         this.terrain = terrain;
  132.     }
  133.  
  134.     public boolean isAvailable() {
  135.         return isAvailable;
  136.     }
  137.  
  138.     public void setAvailable(boolean available) {
  139.         isAvailable = available;
  140.     }
  141.  
  142.     public LocalDate getHiddenDate() {
  143.         return hiddenDate;
  144.     }
  145.  
  146.     public void setHiddenDate(LocalDate hiddenDate) {
  147.         if (hiddenDate == null || hiddenDate.compareTo(LocalDate.now()) > 1)
  148.             throw new IllegalArgumentException("Data inválida");
  149.         this.hiddenDate = hiddenDate;
  150.     }
  151.  
  152.     public int getEncontrado() {
  153.         return encontrado;
  154.     }
  155.  
  156.     public void setEncontrado(int encontrado) {
  157.         if (encontrado < 0)
  158.             throw new IllegalArgumentException("Encontrado tem de ser 0 ou superior");
  159.         this.encontrado = encontrado;
  160.     }
  161.  
  162.     public int getNaoEncontrado() {
  163.         return naoEncontrado;
  164.     }
  165.  
  166.     public void setNaoEncontrado(int naoEncontrado) {
  167.         if (naoEncontrado < 0)
  168.             throw new IllegalArgumentException("Não encontrado tem de ser 0 ou superior");
  169.         this.naoEncontrado = naoEncontrado;
  170.     }
  171.  
  172.     public int getFavoritos() {
  173.         return favoritos;
  174.     }
  175.  
  176.     public void setFavoritos(int favoritos) {
  177.         if (favoritos < 0)
  178.             throw new IllegalArgumentException("Favorito tem de ser 0 ou superior");
  179.  
  180.         this.favoritos = favoritos;
  181.     }
  182.  
  183.     public int getAltitude() {
  184.         return altitude;
  185.     }
  186.  
  187.     public void setAltitude(int altitude) {
  188.         this.altitude = altitude;
  189.     }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement