package com.cn;
public class Criminal {
private int height;
private int weight;
private int blood;
private String home;
@Override
public int hashCode() {
int nu = (nu = height) << 8 ;
nu = (nu | weight ) << 8;
nu = nu | blood;
System.out.println(nu);
return nu;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Criminal other = (Criminal) obj;
if (blood != other.blood)
return false;
if (height != other.height)
return false;
if (home == null) {
if (other.home != null)
return false;
} else if (!home.equals(other.home))
return false;
if (weight != other.weight)
return false;
return true;
}
public Criminal(int height, int weight, int blood, String home) {
super();
this.height = height;
this.weight = weight;
this.blood = blood;
this.home = home;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getBlood() {
return blood;
}
public void setBlood(int blood) {
this.blood = blood;
}
public String getHome() {
return home;
}
public void setHome(String home) {
this.home = home;
}
}
public class Demo {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
//byte by= 2;
//System.out.println((by & 0xFF) << 16 == by << 16);
Criminal c1 = new Criminal(2, 2, 2, "O");
Criminal c4 = new Criminal(2, 2, 2, "O4");
Criminal c2 = new Criminal(254, 254, 254, "A");
Criminal c3 = new Criminal(255, 255, 255, "a");
c1.hashCode();
c2.hashCode();
c3.hashCode();
Set<Criminal> s1 = new HashSet<Criminal>();
s1.add(c1);
s1.add(c2);
s1.add(c3);
s1.add(c4);
Iterator<Criminal> iterator = s1.iterator();
for (Criminal criminal : s1) {
System.out.println(criminal.getHeight());
}
}
}
package com.cn;
public class Criminal {
private int height;
private int weight;
private int blood;
private String home;
@Override
public int hashCode() {
int nu = (nu = height) << 8 ;
nu = (nu | weight ) << 8;
nu = nu | blood;
System.out.println(nu);
return nu;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Criminal other = (Criminal) obj;
if (blood != other.blood)
return false;
if (height != other.height)
return false;
if (home == null) {
if (other.home != null)
return false;
} else if (!home.equals(other.home))
return false;
if (weight != other.weight)
return false;
return true;
}
public Criminal(int height, int weight, int blood, String home) {
super();
this.height = height;
this.weight = weight;
this.blood = blood;
this.home = home;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getBlood() {
return blood;
}
public void setBlood(int blood) {
this.blood = blood;
}
public String getHome() {
return home;
}
public void setHome(String home) {
this.home = home;
}
}
public class Demo {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Person p1 = new Person("name");
Person p2 = new Person("name");
Dog d1 = new Dog("jinba1 ");
Dog d2 = new Dog("jinba3 ");
Map<Person, Dog> m1 = new HashMap<Person, Dog>();
m1.put(p1, d1);
m1.put(p2, d2);
Set<Person> ss = m1.keySet();
for (Person person : m1.keySet()) {
Dog dd = m1.get(person);
System.out.println(dd.name);
}
Set<Map.Entry<Person,Dog>> en = m1.entrySet();
for (Entry<Person, Dog> entry : en) {
}
}