001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.core.collections; 025 026 import java.io.Serializable; 027 import java.util.Collection; 028 import java.util.Iterator; 029 import java.util.List; 030 import java.util.ListIterator; 031 import java.util.Set; 032 033 import org.ujmp.core.exceptions.MatrixException; 034 import org.ujmp.core.interfaces.Wrapper; 035 036 public class SetToListWrapper<A> implements Wrapper<Set<A>>, List<A>, Serializable { 037 private static final long serialVersionUID = 4170885424845593802L; 038 039 private Set<A> set = null; 040 041 public SetToListWrapper(Set<A> set) { 042 this.set = set; 043 } 044 045 046 public Set<A> getWrappedObject() { 047 return set; 048 } 049 050 051 public void setWrappedObject(Set<A> object) { 052 this.set = object; 053 } 054 055 056 public boolean add(A e) { 057 return set.add(e); 058 } 059 060 061 public void add(int index, A element) { 062 throw new MatrixException("not implemented"); 063 } 064 065 066 public boolean addAll(Collection<? extends A> c) { 067 return set.addAll(c); 068 } 069 070 071 public boolean addAll(int index, Collection<? extends A> c) { 072 throw new MatrixException("not implemented"); 073 } 074 075 076 public void clear() { 077 set.clear(); 078 } 079 080 081 public boolean contains(Object o) { 082 return set.contains(o); 083 } 084 085 086 public boolean containsAll(Collection<?> c) { 087 return set.containsAll(c); 088 } 089 090 091 public A get(int index) { 092 Iterator<A> it = set.iterator(); 093 for (int i = 0; i < index && it.hasNext(); i++) { 094 it.next(); 095 } 096 if (it.hasNext()) { 097 return it.next(); 098 } else { 099 return null; 100 } 101 } 102 103 104 public int indexOf(Object o) { 105 Iterator<A> it = set.iterator(); 106 for (int i = 0; it.hasNext(); i++) { 107 A a = it.next(); 108 if (o.equals(a)) { 109 return i; 110 } 111 } 112 return -1; 113 } 114 115 116 public boolean isEmpty() { 117 return set.isEmpty(); 118 } 119 120 121 public Iterator<A> iterator() { 122 return set.iterator(); 123 } 124 125 126 public int lastIndexOf(Object o) { 127 return indexOf(o); 128 } 129 130 131 public ListIterator<A> listIterator() { 132 throw new MatrixException("not implemented"); 133 } 134 135 136 public ListIterator<A> listIterator(int index) { 137 throw new MatrixException("not implemented"); 138 } 139 140 141 public boolean remove(Object o) { 142 return set.remove(o); 143 } 144 145 146 public A remove(int index) { 147 throw new MatrixException("not implemented"); 148 } 149 150 151 public boolean removeAll(Collection<?> c) { 152 return set.removeAll(c); 153 } 154 155 156 public boolean retainAll(Collection<?> c) { 157 return set.retainAll(c); 158 } 159 160 161 public A set(int index, A element) { 162 throw new MatrixException("not implemented"); 163 } 164 165 166 public int size() { 167 return set.size(); 168 } 169 170 171 public List<A> subList(int fromIndex, int toIndex) { 172 throw new MatrixException("not implemented"); 173 } 174 175 176 public Object[] toArray() { 177 return set.toArray(); 178 } 179 180 181 public <T> T[] toArray(T[] a) { 182 return set.toArray(a); 183 } 184 185 public String toString() { 186 return set.toString(); 187 } 188 189 }