forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCache.java
More file actions
41 lines (37 loc) · 779 Bytes
/
Copy pathCache.java
File metadata and controls
41 lines (37 loc) · 779 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
import java.util.ArrayList;
import java.util.List;
public class Cache
{
private List<Service> services;
public Cache()
{
services = new ArrayList<Service>();
}
public Service getService( String serviceName )
{
for( Service service : services )
{
if( service.getName().equalsIgnoreCase(serviceName) )
{
System.out.println("Return cached " + serviceName + " object");
return service;
}
}
return null;
}
public void addService( Service newService )
{
boolean exists = false;
for( Service service : services )
{
if( service.getName().equalsIgnoreCase(newService.getName()) )
{
exists = true;
}
}
if( !exists )
{
services.add(newService);
}
}
}