1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| class Computer { private final String cpu; private final String ram; private final int usbCount; private final String keyboard; private final String display;
public Computer(Builder builder) { this.cpu = builder.cpu; this.ram = builder.ram; this.usbCount = builder.usbCount; this.keyboard = builder.keyboard; this.display = builder.display; }
public String getCpu() { return cpu; }
public String getRam() { return ram; }
public int getUsbCount() { return usbCount; }
public String getKeyboard() { return keyboard; }
public String getDisplay() { return display; }
@Override public String toString() { return "com.lixiang.Computer{" + "cpu='" + cpu + '\'' + ", ram='" + ram + '\'' + ", usbCount=" + usbCount + ", keyboard='" + keyboard + '\'' + ", display='" + display + '\'' + '}'; }
static class Builder { private final String cpu; private final String ram; private int usbCount; private String keyboard; private String display; public Builder(String cpu, String ram) { this.cpu = cpu; this.ram = ram; }
public Builder setUsbCount(int usbCount) { this.usbCount = usbCount; return this; } public Builder setKeyboard(String keyboard) { this.keyboard = keyboard; return this; } public Builder setDisplay(String display) { this.display = display; return this; } public Computer build() { return new Computer(this); } } }
|