View Javadoc
1   package emissary.client.response;
2   
3   import jakarta.xml.bind.annotation.XmlAccessType;
4   import jakarta.xml.bind.annotation.XmlAccessorType;
5   import jakarta.xml.bind.annotation.XmlElement;
6   import jakarta.xml.bind.annotation.XmlRootElement;
7   import org.slf4j.Logger;
8   import org.slf4j.LoggerFactory;
9   
10  import java.util.HashSet;
11  import java.util.Set;
12  import javax.annotation.Nullable;
13  
14  @XmlRootElement(name = "places")
15  @XmlAccessorType(XmlAccessType.NONE)
16  public class PlacesResponseEntity extends BaseResponseEntity {
17      private static final long serialVersionUID = 5686691885767273319L;
18  
19      private static final Logger logger = LoggerFactory.getLogger(PlacesResponseEntity.class);
20  
21      @XmlElement(name = "local")
22      private PlaceList local = new PlaceList();
23  
24      @XmlElement(name = "cluster")
25      private Set<PlaceList> cluster = new HashSet<>();
26  
27      public PlacesResponseEntity() {}
28  
29      public PlacesResponseEntity(PlaceList local) {
30          this.local = local;
31      }
32  
33      public void addClusterPlaces(@Nullable PlaceList pl) {
34          if (cluster == null) {
35              cluster = new HashSet<>();
36          }
37  
38          if (pl != null) {
39              this.cluster.add(pl);
40          }
41      }
42  
43      public PlaceList getLocal() {
44          return local;
45      }
46  
47      public void setLocal(PlaceList local) {
48          this.local = local;
49      }
50  
51      public Set<PlaceList> getCluster() {
52          return cluster;
53      }
54  
55      @Override
56      public void append(BaseEntity e) {
57          addErrors(e.getErrors());
58          if (e instanceof PlacesResponseEntity) {
59              PlacesResponseEntity pre = this.getClass().cast(e);
60              addClusterPlaces(pre.getLocal());
61          }
62      }
63  
64      @Override
65      public void dumpToConsole() {
66          getLocal().dumpToConsole();
67          for (PlaceList placeList : getCluster()) {
68              placeList.dumpToConsole();
69          }
70          logger.info("");
71      }
72  }