001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2023 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit https://imagingbook.com for additional details. 008 ******************************************************************************/ 009package imagingbook.common.util.tuples; 010 011/** 012 * <p> 013 * Elementary implementation of tuples, i.e, ordered sequences of items of arbitrary types. Tuples are generally 014 * immutable and their main use is to get methods return multiple values with maximum compile-time safety. A concrete 015 * tuple class is defined for each "arity", e.g., {@link Tuple2} for 2 elements. Currently tuple classes for 2, 3 and 4 016 * elements are defined. 017 * </p> 018 * <p> 019 * A tuple may be instantiated using either the class constructor, e.g., 020 * </p> 021 * <pre>new Tuple2<Integer, String>(10, "Foo")</pre> 022 * <p> 023 * or the associated static method 024 * </p> 025 * <pre>Tuple2.of(10, "Foo")</pre> 026 * Individual tuple elements can be accessed (read-only) by the associated field names, e.g. {@code f0}, {@code f1} ... 027 * etc. There are no getter methods. 028 * 029 * @author WB 030 */ 031public interface Tuple { 032 033 034 // ------------------------------------------------------------------------ 035 036// public static void main(String[] args) { 037// Tuple2<Integer, String> tA = new Tuple2<>(10, "Foo"); 038// Tuple tB = new Tuple2<Integer, String>(-3, "Bar"); 039// Tuple tC = Tuple2.from(17, "Kaputnik"); 040// System.out.println("tA = " + tA.toString()); 041// System.out.println("tB = " + tB.toString()); 042// System.out.println("tC = " + tC.toString()); 043// 044// int k = tA.get0(); 045// String s = tA.get1(); 046// 047// System.out.println("tA.f0 = " + tA.get0().toString()); 048// System.out.println("tA.f1 = " + tA.get1().toString()); 049// 050// System.out.println("tA class = " + tA.getClass()); 051// System.out.println("tB class = " + tB.getClass()); 052// System.out.println("tC class = " + tC.getClass()); 053// } 054} 055 056