forked from quanke/design-pattern-java-source-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceFactory.java
More file actions
43 lines (38 loc) · 727 Bytes
/
Copy pathDeviceFactory.java
File metadata and controls
43 lines (38 loc) · 727 Bytes
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
import java.util.*;
public class DeviceFactory
{
private ArrayList devices = new ArrayList();
private int totalTerminal=0;
public DeviceFactory()
{
NetworkDevice nd1=new Switch("Cisco-WS-C2950-24");
devices.add(nd1);
NetworkDevice nd2=new Hub("TP-LINK-HF8M");
devices.add(nd2);
}
public NetworkDevice getNetworkDevice(String type)
{
if(type.equalsIgnoreCase("cisco"))
{
totalTerminal++;
return (NetworkDevice)devices.get(0);
}
else if(type.equalsIgnoreCase("tp"))
{
totalTerminal++;
return (NetworkDevice)devices.get(1);
}
else
{
return null;
}
}
public int getTotalDevice()
{
return devices.size();
}
public int getTotalTerminal()
{
return totalTerminal;
}
}