Answered step by step
Verified Expert Solution
Link Copied!

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 Table(Schema 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 insert(Tuple rec){
if (! rec.getSchema().equals(schema)){
throw new IllegalStateException("Error: 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 delete(Object key){
if (schema.getKey()== null){
throw new IllegalStateException("Error: table does not have a primary key. Can not delete.");
}
// TODO
throw new UnsupportedOperationException();
}
@Override
public Tuple lookup(Object key){
if (schema.getKey()== null){
throw new IllegalStateException("Error: table does not have a primary key. Can not lookup by key.");
}
// TODO
throw new UnsupportedOperationException();
}
@Override
public ITable lookup(String colname, Object value){
if (schema.getColumnIndex(colname)<0){
throw new IllegalStateException("Error: table does not contain column "+colname);
}
Table result = new Table(this.getSchema());
// find all tuples that satisfy the predicate colname=value
// 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 (tuples.isEmpty()){
return "Empty Table";
} else {
StringBuilder sb = new StringBuilder();
for (Tuple t : this){
sb.append(t.toString());
sb.append("
");
}
return sb.toString();
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions