1 package rydeen.io;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7 import rydeen.ProcessTarget;
8 import rydeen.TargetSource;
9
10
11
12
13
14
15
16
17
18 public class MemoryTargetSource implements TargetSource{
19 private List<ProcessTarget> list = new ArrayList<ProcessTarget>();
20
21
22
23
24 public MemoryTargetSource(){
25 }
26
27
28
29
30 public MemoryTargetSource(ProcessTarget... targets){
31 for(ProcessTarget target: targets){
32 addTarget(target);
33 }
34 }
35
36
37
38
39 public void addTarget(ProcessTarget target){
40 if(target.getTargetSource() != this){
41 if(target instanceof DelegateProcessTarget){
42 ((DelegateProcessTarget)target).setTargetSource(this);
43 }
44 else{
45 target = new DelegateProcessTarget(this, target);
46 }
47 }
48 list.add(target);
49 }
50
51
52
53
54 public int getTargetCount(){
55 return list.size();
56 }
57
58
59
60
61 @Override
62 public String getName(){
63 return getClass().getName() + ":" + System.identityHashCode(this);
64 }
65
66
67
68
69 @Override
70 public Iterator<ProcessTarget> iterator(){
71 return list.iterator();
72 }
73
74
75
76
77
78 public void close(){
79 list.clear();
80 }
81
82
83
84
85 @Override
86 public boolean contains(String target){
87 boolean flag = false;
88 for(ProcessTarget pt: list){
89 if(pt.getName().equals(target)){
90 flag = true;
91 break;
92 }
93 }
94 return flag;
95 }
96 }