gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
6971b1c30e51cf4d0a56fa7f6ad12db0d49d56c7
[spa2-materijali.git] / Stabla / StabloOpstegTipa / Osoba.java
1 import java.util.Objects;
3 // Tip podataka koji predstavlja jednu osobu
4 public class Osoba {
6 private final String ime;
7 private final String prezime;
8 private final int godinaRodjenja;
10 public Osoba(String ime, String prezime, int godinaRodjenja) {
11 if (ime == null) {
12 throw new IllegalArgumentException("ime");
13 }
14 this.ime = ime;
15 if (prezime == null) {
16 throw new IllegalArgumentException("prezime");
17 }
18 this.prezime = prezime;
19 this.godinaRodjenja = godinaRodjenja;
20 }
22 public String getIme() {
23 return ime;
24 }
26 public String getPrezime() {
27 return prezime;
28 }
30 public int getGodinaRodjenja() {
31 return godinaRodjenja;
32 }
34 @Override
35 public int hashCode() {
36 final int prostBroj = 31;
37 int rezultat = 1;
38 rezultat = prostBroj * rezultat + godinaRodjenja;
39 rezultat = prostBroj * rezultat + ime.hashCode();
40 rezultat = prostBroj * rezultat + prezime.hashCode();
41 return rezultat;
42 }
44 @Override
45 public boolean equals(Object obj) {
46 if (this == obj) {
47 return true;
48 }
49 if (obj == null) {
50 return false;
51 }
52 if (getClass() != obj.getClass()) {
53 return false;
54 }
55 Osoba that = (Osoba) obj;
56 if (this.godinaRodjenja != that.godinaRodjenja) {
57 return false;
58 }
59 if (!Objects.equals(this.ime, that.ime)) {
60 return false;
61 }
62 if (!Objects.equals(this.prezime, that.prezime)) {
63 return false;
64 }
65 return true;
66 }
68 @Override
69 public String toString() {
70 return ime + " " + prezime + " " + godinaRodjenja;
71 }
72 }
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner