View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import javax.faces.event.AjaxBehaviorEvent;
26  import java.io.Serializable;
27  import java.lang.invoke.MethodHandles;
28  import java.util.Collections;
29  import java.util.List;
30  import java.util.stream.Collectors;
31  
32  public class SolarObject implements Serializable {
33  
34    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
35  
36    private String name;
37  
38    private String number;
39  
40    private String orbit;
41  
42    private Integer distance;
43  
44    private Double period;
45  
46    private Double incl;
47  
48    private Double eccen;
49  
50    private String discoverer;
51  
52    private Integer discoverYear;
53  
54    private String population;
55  
56    private List<Element> chemicalComposition;
57  
58    public SolarObject(
59        final String name, final String number, final String orbit, final Integer distance, final Double period,
60        final Double incl, final Double eccen, final String discoverer, final Integer discoverYear) {
61      this.name = name;
62      this.number = number;
63      this.orbit = orbit;
64      this.distance = distance;
65      this.period = period;
66      this.incl = incl;
67      this.eccen = eccen;
68      this.discoverer = discoverer;
69      this.discoverYear = discoverYear;
70      this.population = "Earth".equals(name) ? "~ 8.000.000.000" : "0";
71    }
72  
73    public SolarObject(final SolarObject solarObject) {
74      this.name = solarObject.getName();
75      this.number = solarObject.getNumber();
76      this.orbit = solarObject.getOrbit();
77      this.distance = solarObject.getDistance();
78      this.period = solarObject.getPeriod();
79      this.incl = solarObject.getIncl();
80      this.eccen = solarObject.getEccen();
81      this.discoverer = solarObject.getDiscoverer();
82      this.discoverYear = solarObject.getDiscoverYear();
83      this.population = getPopulation();
84      this.chemicalComposition = chemicalComposition != null
85          ? chemicalComposition.stream().map(Element::new).collect(Collectors.toList())
86          : null;
87    }
88  
89    public String getName() {
90      return name;
91    }
92  
93    public void update(final AjaxBehaviorEvent event) {
94      LOG.info("AjaxBehaviorEvent called. New value: '{}' event: {}", name, event);
95    }
96  
97    public void setName(final String name) {
98      this.name = name;
99    }
100 
101   public String getMarkup() {
102     if (name.equals("Sun")) {
103       return "sun";
104     } else {
105       if (orbit.equals("Sun")) {
106         return "planet";
107       } else {
108         return "moon";
109       }
110     }
111   }
112 
113   public String getNumber() {
114     return number;
115   }
116 
117   public void setNumber(final String number) {
118     this.number = number;
119   }
120 
121   public String getOrbit() {
122     return orbit;
123   }
124 
125   public void setOrbit(final String orbit) {
126     this.orbit = orbit;
127   }
128 
129   public Integer getDistance() {
130     return distance;
131   }
132 
133   public void setDistance(final Integer distance) {
134     this.distance = distance;
135   }
136 
137   public Double getPeriod() {
138     return period;
139   }
140 
141   public void setPeriod(final Double period) {
142     this.period = period;
143   }
144 
145   public Double getIncl() {
146     return incl;
147   }
148 
149   public void setIncl(final Double incl) {
150     this.incl = incl;
151   }
152 
153   public Double getEccen() {
154     return eccen;
155   }
156 
157   public void setEccen(final Double eccen) {
158     this.eccen = eccen;
159   }
160 
161   public String getDiscoverer() {
162     return discoverer;
163   }
164 
165   public void setDiscoverer(final String discoverer) {
166     this.discoverer = discoverer;
167   }
168 
169   public Integer getDiscoverYear() {
170     return discoverYear;
171   }
172 
173   public void setDiscoverYear(final Integer discoverYear) {
174     this.discoverYear = discoverYear;
175   }
176 
177   public String getPopulation() {
178     return population;
179   }
180 
181   public void setPopulation(final String population) {
182     this.population = population;
183   }
184 
185   public List<Element> getChemicalComposition() {
186     return chemicalComposition != null ? chemicalComposition : Collections.emptyList();
187   }
188 
189   public void setChemicalComposition(final List<Element> chemicalComposition) {
190     this.chemicalComposition = chemicalComposition;
191   }
192 
193   public String toString() {
194     return name;
195   }
196 }