001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of AutomataLib, http://www.automatalib.net/.
003 * 
004 * AutomataLib is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Lesser General Public
006 * License version 3.0 as published by the Free Software Foundation.
007 * 
008 * AutomataLib is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011 * Lesser General Public License for more details.
012 * 
013 * You should have received a copy of the GNU Lesser General Public
014 * License along with AutomataLib; if not, see
015 * http://www.gnu.de/documents/lgpl.en.html.
016 */
017package net.automatalib.commons.util;
018
019import java.io.IOException;
020
021import net.automatalib.commons.util.strings.AbstractPrintable;
022import net.automatalib.commons.util.strings.StringUtil;
023
024@Deprecated
025public class Triple<T1, T2, T3> extends AbstractPrintable {
026        
027        protected T1 first;
028        protected T2 second;
029        protected T3 third;
030        
031        public Triple() {
032                
033        }
034        
035        public Triple(T1 first, T2 second, T3 third) {
036                this.first = first;
037                this.second = second;
038                this.third = third;
039        }
040        
041        
042        
043        
044        public T1 getFirst() {
045                return first;
046        }
047
048        public void setFirst(T1 first) {
049                this.first = first;
050        }
051
052        public T2 getSecond() {
053                return second;
054        }
055
056        public void setSecond(T2 second) {
057                this.second = second;
058        }
059
060        public T3 getThird() {
061                return third;
062        }
063
064        public void setThird(T3 third) {
065                this.third = third;
066        }
067
068        @Override
069        public void print(Appendable a) throws IOException {
070                StringUtil.appendObject(a, first);
071                a.append(", ");
072                StringUtil.appendObject(a, second);
073                a.append(", ");
074                StringUtil.appendObject(a, third);
075        }
076        
077        
078        
079        
080        @Override
081        public int hashCode() {
082                final int prime = 31;
083                int result = 1;
084                result = prime * result + ((first == null) ? 0 : first.hashCode());
085                result = prime * result + ((second == null) ? 0 : second.hashCode());
086                result = prime * result + ((third == null) ? 0 : third.hashCode());
087                return result;
088        }
089
090        @Override
091        public boolean equals(Object obj) {
092                if (this == obj)
093                        return true;
094                if (obj == null)
095                        return false;
096                if (getClass() != obj.getClass())
097                        return false;
098                Triple<?,?,?> other = (Triple<?,?,?>) obj;
099                if (first == null) {
100                        if (other.first != null)
101                                return false;
102                } else if (!first.equals(other.first))
103                        return false;
104                if (second == null) {
105                        if (other.second != null)
106                                return false;
107                } else if (!second.equals(other.second))
108                        return false;
109                if (third == null) {
110                        if (other.third != null)
111                                return false;
112                } else if (!third.equals(other.third))
113                        return false;
114                return true;
115        }
116
117        public Pair<T1,Pair<T2,T3>> asPair1() {
118                return Pair.make(first, Pair.make(second, third));
119        }
120        
121        public Pair<Pair<T1,T2>,T3> asPair2() {
122                return Pair.make(Pair.make(first, second), third);
123        }
124        
125        
126        
127        public static <T1,T2,T3> Triple<T1,T2,T3> make(T1 first, T2 second, T3 third) {
128                return new Triple<T1,T2,T3>(first, second, third);
129        }
130        
131        public static <T1,T2,T3> Triple<T1,T2,T3> fromPair1(Pair<T1,Pair<T2,T3>> pair) {
132                T1 first = null;
133                Pair<T2,T3> sndPair = null;
134                if(pair != null) {
135                        first = pair.getFirst();
136                        sndPair = pair.getSecond();
137                }
138                T2 second = null;
139                T3 third = null;
140                if(sndPair != null) {
141                        second = sndPair.getFirst();
142                        third = sndPair.getSecond();
143                }
144                
145                return make(first, second, third);
146        }
147        
148        public static <T1,T2,T3> Triple<T1,T2,T3> fromPair2(Pair<Pair<T1,T2>,T3> pair) {
149                Pair<T1,T2> fstPair = null;
150                T3 third = null;
151                if(pair != null) {
152                        fstPair = pair.getFirst();
153                        third = pair.getSecond();
154                }
155                T1 first = null;
156                T2 second = null;
157                if(fstPair != null) {
158                        first = fstPair.getFirst();
159                        second = fstPair.getSecond();
160                }
161                
162                return make(first, second, third);
163        }
164}