privateint id; private String name; privateint age; privatedouble salary; // get/set/constructor... @Override publicinthashCode() { finalintprime=31; intresult=1; result = prime * result + age; result = prime * result + id; result = prime * result + ((name == null) ? 0 : name.hashCode()); long temp; temp = Double.doubleToLongBits(salary); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; }
@Override publicbooleanequals(Object obj) { if (this == obj) returntrue; if (obj == null) returnfalse; if (getClass() != obj.getClass()) returnfalse; Employeeother= (Employee) obj; if (age != other.age) returnfalse; if (id != other.id) returnfalse; if (name == null) { if (other.name != null) returnfalse; } elseif (!name.equals(other.name)) returnfalse; if (Double.doubleToLongBits(salary) != Double.doubleToLongBits(other.salary)) returnfalse; returntrue; } }
@Override publicinthashCode() { finalintprime=31; intresult=1; result = prime * result + age; result = prime * result + id; result = prime * result + ((name == null) ? 0 : name.hashCode()); long temp; temp = Double.doubleToLongBits(salary); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; }
@Override publicbooleanequals(Object obj) { if (this == obj) returntrue; if (obj == null) returnfalse; if (getClass() != obj.getClass()) returnfalse; Employeeother= (Employee) obj; if (age != other.age) returnfalse; if (id != other.id) returnfalse; if (name == null) { if (other.name != null) returnfalse; } elseif (!name.equals(other.name)) returnfalse; if (Double.doubleToLongBits(salary) != Double.doubleToLongBits(other.salary)) returnfalse; returntrue; }
@Override public String toString() { return"Employee [id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", status=" + status + "]"; }
for (Integer num : numList) { System.out.println(num); } } //需求:产生指定个数的整数,并放入集合中 public List<Integer> getNumList(int num, Supplier<Integer> sup){ List<Integer> list = newArrayList<>();
for (inti=0; i < num; i++) { Integern= sup.get(); list.add(n); }
因为sonarqube采用elasticsearch作为检索后台服务,在Linux下面部署应用的时候,有时候会遇上Socket/File: Can’t open so many files的问题;这个值也会影响服务器的最大并发数,其实Linux是有文件句柄限制的,而且Linux默认不是很高,一般都是1024,生产服务器用其实很容易就达到这个数量
publicclassBatchClient { publicstaticvoidmain(String[] args) { Directordirector=newDirector(); // 1万辆A类型的奔驰车 for (inti=0; i < 10000; i++) { director.getABenzModel().run(); } // 100万辆B类型的奔驰车 for (inti=0; i < 1000000; i++) { director.getBBenzModel().run(); } // 1000万辆C类型的宝马车 for (inti=0; i < 10000000; i++) { director.getCBMWModel().run(); } } }
2 建造者模式的定义
建造者模式(Builder Pattern)也叫做生成器模式,其定义如下:
Separate the construction of a complex object from its representation so that the same construction process can create different representations.(将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。)