001/* 002 AUTOMATICALLY GENERATED BY jTemp FROM 003 /Users/jsh2/Work/openimaj/target/checkout/core/core/src/main/jtemp/org/openimaj/util/pair/#T#ObjectPair.jtemp 004*/ 005/** 006 * Copyright (c) 2011, The University of Southampton and the individual contributors. 007 * All rights reserved. 008 * 009 * Redistribution and use in source and binary forms, with or without modification, 010 * are permitted provided that the following conditions are met: 011 * 012 * * Redistributions of source code must retain the above copyright notice, 013 * this list of conditions and the following disclaimer. 014 * 015 * * Redistributions in binary form must reproduce the above copyright notice, 016 * this list of conditions and the following disclaimer in the documentation 017 * and/or other materials provided with the distribution. 018 * 019 * * Neither the name of the University of Southampton nor the names of its 020 * contributors may be used to endorse or promote products derived from this 021 * software without specific prior written permission. 022 * 023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 024 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 025 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 027 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 028 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 030 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 032 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 033 */ 034package org.openimaj.util.pair; 035 036import java.util.ArrayList; 037import java.util.List; 038 039import gnu.trove.list.array.TLongArrayList; 040 041/** 042 * A pair of long and a generic type <Q> 043 * 044 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 045 * 046 * @param <Q> type of second object 047 */ 048public class LongObjectPair<Q> { 049 /** 050 * The first element of the pair 051 */ 052 public long first; 053 054 /** 055 * The first element of the pair 056 */ 057 public Q second; 058 059 /** 060 * Construct pair with given values 061 * 062 * @param f first value 063 * @param s second value 064 */ 065 public LongObjectPair(long f, Q s) {first=f; second=s;} 066 067 /** 068 * Construct empty pair 069 */ 070 public LongObjectPair() { } 071 072 /** 073 * Get the value of the first element 074 * @return the first value 075 */ 076 public long getFirst() { 077 return first; 078 } 079 080 /** 081 * Set the value of the first element 082 * @param first the value to set 083 */ 084 public void setFirst(long first) { 085 this.first = first; 086 } 087 088 /** 089 * Get the value of the second element 090 * @return the second 091 */ 092 public Q getSecond() { 093 return second; 094 } 095 096 /** 097 * Set the value of the second element 098 * @param second the value to set 099 */ 100 public void setSecond(Q second) { 101 this.second = second; 102 } 103 104 /** 105 * Create a pair from the given objects. 106 * 107 * @param <Q> Type of second object. 108 * @param t The first object. 109 * @param q The second object. 110 * @return The pair. 111 */ 112 public static <Q> LongObjectPair<Q> pair(long t, Q q) { 113 return new LongObjectPair<Q>(t, q); 114 } 115 116 /** 117 * Extract the first objects from a list of pairs. 118 * 119 * @param <Q> type of second object 120 * @param data the data 121 * @return extracted first objects 122 */ 123 public static <Q> TLongArrayList getFirst(Iterable<LongObjectPair<Q>> data) { 124 TLongArrayList extracted = new TLongArrayList(); 125 126 for (LongObjectPair<Q> item : data) 127 extracted.add(item.first); 128 129 return extracted; 130 } 131 132 /** 133 * Extract the second objects from a list of pairs. 134 * 135 * @param <Q> type of second object 136 * @param data the data 137 * @return extracted second objects 138 */ 139 public static <Q> List<Q> getSecond(Iterable<LongObjectPair<Q>> data) { 140 List<Q> extracted = new ArrayList<Q>(); 141 142 for (LongObjectPair<Q> item : data) 143 extracted.add(item.second); 144 145 return extracted; 146 } 147}