[WikiDyd] [TitleIndex] [WordIndex

O czym było między innymi na wykładzie:

   1 public class SBox {
   2         private double x;
   3         private double y;
   4         private double a;
   5         private String kolor;
   6 
   7         public SBox() {
   8                 x = 0;
   9                 y = 0;
  10                 a = 0;
  11         }
  12 
  13         public SBox(double x, double y, double a) {
  14                 this.x = x;
  15                 this.y = y;
  16                 this.a = a;
  17         }
  18 
  19         public double getX() {
  20                 return x;
  21         }
  22 
  23         public void setX(double x) {
  24                 this.x = x;
  25         }
  26 
  27         /* itd. */
  28 
  29         public String toString() {
  30                 return "SBox: " + a + " at (" + x + "," + y + ")"; 
  31         }
  32 
  33 
  34         public boolean equals( Object o ) {
  35                 if ( o == this )
  36                         return true;
  37                 if ( ! ( o instanceof SBox) )
  38                         return false;
  39                 
  40                 SBox sb = (SBox) o;
  41 
  42                 //return this.toString().equals( o.toString() );
  43 
  44                 if ((x != sb.x ) || (y != sb.y) || (a != sb.a))
  45                         return false;
  46 
  47 /*
  48                 if ( (kolor != null ? !kolor.equals( sb.getKolor() ) : 
  49                       sb.getKolor() != null ) ) {
  50                       return false;
  51                 }
  52 */
  53                 return true;
  54 
  55         }
  56 
  57 
  58         public int hashCode() {
  59                 return toString().hashCode();
  60 
  61         }
  62 
  63         public static void main(String[] args) {
  64                 SBox ref = new SBox( 0, 0, 0 );
  65 
  66                 for (int i = 0; i < args.length; i+=3 ) {
  67                         SBox test = new SBox( Double.parseDouble( args[i] ),
  68                          Double.parseDouble( args[i+1] ),
  69                          Double.parseDouble( args[i+2] ) );
  70                          System.out.println( test + " hashCode " + test.hashCode());
  71                          System.out.println(test + ( test.equals(ref) ? "==" : "!=" ) + ref );
  72                 }
  73         }
  74 }

2015-09-23 06:43