001package basics.mutablebasic;
002import basics.immutabledata.Pair;
003public class Main {
004        private Main() {}
005        static public void main (final String[] args) {
006                //stdlib.Trace.graphvizShowSteps (true); stdlib.Trace.run ();
007                final PairBuilder<Integer,String> pb1 = new PairBuilder<Integer,String>();
008                pb1.setFirst(42);
009                pb1.setSecond("dog");
010                System.out.println(pb1);
011                final Pair<Integer,String> p1 = pb1.toPair();
012                System.out.println(p1);
013
014                final PairBuilder<Integer,String> pb2 = new PairBuilder<Integer,String>();
015                final Pair<Integer,String> p2 = pb2.toPair();
016        }
017}
018final class PairBuilder<S extends Comparable<S>, T extends Comparable<T>> {
019        private S x;
020        private T y;
021        public PairBuilder() { }
022        public void setFirst(S x) { this.x = x; }
023        public void setSecond(T y) { this.y = y; }
024        public Pair<S,T> toPair() {
025                if (x == null || y == null)
026                        throw new NullPointerException();
027                return new Pair<S,T>(x,y);
028        }
029}