$darkmode
DENOPTIM
SymmetricAPs.java
Go to the documentation of this file.
1package denoptim.graph;
2
3import java.lang.reflect.Type;
4import java.util.ArrayList;
5import java.util.HashSet;
6import java.util.List;
7import java.util.Set;
8
9import com.google.gson.JsonElement;
10import com.google.gson.JsonSerializationContext;
11import com.google.gson.JsonSerializer;
12
20public class SymmetricAPs extends SymmetricSet<AttachmentPoint>
21{
22
26 private static final long serialVersionUID = 4L;
27
28//------------------------------------------------------------------------------
29
30 public SymmetricAPs()
31 {
32 super();
33 }
34
35//------------------------------------------------------------------------------
36
37 public SymmetricAPs(List<AttachmentPoint> symAPs)
38 {
39 super();
40 this.addAll(symAPs);
41 }
42
43//------------------------------------------------------------------------------
44
45 public String toString()
46 {
47 StringBuilder sb = new StringBuilder();
48 sb.append("SymmetricAPs [");
49 for (int i=0; i<this.size(); i++)
50 {
51 sb.append(this.get(i).getID());
52 if (i<(this.size()-1))
53 sb.append(", ");
54 }
55 sb.append("]");
56 return sb.toString();
57 }
58
59//------------------------------------------------------------------------------
60
70 public SymmetricAPs getSameAs(Set<SymmetricAPs> others)
71 {
72 for (SymmetricAPs other : others)
73 if (sameAs(other))
74 return other;
75 return null;
76 }
77
78//------------------------------------------------------------------------------
79
89 public Set<SymmetricAPs> getAllSameAs(Set<SymmetricAPs> others)
90 {
91 Set<SymmetricAPs> result = new HashSet<SymmetricAPs>();
92 for (SymmetricAPs other : others)
93 if (sameAs(other))
94 result.add(other);
95 return result;
96 }
97
98//------------------------------------------------------------------------------
99
108 public boolean sameAs(SymmetricAPs other)
109 {
110 if (this.size()!=other.size())
111 return false;
112 for (int i=0; i<this.size(); i++)
113 {
114 if (!this.get(i).sameAs(other.get(i)))
115 return false;
116 }
117 return true;
118 }
119
120//------------------------------------------------------------------------------
121
122 public static class SymmetricAPsSerializer
123 implements JsonSerializer<SymmetricAPs>
124 {
125 @Override
126 public JsonElement serialize(SymmetricAPs list, Type typeOfSrc,
127 JsonSerializationContext context)
128 {
129 List<Integer> ids = new ArrayList<Integer>();
130 for (AttachmentPoint ap : list)
131 {
132 ids.add(ap.getID());
133 }
134 return context.serialize(ids);
135 }
136 }
137
138 //NB: deserialization is done in the DENOPTIMVertexDeserializer
139
140//------------------------------------------------------------------------------
141
142}
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
JsonElement serialize(SymmetricAPs list, Type typeOfSrc, JsonSerializationContext context)
A collection of AttachmentPoints that are related by a relation that we call "symmetry",...
SymmetricAPs getSameAs(Set< SymmetricAPs > others)
Identifies a set of symmetric APs that, although it contains references to different instances of Att...
SymmetricAPs(List< AttachmentPoint > symAPs)
Set< SymmetricAPs > getAllSameAs(Set< SymmetricAPs > others)
Identifies any set of symmetric APs that, although it contains references to different instances of A...
static final long serialVersionUID
Version ID.
boolean sameAs(SymmetricAPs other)
Checks if this collection SymmetricAPs is analogous to the other one, i.e., they contain AttachmentPo...
Class representing a list of references pointing to instances that are related by some conventional c...