OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
DataRepresentationImpl.java
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
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,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 package org.opensplice.dds.core.policy;
22 
23 import java.util.List;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 
31 
32 public class DataRepresentationImpl extends QosPolicyImpl implements
34  private static final long serialVersionUID = -3169717693569991730L;
35  private final ArrayList<Short> value;
36 
38  super(environment);
39  this.value = new ArrayList<Short>();
40  }
41 
43  List<Short> value) {
44  super(environment);
45 
46  if (value == null) {
47  throw new IllegalArgumentExceptionImpl(environment,
48  "Supplied invalid list of values.");
49  }
50  this.value = new ArrayList<Short>(value);
51  }
52 
54  short... value) {
55  super(environment);
56  this.value = new ArrayList<Short>(value.length);
57 
58  for (short val : value) {
59  this.value.add(val);
60  }
61  }
62 
63  @Override
64  public Comparable<DataRepresentation> requestedOfferedContract() {
65  return this;
66  }
67 
68  @Override
69  public int compareTo(DataRepresentation arg0) {
70  if (arg0 == null) {
71  return 1;
72  }
73  return this.value.hashCode() - arg0.getValue().hashCode();
74  }
75 
76  @Override
77  public boolean equals(Object other) {
78  if (!(other instanceof DataRepresentationImpl)) {
79  return false;
80  }
81  DataRepresentationImpl d = (DataRepresentationImpl) other;
82 
83  if (d.value.size() != this.value.size()) {
84  return false;
85  }
86  for (int i = 0; i < this.value.size(); i++) {
87  if (!(this.value.get(i).equals(d.value.get(i)))) {
88  return false;
89  }
90  }
91  return true;
92  }
93 
94  @Override
95  public int hashCode() {
96  final int prime = 31;
97  int result = 17;
98 
99  for (short s : this.value) {
100  result = prime * result + s;
101  }
102  return result;
103  }
104 
105  @Override
106  public List<Short> getValue() {
107  return Collections.unmodifiableList(this.value);
108  }
109 
110  @Override
111  public DataRepresentation withValue(List<Short> value) {
112  return new DataRepresentationImpl(this.environment, value);
113  }
114 
115  @Override
116  public DataRepresentation withValue(short... value) {
117  return new DataRepresentationImpl(this.environment, value);
118  }
119 
120  @Override
121  public Class<? extends QosPolicy> getPolicyClass() {
122  return DataRepresentation.class;
123  }
124 
125 }
DataRepresentation withValue(short... value)
Copy this policy and override the value of the property.
DataRepresentationImpl(OsplServiceEnvironment environment, short... value)
DataRepresentation withValue(List< Short > value)
Copy this policy and override the value of the property.
This class is the abstract root for all the QoS policies.
Definition: QosPolicy.java:118
DataRepresentationImpl(OsplServiceEnvironment environment, List< Short > value)