$darkmode
DENOPTIM
ObjectPair.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.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.utils;
20
21import java.util.Objects;
22
29public class ObjectPair
30{
31 private Object o1;
32 private Object o2;
33
34//------------------------------------------------------------------------------
35
36 public ObjectPair()
37 {
38 o1 = null;
39 o2 = null;
40 }
41
42//------------------------------------------------------------------------------
43
44 public ObjectPair(Object o1, Object o2)
45 {
46 this.o1 = o1;
47 this.o2 = o2;
48 }
49
50//------------------------------------------------------------------------------
51
52 public boolean isSame(Object o1, Object o2)
53 {
54 return Objects.equals(o1, o2);
55 }
56
57//------------------------------------------------------------------------------
58
59 public Object getFirst()
60 {
61 return o1;
62 }
63
64//------------------------------------------------------------------------------
65
66 public Object getSecond()
67 {
68 return o2;
69 }
70
71//------------------------------------------------------------------------------
72
73 public void setFirst(Object o)
74 {
75 o1 = o;
76 }
77
78//------------------------------------------------------------------------------
79
80 public void setSecond(Object o)
81 {
82 o2 = o;
83 }
84
85//------------------------------------------------------------------------------
86
87 @Override
88 public boolean equals(Object obj)
89 {
90 if (obj == null)
91 return false;
92
93 if (!(obj instanceof ObjectPair))
94 return false;
95
96 ObjectPair p = (ObjectPair)obj;
97 return (isSame(p.o1, this.o1) && isSame(p.o2, this.o2));
98 }
99
100//------------------------------------------------------------------------------
101
102 @Override
103 public int hashCode()
104 {
105 return ((o1 == null ? 0 : o1.hashCode()) ^
106 (o2 == null ? 0 : o2.hashCode()));
107 }
108
109//------------------------------------------------------------------------------
110
111 @Override
112 public String toString()
113 {
114 return "DENOPTIMPair{"+o1+", "+o2+"}";
115 }
116
117//------------------------------------------------------------------------------
118
119}
This class is the equivalent of the Pair data structure used in C++ Although AbstractMap....
Definition: ObjectPair.java:30
boolean isSame(Object o1, Object o2)
Definition: ObjectPair.java:52
ObjectPair(Object o1, Object o2)
Definition: ObjectPair.java:44
boolean equals(Object obj)
Definition: ObjectPair.java:88
void setFirst(Object o)
Definition: ObjectPair.java:73
void setSecond(Object o)
Definition: ObjectPair.java:80