1 /* 2 3 dsh-venn Lightweight components for venn diagrams. 4 Copyright (c) 2009-2013 held jointly by the individual authors. 5 6 This library is free software; you can redistribute it and/or modify it 7 under the terms of the GNU Lesser General Public License as published 8 by the Free Software Foundation; either version 3 of the License, or (at 9 your option) any later version. 10 11 This library is distributed in the hope that it will be useful, but WITHOUT 12 ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with this library; if not, write to the Free Software Foundation, 18 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 19 20 > http://www.fsf.org/licensing/licenses/lgpl.html 21 > http://www.opensource.org/licenses/lgpl-license.php 22 23 */ 24 package org.dishevelled.venn.model; 25 26 import java.util.List; 27 import java.util.Set; 28 29 import org.dishevelled.venn.BinaryVennModel; 30 import org.dishevelled.venn.TernaryVennModel; 31 import org.dishevelled.venn.QuaternaryVennModel; 32 import org.dishevelled.venn.VennModel; 33 34 /** 35 * Venn diagram model implementations. 36 * 37 * @author Michael Heuer 38 */ 39 public final class VennModels 40 { 41 42 /** 43 * Private no-arg constructor. 44 */ 45 private VennModels() 46 { 47 // empty 48 } 49 50 51 /** 52 * Create and return a new venn model with the specified sets. 53 * 54 * @param <E> value type 55 * @param sets list of sets, must not be null and must contain at least two sets 56 * @return a new venn model with the specified sets 57 */ 58 public static <E> VennModel<E> createVennModel(final List<Set<E>> sets) 59 { 60 if (sets == null) 61 { 62 throw new IllegalArgumentException("sets must not be null"); 63 } 64 switch (sets.size()) 65 { 66 case 0: 67 case 1: 68 throw new IllegalArgumentException("sets must contain at least two sets"); 69 case 2: 70 return createVennModel(sets.get(0), sets.get(1)); 71 case 3: 72 return createVennModel(sets.get(0), sets.get(1), sets.get(2)); 73 case 4: 74 return createVennModel(sets.get(0), sets.get(1), sets.get(2), sets.get(3)); 75 default: 76 break; 77 } 78 return new VennModelImpl<E>(sets); 79 } 80 81 /** 82 * Create and return a new binary venn model with the specified sets. 83 * 84 * @param <E> value type 85 * @param first first set, must not be null 86 * @param second second set, must not be null 87 * @return a new binary venn model with the specified sets 88 */ 89 public static <E> BinaryVennModel<E> createVennModel(final Set<? extends E> first, 90 final Set<? extends E> second) 91 { 92 return new BinaryVennModelImpl<E>(first, second); 93 } 94 95 /** 96 * Create and return a new ternary venn model with the specified sets. 97 * 98 * @param <E> value type 99 * @param first first set, must not be null 100 * @param second second set, must not be null 101 * @param third third set, must not be null 102 * @return a new ternary venn model with the specified sets 103 */ 104 public static <E> TernaryVennModel<E> createVennModel(final Set<? extends E> first, 105 final Set<? extends E> second, 106 final Set<? extends E> third) 107 { 108 return new TernaryVennModelImpl<E>(first, second, third); 109 } 110 111 /** 112 * Create and return a new quaternary venn model with the specified sets. 113 * 114 * @param <E> value type 115 * @param first first set, must not be null 116 * @param second second set, must not be null 117 * @param third third set, must not be null 118 * @param fourth fourth set, must not be null 119 * @return a new quaternary venn model with the specified sets 120 */ 121 public static <E> QuaternaryVennModel<E> createVennModel(final Set<? extends E> first, 122 final Set<? extends E> second, 123 final Set<? extends E> third, 124 final Set<? extends E> fourth) 125 { 126 return new QuaternaryVennModelImpl<E>(first, second, third, fourth); 127 } 128 }