Facebook
From Reliable Hamster, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 202
  1. public class Plik implements Cloneable, Comparable<Plik>{
  2.  
  3.     public Plik(String nazwa, int rozmiar, boolean czyDoZapisu){
  4.         this.nazwa = nazwa;
  5.         this.rozmiar = rozmiar;
  6.         this.czyDoZapisu = czyDoZapisu;
  7.         ile++;
  8.     }
  9.  
  10.     public Plik(int rozmiar, boolean czyDoZapisu){
  11.         this("Jakis Plik", rozmiar, czyDoZapisu);
  12.     }
  13.  
  14.     public boolean equals(Object obj) {
  15.         if (this == obj) return true;
  16.         if (obj == null) return false;
  17.         if (getClass() != obj.getClass()) return false;
  18.         Plik other = (Plik) obj;
  19.         if (nazwa == null) if (other.nazwa != null) return false;
  20.         else if (!nazwa.equals(other.nazwa)) return false;
  21.         if (this.rozmiar != other.rozmiar) return false;
  22.         if (this.czyDoZapisu != other.czyDoZapisu) return false;
  23.         if (this.ile != other.ile) return false;
  24.         return true;
  25.     }
  26.  
  27.     public int compareTo(Plik other)
  28.     {
  29.         if((this.nazwa.compareTo(other.nazwa)) == 0){
  30.             if(this.rozmiar == other.rozmiar) {
  31.                 if(this.czyDoZapisu == other.czyDoZapisu){
  32.                     if(this.ile == other.ile){
  33.                         return 0;
  34.                     }
  35.                     else if (this.ile > other.ile) return 1;
  36.                     else return -1;
  37.                 } else return 1;
  38.             } else if(this.rozmiar > other.rozmiar) return 1;
  39.             else return -1;
  40.         }else return this.nazwa.compareTo(other.nazwa);
  41.     }
  42.  
  43.     public Object clone() throws CloneNotSupportedException {
  44.         return super.clone();
  45.     }
  46.  
  47.     public String toString(){
  48.         if(nazwa == "Jakis Plik"){
  49.             return this.getClass().getSimpleName() + " [" + this.rozmiar + "]" + " , " + "[" + this.czyDoZapisu + "]" + " , " + "[" + this.ile + "]";
  50.         }
  51.         return this.getClass().getSimpleName() + " [" + this.nazwa + "]" + " , " + "[" + this.rozmiar + "]" + " , " + "[" + this.czyDoZapisu + "]" + " , " + "[" + this.ile + "]";
  52.     }
  53.  
  54.     public void setNazwa(String nazwa){
  55.         this.nazwa = nazwa;
  56.     }
  57.  
  58.     public void setRozmiar(int rozmiar){
  59.         this.rozmiar = rozmiar;
  60.     }
  61.  
  62.     public void setCzyDoZapisu(boolean czyDoZapisu){
  63.         this.czyDoZapisu = czyDoZapisu;
  64.     }
  65.  
  66.     public void setIle(int ile){
  67.         this.ile = ile;
  68.     }
  69.  
  70.     public String getNazwa(){
  71.         return this.nazwa;
  72.     }
  73.  
  74.     public int getRozmiar(){
  75.         return this.rozmiar;
  76.     }
  77.  
  78.     public boolean getCzyDoZapisu(){
  79.         return this.czyDoZapisu;
  80.     }
  81.  
  82.     public static int getIle(){
  83.         return ile;
  84.     }
  85.  
  86.     private String nazwa;
  87.     private int rozmiar;
  88.     private boolean czyDoZapisu;
  89.     public static int ile = 0;
  90.  
  91.  
  92. }
  93.