Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started