001: /*
002: This source file is part of Smyle, a database library.
003: For up-to-date information, see http://www.drjava.de/smyle
004: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: For full license text, see doc/license/lgpl.txt in this distribution
021: */
022:
023: package drjava.smyle;
024:
025: import java.util.*;
026: import org.artsProject.mcop.Type;
027: import org.artsProject.mcop.core.TypeDef;
028: import org.artsProject.util.*;
029: import drjava.smyle.meta.*;
030:
031: /** A data table in a Smyle store.
032: Table is an extension of the java.util.List interface, so you can use a table just like you
033: use a standard Java Vector. Additionally, table defines methods to perform convenient
034: and efficient queries.
035: <p>
036: Every row in the table is of type "T", where T must be a class generated from an IDL
037: file by the CodeGenerator.
038: */
039: public interface Table<T extends Struct<T>> extends java.util.List<T> {
040: // methods inherited from java.util.List (repeated for completeness)
041:
042: public int size();
043:
044: public boolean isEmpty();
045:
046: public T get(int nr);
047:
048: public Iterator<T> iterator();
049:
050: public int indexOf(T t);
051:
052: public boolean add(T t);
053:
054: public boolean addAll(Collection<T> c);
055:
056: public boolean remove(T t);
057:
058: public T remove(int index);
059:
060: public T set(int index, T t);
061:
062: public void clear();
063:
064: // accessors
065:
066: public T first();
067:
068: // filter based accessors
069:
070: public boolean contains(Filter<T> filter);
071:
072: public int count(Filter<T> filter);
073:
074: public Iterator<T> iterator(Filter<T> filter);
075:
076: /** if there are any records that satisfy the filter, get returns one of
077: them; otherwise it returns null */
078: public T get(Filter<T> filter);
079:
080: public int indexOf(Filter<T> filter);
081:
082: public List<T> subList(Filter<T> filter);
083:
084: /** if there is a record that satisfies the filter, returns it;
085: otherwise creates an instance of T that matches the filter and
086: has default values in all fields not tested by the filter */
087: public T getOrCreate(Filter<T> filter);
088:
089: /** if there is a record that satisfies the filter, replace it with t;
090: otherwise add t to the table */
091: public void put(Filter<T> filter, T t);
092:
093: // function based accessors
094:
095: public IntVector getUniqueValues(Function<T, Integer> function);
096:
097: public <A> Map<A, Integer> getUniqueValueCounts(
098: Function<T, A> function);
099:
100: public <A> Map<A, Integer> getUniqueValueCounts(
101: Function<T, A> function, Filter<T> filter);
102:
103: // filter based mutators
104:
105: public void removeAll(Filter<T> filter);
106:
107: // schema handling
108:
109: public TypeDef getSchema();
110:
111: // auto increment
112:
113: public void setAutoIncrementField(Field<T, Integer> field);
114: }
|