Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import java.util.Objects;
  2.  
  3. import org.svetovid.io.SvetovidReader;
  4.  
  5. /**
  6.  *
  7.  *
  8.  * Prosiruje InfoTip samo zbog jednostavnosti u TestHash, nema razloga inace.
  9.  */
  10. public class Boja extends InfoTip {
  11.     private int r,g,b;
  12.  
  13.     public Boja(int r, int g, int b) {
  14.         this.r = r;
  15.         this.g = g;
  16.         this.b = b;
  17.     }
  18.  
  19.     public Boja() {
  20.     };
  21.  
  22.     public boolean equals(Object o) {
  23.         // Objekat je identican
  24.         if (this == o) {
  25.             return true;
  26.         }
  27.         // Null je uvek razlicit
  28.         if (o == null) {
  29.             return false;
  30.         }
  31.         // Ako su klase razlicite, objekti ne mogu bili jednaki
  32.         if (getClass() != o.getClass()) {
  33.             return false;
  34.         }
  35.  
  36.         // pretvaramo objekat u nas tip
  37.         Boja b2 = (Boja) o;
  38.  
  39.         //  proveravamo kanale
  40.         if (r != b2.r) {
  41.             return false;
  42.         }
  43.  
  44.         if (g != b2.g) {
  45.             return false;
  46.         }
  47.        
  48.         if (b != b2.b) {
  49.             return false;
  50.         }
  51.  
  52.         // Proverili smo polja i sva su jednaka
  53.         return true;
  54.     }
  55.  
  56.     public int hashCode() {
  57.         return r + 256 * g + 256 * 256 * b;
  58.     }
  59.  
  60.     @Override
  61.     public Boja ucitaj(SvetovidReader read) {
  62.        
  63.         int r = read.readInt();
  64.         int g = read.readInt();
  65.         int b = read.readInt();
  66.         Boja rez = new Boja(r,g,b);
  67.         return rez;
  68.     }
  69.  
  70.     // pomocni metod za lakse testiranje
  71.     public static void main(String[] args) {
  72.         new TestHash(new Boja(), "boje/", "boje").run();
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement