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.listmatrix; 025 026 import java.util.Collection; 027 import java.util.Iterator; 028 import java.util.List; 029 import java.util.ListIterator; 030 031 import org.ujmp.core.enums.ValueType; 032 import org.ujmp.core.exceptions.MatrixException; 033 import org.ujmp.core.genericmatrix.stub.AbstractDenseGenericMatrix2D; 034 import org.ujmp.core.util.MathUtil; 035 036 public abstract class AbstractListMatrix<A> extends AbstractDenseGenericMatrix2D<A> implements 037 ListMatrix<A> { 038 039 private static final long serialVersionUID = -6776628601679785451L; 040 041 public abstract List<A> getList(); 042 043 public final long[] getSize() { 044 return new long[] { size(), 1 }; 045 } 046 047 public final void clear() { 048 getList().clear(); 049 } 050 051 public boolean add(A e) { 052 boolean ret = getList().add(e); 053 notifyGUIObject(); 054 return ret; 055 } 056 057 public void add(int index, A element) { 058 getList().add(index, element); 059 notifyGUIObject(); 060 } 061 062 public boolean addAll(Collection<? extends A> c) { 063 boolean ret = getList().addAll(c); 064 notifyGUIObject(); 065 return ret; 066 } 067 068 public boolean addAll(int index, Collection<? extends A> c) { 069 boolean ret = getList().addAll(index, c); 070 notifyGUIObject(); 071 return ret; 072 } 073 074 public boolean contains(Object o) { 075 return getList().contains(o); 076 } 077 078 public boolean containsAll(Collection<?> c) { 079 return getList().containsAll(c); 080 } 081 082 public A get(int index) { 083 return getList().get(index); 084 } 085 086 public int indexOf(Object o) { 087 return getList().indexOf(o); 088 } 089 090 091 public boolean isEmpty() { 092 return getList().isEmpty(); 093 } 094 095 public Iterator<A> iterator() { 096 return getList().iterator(); 097 } 098 099 public int lastIndexOf(Object o) { 100 return getList().lastIndexOf(o); 101 } 102 103 public ListIterator<A> listIterator() { 104 return getList().listIterator(); 105 } 106 107 public ListIterator<A> listIterator(int index) { 108 return getList().listIterator(); 109 } 110 111 public boolean remove(Object o) { 112 boolean ret = getList().remove(o); 113 notifyGUIObject(); 114 return ret; 115 } 116 117 public A remove(int index) { 118 A a = getList().remove(index); 119 notifyGUIObject(); 120 return a; 121 } 122 123 public boolean removeAll(Collection<?> c) { 124 boolean ret = getList().removeAll(c); 125 notifyGUIObject(); 126 return ret; 127 } 128 129 public boolean retainAll(Collection<?> c) { 130 boolean ret = getList().retainAll(c); 131 notifyGUIObject(); 132 return ret; 133 } 134 135 public A set(int index, A element) { 136 A a = getList().set(index, element); 137 notifyGUIObject(); 138 return a; 139 } 140 141 public int size() { 142 return getList().size(); 143 } 144 145 public List<A> subList(int fromIndex, int toIndex) { 146 return getList().subList(fromIndex, toIndex); 147 } 148 149 public A getObject(long row, long column) { 150 A a = getList().get((int) row); 151 return a; 152 } 153 154 public A getObject(int row, int column) { 155 A a = getList().get(row); 156 return a; 157 } 158 159 public void setObject(A value, long row, long column) { 160 getList().set((int) row, value); 161 notifyGUIObject(); 162 } 163 164 public void setObject(A value, int row, int column) { 165 getList().set(row, value); 166 notifyGUIObject(); 167 } 168 169 public Object[] toArray() { 170 return getList().toArray(); 171 } 172 173 public <T> T[] toArray(T[] a) { 174 return getList().toArray(a); 175 } 176 177 178 public double getAsDouble(long... coordinates) throws MatrixException { 179 return MathUtil.getDouble(getObject(coordinates)); 180 } 181 182 183 public void setAsDouble(double value, long... coordinates) throws MatrixException { 184 setAsObject(value, coordinates); 185 } 186 187 188 public ValueType getValueType() { 189 return ValueType.OBJECT; 190 } 191 192 193 public final StorageType getStorageType() { 194 return StorageType.LIST; 195 } 196 197 }