Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Objects;
- import org.svetovid.io.SvetovidReader;
- /**
- *
- *
- * Prosiruje InfoTip samo zbog jednostavnosti u TestHash, nema razloga inace.
- */
- public class Boja extends InfoTip {
- private int r,g,b;
- public Boja(int r, int g, int b) {
- this.r = r;
- this.g = g;
- this.b = b;
- }
- public Boja() {
- };
- public boolean equals(Object o) {
- // Objekat je identican
- if (this == o) {
- return true;
- }
- // Null je uvek razlicit
- if (o == null) {
- return false;
- }
- // Ako su klase razlicite, objekti ne mogu bili jednaki
- if (getClass() != o.getClass()) {
- return false;
- }
- // pretvaramo objekat u nas tip
- Boja b2 = (Boja) o;
- // proveravamo kanale
- if (r != b2.r) {
- return false;
- }
- if (g != b2.g) {
- return false;
- }
- if (b != b2.b) {
- return false;
- }
- // Proverili smo polja i sva su jednaka
- return true;
- }
- public int hashCode() {
- return r + 256 * g + 256 * 256 * b;
- }
- @Override
- public Boja ucitaj(SvetovidReader read) {
- int r = read.readInt();
- int g = read.readInt();
- int b = read.readInt();
- Boja rez = new Boja(r,g,b);
- return rez;
- }
- // pomocni metod za lakse testiranje
- public static void main(String[] args) {
- new TestHash(new Boja(), "boje/", "boje").run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement