-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInvoiceIdServer.java
More file actions
52 lines (51 loc) · 1.54 KB
/
InvoiceIdServer.java
File metadata and controls
52 lines (51 loc) · 1.54 KB
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
package com.company;
import java.io.*;
public class InvoiceIdServer implements Serializable {
private int idCounter;
private static InvoiceIdServer server;
private InvoiceIdServer() {
idCounter = 10001;
}
public static InvoiceIdServer instance() {
if (server == null) {
return (server = new InvoiceIdServer());
} else {
return server;
}
}
public int getId() {
return idCounter++;
}
public String toString() {
return ("IdServer" + idCounter);
}
public static void retrieve(ObjectInputStream input) {
try {
server = (InvoiceIdServer) input.readObject();
} catch(IOException ioe) {
ioe.printStackTrace();
} catch(Exception cnfe) {
cnfe.printStackTrace();
}
}
private void writeObject(java.io.ObjectOutputStream output) throws IOException {
try {
output.defaultWriteObject();
output.writeObject(server);
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
private void readObject(java.io.ObjectInputStream input) throws IOException, ClassNotFoundException {
try {
input.defaultReadObject();
if (server == null) {
server = (InvoiceIdServer) input.readObject();
} else {
input.readObject();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}