Question: Please help complete below java code. I have already have Tuples, Schema classes and other interfaces. package heapdb; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public
Please help complete below java code. I have already have Tuples, Schema classes and other interfaces. package heapdb;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Table implements ITable
private List tuples;
private Schema schema;
public TableSchema schema
this.schema schema;
tuples new ArrayList;
@Override
public Schema getSchema
return schema;
@Override
public int size
return tuples.size;
@Override
public void close
do nothing
@Override
public boolean insertTuple rec
if rec.getSchemaequalsschema
throw new IllegalStateExceptionError: tuple schema does not match table schema.";
if schema has no key, then just add the tuple.
if schema has key, see if key already exists in table
TODO
throw new UnsupportedOperationException;
@Override
public boolean deleteObject key
if schemagetKey null
throw new IllegalStateExceptionError: table does not have a primary key. Can not delete.";
TODO
throw new UnsupportedOperationException;
@Override
public Tuple lookupObject key
if schemagetKey null
throw new IllegalStateExceptionError: table does not have a primary key. Can not lookup by key.";
TODO
throw new UnsupportedOperationException;
@Override
public ITable lookupString colname, Object value
if schemagetColumnIndexcolname
throw new IllegalStateExceptionError: table does not contain column colname;
Table result new TablethisgetSchema;
find all tuples that satisfy the predicate colnamevalue
and insert the tuples to result table.
return the result
TODO
throw new UnsupportedOperationException;
@Override
public Iterator iterator
return tuples.iterator;
public String toString
if tuplesisEmpty
return "Empty Table";
else
StringBuilder sb new StringBuilder;
for Tuple t : this
sbappendttoString;
sbappend
;
return sbtoString;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
