001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 The ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package org.conqat.lib.commons.collections; 018 019/** 020 * Simple pair class. 021 * 022 * @author hummelb 023 */ 024public class Pair<S, T> extends ImmutablePair<S, T> { 025 026 /** Version used for serialization. */ 027 private static final long serialVersionUID = 1; 028 029 /** Constructor. */ 030 public Pair(S first, T second) { 031 super(first, second); 032 } 033 034 /** Copy constructor. */ 035 public Pair(ImmutablePair<S, T> p) { 036 super(p); 037 } 038 039 /** Set the first value. */ 040 public void setFirst(S first) { 041 this.first = first; 042 } 043 044 /** Set the second value. */ 045 public void setSecond(T second) { 046 this.second = second; 047 } 048 049 /** {@inheritDoc} */ 050 @Override 051 protected Pair<S, T> clone() { 052 return new Pair<>(this); 053 } 054 055 /** 056 * Converts a string comma separated integers to a pair of Integers. 057 * 058 * @throws NumberFormatException 059 * if the format does not match 060 */ 061 public static Pair<Integer, Integer> parseIntPair(String string) { 062 String[] tokens = string.split(",\\s*"); 063 if (tokens.length != 2) { 064 throw new NumberFormatException("Invalid number of comma separated tokens!"); 065 } 066 067 return new Pair<>(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); 068 } 069 070 /** Factory method for pairs, to simplify creation. */ 071 public static <S, T> Pair<S, T> createPair(S first, T second) { 072 return new Pair<>(first, second); 073 } 074}