$darkmode
DENOPTIM
APTreeMap.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.graph;
20
21import java.lang.reflect.Type;
22import java.util.HashSet;
23import java.util.LinkedHashMap;
24import java.util.Map.Entry;
25import java.util.Set;
26import java.util.TreeMap;
27
28import com.google.gson.JsonElement;
29import com.google.gson.JsonSerializationContext;
30import com.google.gson.JsonSerializer;
31
42public class APTreeMap extends LinkedHashMap<AttachmentPoint, AttachmentPoint>
43{
47 private static final long serialVersionUID = 3L;
48
55 public static class APMapSerializer implements JsonSerializer<APTreeMap>
56 {
57 @Override
58 public JsonElement serialize(APTreeMap apmap, Type typeOfSrc,
59 JsonSerializationContext context)
60 {
61 TreeMap<Integer,AttachmentPoint> jsonableMap = new TreeMap<>();
62 Set<Integer> foundIDs = new HashSet<Integer>();
63 for (Entry<AttachmentPoint, AttachmentPoint> entry
64 : apmap.entrySet())
65 {
66 int keyID = entry.getKey().getID();
67 if (foundIDs.contains(keyID))
68 throw new Error("Found diplicate AP ID for APs that are "
69 + "expected to have unique IDs.");
70 jsonableMap.put(keyID, entry.getValue());
71 }
72 return context.serialize(jsonableMap);
73 }
74 }
75
76//------------------------------------------------------------------------------
77
78 @Override
80 {
81 return super.put(key, value);
82 }
83
84//------------------------------------------------------------------------------
85
86 @Override
87 public AttachmentPoint remove(Object key)
88 {
89 return super.remove(key);
90 }
91
92//------------------------------------------------------------------------------
93
94 @Override
95 public AttachmentPoint get(Object key)
96 {
97 return super.get(key);
98 }
99
100//------------------------------------------------------------------------------
101}
Method that serializes this class without creating loops of references.
Definition: APTreeMap.java:56
JsonElement serialize(APTreeMap apmap, Type typeOfSrc, JsonSerializationContext context)
Definition: APTreeMap.java:58
Attachment point mapping where keys are sorted by natural ordering, i.e., by AttachmentPoint#compareT...
Definition: APTreeMap.java:43
static final long serialVersionUID
Version identifier.
Definition: APTreeMap.java:47
AttachmentPoint put(AttachmentPoint key, AttachmentPoint value)
Definition: APTreeMap.java:79
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....