View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.job.api;
23  
24  import static org.opencastproject.util.EqualsUtil.eq;
25  import static org.opencastproject.util.EqualsUtil.hash;
26  
27  import org.opencastproject.util.data.Tuple;
28  
29  import java.util.Collections;
30  import java.util.Date;
31  import java.util.List;
32  import java.util.Map;
33  
34  public final class IncidentImpl implements Incident {
35    private final long id;
36    private final long jobId;
37    private final String serviceType;
38    private final String processingHost;
39    private final Date timestamp;
40    private final Severity severity;
41    private final String code;
42    private final List<Tuple<String, String>> details;
43    private final Map<String, String> parameters;
44  
45    public IncidentImpl(long id,
46                        long jobId,
47                        String serviceType,
48                        String processingHost,
49                        Date timestamp,
50                        Severity severity,
51                        String code,
52                        List<Tuple<String, String>> details,
53                        Map<String, String> parameters) {
54      this.id = id;
55      this.jobId = jobId;
56      this.serviceType = serviceType;
57      this.processingHost = processingHost;
58      this.timestamp = new Date(timestamp.getTime());
59      this.severity = severity;
60      this.code = code;
61      this.details = Collections.unmodifiableList(details);
62      this.parameters = Collections.unmodifiableMap(parameters);
63    }
64  
65    @Override
66    public long getId() {
67      return id;
68    }
69  
70    @Override
71    public long getJobId() {
72      return jobId;
73    }
74  
75    @Override
76    public String getServiceType() {
77      return serviceType;
78    }
79  
80    @Override
81    public String getProcessingHost() {
82      return processingHost;
83    }
84  
85    @Override
86    public Date getTimestamp() {
87      return timestamp;
88    }
89  
90    @Override
91    public Severity getSeverity() {
92      return severity;
93    }
94  
95    @Override
96    public String getCode() {
97      return code;
98    }
99  
100   @Override
101   public List<Tuple<String, String>> getDetails() {
102     return details;
103   }
104 
105   @Override
106   public Map<String, String> getDescriptionParameters() {
107     return parameters;
108   }
109 
110   @Override
111   public int hashCode() {
112     return hash(id, jobId, serviceType, processingHost, timestamp, severity, code, details, parameters);
113   }
114 
115   @Override
116   public boolean equals(Object that) {
117     return (this == that) || (that instanceof Incident && eqFields((Incident) that));
118   }
119 
120   private boolean eqFields(Incident that) {
121     return eq(id, that.getId())
122             && eq(jobId, that.getJobId())
123             && eq(serviceType, that.getServiceType())
124             && eq(processingHost, that.getProcessingHost())
125             && eq(timestamp, that.getTimestamp())
126             && eq(severity, that.getSeverity())
127             && eq(code, that.getCode())
128             && eq(details, that.getDetails())
129             && eq(parameters, that.getDescriptionParameters());
130   }
131 }