refactor database class hierarchy

This commit is contained in:
Eyck Jentzsch 2020-11-28 10:22:22 +01:00
parent db838efc65
commit 21d83f93dc
22 changed files with 217 additions and 190 deletions

View File

@ -20,10 +20,9 @@ import java.util.List;
import com.minres.scviewer.database.AssociationType; import com.minres.scviewer.database.AssociationType;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxAttribute; import com.minres.scviewer.database.ITxAttribute;
import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.ITxGenerator; import com.minres.scviewer.database.ITxGenerator;
import com.minres.scviewer.database.ITxRelation; import com.minres.scviewer.database.ITxRelation;
import com.minres.scviewer.database.ITxStream; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.sqlite.db.IDatabase; import com.minres.scviewer.database.sqlite.db.IDatabase;
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler; import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
import com.minres.scviewer.database.sqlite.tables.ScvStream; import com.minres.scviewer.database.sqlite.tables.ScvStream;
@ -55,7 +54,7 @@ public class Tx implements ITx {
} }
@Override @Override
public ITxStream<ITxEvent> getStream() { public IWaveform getStream() {
return trStream; return trStream;
} }

View File

@ -10,16 +10,17 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database.sqlite; package com.minres.scviewer.database.sqlite;
import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxEvent; import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.IWaveformEvent;
public class TxEvent implements ITxEvent { public class TxEvent implements ITxEvent {
private final Type type; private final EventKind type;
private ITx tx; private ITx tx;
public TxEvent(Type type, ITx tx) { public TxEvent(EventKind type, ITx tx) {
super(); super();
this.type = type; this.type = type;
this.tx = tx; this.tx = tx;
@ -27,26 +28,21 @@ public class TxEvent implements ITxEvent {
@Override @Override
public Long getTime() { public Long getTime() {
return type==Type.BEGIN?tx.getBeginTime():tx.getEndTime(); return type==EventKind.BEGIN?tx.getBeginTime():tx.getEndTime();
} }
@Override @Override
public IWaveformEvent duplicate() throws CloneNotSupportedException { public IEvent duplicate() throws CloneNotSupportedException {
return new TxEvent(type, tx); return new TxEvent(type, tx);
} }
@Override
public int compareTo(IWaveformEvent o) {
return getTime().compareTo(o.getTime());
}
@Override @Override
public ITx getTransaction() { public ITx getTransaction() {
return tx; return tx;
} }
@Override @Override
public Type getType() { public EventKind getKind() {
return type; return type;
} }
@ -54,4 +50,9 @@ public class TxEvent implements ITxEvent {
public String toString() { public String toString() {
return type.toString()+"@"+getTime()+" of tx #"+tx.getId(); return type.toString()+"@"+getTime()+" of tx #"+tx.getId();
} }
@Override
public Class<?> getType() {
return TxEvent.class;
}
} }

View File

@ -13,18 +13,17 @@ package com.minres.scviewer.database.sqlite;
import java.util.List; import java.util.List;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.ITxGenerator; import com.minres.scviewer.database.ITxGenerator;
import com.minres.scviewer.database.ITxStream; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.sqlite.tables.ScvGenerator; import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
public class TxGenerator implements ITxGenerator { public class TxGenerator implements ITxGenerator {
private ITxStream<ITxEvent> stream; private IWaveform stream;
private ScvGenerator scvGenerator; private ScvGenerator scvGenerator;
public TxGenerator(ITxStream<ITxEvent> stream, ScvGenerator scvGenerator) { public TxGenerator(IWaveform stream, ScvGenerator scvGenerator) {
this.stream=stream; this.stream=stream;
this.scvGenerator=scvGenerator; this.scvGenerator=scvGenerator;
} }
@ -35,7 +34,7 @@ public class TxGenerator implements ITxGenerator {
} }
@Override @Override
public ITxStream<ITxEvent> getStream() { public IWaveform getStream() {
return stream; return stream;
} }

View File

@ -14,19 +14,17 @@ import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Vector;
import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.HierNode; import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.ITxGenerator; import com.minres.scviewer.database.ITxGenerator;
import com.minres.scviewer.database.ITxStream;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.RelationType;
@ -36,7 +34,7 @@ import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
import com.minres.scviewer.database.sqlite.tables.ScvStream; import com.minres.scviewer.database.sqlite.tables.ScvStream;
import com.minres.scviewer.database.sqlite.tables.ScvTx; import com.minres.scviewer.database.sqlite.tables.ScvTx;
public class TxStream extends HierNode implements ITxStream<ITxEvent> { public class TxStream extends HierNode implements IWaveform {
private IDatabase database; private IDatabase database;
@ -52,7 +50,7 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
private Integer maxConcurrency; private Integer maxConcurrency;
private TreeMap<Long, List<ITxEvent>> events; private TreeMap<Long, IEvent[]> events;
private List<RelationType> usedRelationsList; private List<RelationType> usedRelationsList;
@ -84,7 +82,6 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
return scvStream.getKind(); return scvStream.getKind();
} }
@Override
public List<ITxGenerator> getGenerators() { public List<ITxGenerator> getGenerators() {
if(generators==null){ if(generators==null){
SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<ScvGenerator>( SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<ScvGenerator>(
@ -136,12 +133,12 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
} }
@Override @Override
public NavigableMap<Long, List<ITxEvent>> getEvents(){ public NavigableMap<Long, IEvent[]> getEvents(){
if(events==null){ if(events==null){
events=new TreeMap<Long, List<ITxEvent>>(); events=new TreeMap<Long, IEvent[]>();
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){ for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
putEvent(new TxEvent(TxEvent.Type.BEGIN, entry.getValue())); putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
putEvent(new TxEvent(TxEvent.Type.END, entry.getValue())); putEvent(new TxEvent(EventKind.END, entry.getValue()));
} }
} }
return events; return events;
@ -149,12 +146,14 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
private void putEvent(TxEvent ev){ private void putEvent(TxEvent ev){
Long time = ev.getTime(); Long time = ev.getTime();
if(!events.containsKey(time)){ if(events.containsKey(time)) {
Vector<ITxEvent> vector=new Vector<ITxEvent>(); IEvent[] oldV = events.get(time);
vector.add(ev); IEvent[] newV = new IEvent[oldV.length+1];
events.put(time, vector); System.arraycopy(oldV, 0, newV, 0, oldV.length);
newV[oldV.length]=ev;
events.put(time, newV);
} else { } else {
events.get(time).add(ev); events.put(time, new IEvent[] {ev});
} }
} }
@ -177,7 +176,7 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
} }
@Override @Override
public Collection<ITxEvent> getWaveformEventsAtTime(Long time) { public IEvent[] getEventsAtTime(Long time) {
return getEvents().get(time); return getEvents().get(time);
} }
@ -196,4 +195,18 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
return(other instanceof TxStream && this.getId().equals(other.getId())); return(other instanceof TxStream && this.getId().equals(other.getId()));
} }
@Override
public IEvent[] getEventsBeforeTime(Long time) {
Entry<Long, IEvent[]> e = events.floorEntry(time);
if(e==null)
return null;
else
return events.floorEntry(time).getValue();
}
@Override
public Class<?> getType() {
return TxEvent.class;
}
} }

View File

@ -23,7 +23,6 @@ import groovy.io.FileType
import com.minres.scviewer.database.AssociationType import com.minres.scviewer.database.AssociationType
import com.minres.scviewer.database.DataType import com.minres.scviewer.database.DataType
import com.minres.scviewer.database.ITxGenerator import com.minres.scviewer.database.ITxGenerator
import com.minres.scviewer.database.ITxStream
import com.minres.scviewer.database.IWaveform import com.minres.scviewer.database.IWaveform
import com.minres.scviewer.database.IWaveformDb import com.minres.scviewer.database.IWaveformDb
import com.minres.scviewer.database.IWaveformDbLoader import com.minres.scviewer.database.IWaveformDbLoader
@ -163,7 +162,7 @@ public class TextDbLoader implements IWaveformDbLoader{
case "scv_tr_generator": case "scv_tr_generator":
if ((matcher = line =~ /^scv_tr_generator\s+\(ID\s+(\d+),\s+name\s+"([^"]+)",\s+scv_tr_stream\s+(\d+),$/)) { if ((matcher = line =~ /^scv_tr_generator\s+\(ID\s+(\d+),\s+name\s+"([^"]+)",\s+scv_tr_stream\s+(\d+),$/)) {
def id = Integer.parseInt(matcher[0][1]) def id = Integer.parseInt(matcher[0][1])
ITxStream stream=streamsById[Integer.parseInt(matcher[0][3])] TxStream stream=streamsById[Integer.parseInt(matcher[0][3])] as TxStream
generator=new TxGenerator(id, stream, matcher[0][2]) generator=new TxGenerator(id, stream, matcher[0][2])
stream.generators<<generator stream.generators<<generator
generatorsById[id]=generator generatorsById[id]=generator

View File

@ -1,36 +1,41 @@
package com.minres.scviewer.database.text; package com.minres.scviewer.database.text;
import com.minres.scviewer.database.EventKind
import com.minres.scviewer.database.ITx import com.minres.scviewer.database.ITx
import com.minres.scviewer.database.ITxEvent import com.minres.scviewer.database.ITxEvent
import com.minres.scviewer.database.IWaveformEvent
class TxEvent implements ITxEvent { class TxEvent implements ITxEvent {
final ITxEvent.Type type; final EventKind kind;
final Tx transaction; final Tx transaction;
final Long time final Long time
TxEvent(ITxEvent.Type type, ITx transaction) { TxEvent(EventKind kind, ITx transaction) {
super(); super();
this.type = type; this.kind = kind;
this.transaction = transaction; this.transaction = transaction;
this.time = type==ITxEvent.Type.BEGIN?transaction.beginTime:transaction.endTime this.time = kind==EventKind.BEGIN?transaction.beginTime:transaction.endTime
} }
@Override @Override
IWaveformEvent duplicate() throws CloneNotSupportedException { ITxEvent duplicate() throws CloneNotSupportedException {
new TxEvent(type, transaction, time) new TxEvent(type, transaction, time)
} }
@Override // @Override
int compareTo(IWaveformEvent o) { // int compareTo(IWaveformEvent o) {
time.compareTo(o.time) // time.compareTo(o.time)
} // }
@Override @Override
String toString() { String toString() {
type.toString()+"@"+time+" of tx #"+transaction.id; kind.toString()+"@"+time+" of tx #"+transaction.id;
}
@Override
Class<?> getType() {
return this.getClass();
} }
} }

View File

@ -15,15 +15,13 @@ import java.util.List;
import com.minres.scviewer.database.ITxAttributeType import com.minres.scviewer.database.ITxAttributeType
import com.minres.scviewer.database.ITxAttribute; import com.minres.scviewer.database.ITxAttribute;
import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.ITxGenerator; import com.minres.scviewer.database.ITxGenerator;
import com.minres.scviewer.database.ITxStream; import com.minres.scviewer.database.IWaveform
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.IWaveformEvent;
class TxGenerator implements ITxGenerator{ class TxGenerator implements ITxGenerator{
Long id Long id
TxStream stream IWaveform stream
String name String name
Boolean active = false Boolean active = false
ArrayList<ITx> transactions=[] ArrayList<ITx> transactions=[]
@ -39,7 +37,7 @@ class TxGenerator implements ITxGenerator{
this.name=name this.name=name
} }
ITxStream<? extends ITxEvent> getStream(){ IWaveform getStream(){
return stream; return stream;
} }

View File

@ -16,20 +16,21 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.Map.Entry
import org.mapdb.Serializer import org.mapdb.Serializer
import com.minres.scviewer.database.ITxEvent; import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb import com.minres.scviewer.database.IWaveformDb
import com.minres.scviewer.database.IWaveformEvent
import com.minres.scviewer.database.ITxGenerator import com.minres.scviewer.database.ITxGenerator
import com.minres.scviewer.database.EventKind
import com.minres.scviewer.database.HierNode; import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent
import com.minres.scviewer.database.IHierNode import com.minres.scviewer.database.IHierNode
import com.minres.scviewer.database.ITxStream
import com.minres.scviewer.database.ITx import com.minres.scviewer.database.ITx
class TxStream extends HierNode implements ITxStream { class TxStream extends HierNode implements IWaveform {
Long id Long id
@ -43,7 +44,7 @@ class TxStream extends HierNode implements ITxStream {
int maxConcurrency int maxConcurrency
private TreeMap<Long, List<ITxEvent>> events private TreeMap<Long, IEvent[]> events
TxStream(TextDbLoader loader, int id, String name, String kind){ TxStream(TextDbLoader loader, int id, String name, String kind){
super(name) super(name)
@ -70,14 +71,14 @@ class TxStream extends HierNode implements ITxStream {
if(!maxConcurrency){ if(!maxConcurrency){
generators.each {TxGenerator generator -> generators.each {TxGenerator generator ->
generator.transactions.each{ Tx tx -> generator.transactions.each{ Tx tx ->
putEvent(new TxEvent(ITxEvent.Type.BEGIN, tx)) putEvent(new TxEvent(EventKind.BEGIN, tx))
putEvent(new TxEvent(ITxEvent.Type.END, tx)) putEvent(new TxEvent(EventKind.END, tx))
} }
} }
def rowendtime = [0] def rowendtime = [0]
events.keySet().each{long time -> events.keySet().each{long time ->
def value=events.get(time) def value=events.get(time)
def starts=value.findAll{ITxEvent event ->event.type==ITxEvent.Type.BEGIN} def starts=value.findAll{ITxEvent event ->event.type==EventKind.BEGIN}
starts.each {ITxEvent event -> starts.each {ITxEvent event ->
Tx tx = event.transaction Tx tx = event.transaction
def rowIdx = 0 def rowIdx = 0
@ -102,12 +103,12 @@ class TxStream extends HierNode implements ITxStream {
} }
@Override @Override
public NavigableMap getEvents() { public NavigableMap<Long, IEvent[]> getEvents() {
return events; return events;
} }
@Override @Override
public Collection getWaveformEventsAtTime(Long time) { public IEvent[] getEventsAtTime(Long time) {
return events.get(time); return events.get(time);
} }
@ -116,4 +117,18 @@ class TxStream extends HierNode implements ITxStream {
return(other instanceof TxStream && this.getId()==other.getId()); return(other instanceof TxStream && this.getId()==other.getId());
} }
@Override
public IEvent[] getEventsBeforeTime(Long time) {
Entry<Long, IEvent[]> e = events.floorEntry(time);
if(e==null)
return null;
else
return events.floorEntry(time).getValue();
}
@Override
public Class<?> getType() {
return TxEvent.class;
}
} }

View File

@ -24,7 +24,8 @@ import java.util.Vector;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import com.minres.scviewer.database.BitVector; import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.ISignal; import com.minres.scviewer.database.DoubleVal;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader; import com.minres.scviewer.database.IWaveformDbLoader;
@ -96,7 +97,7 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
if(!res) throw new InputFormatException(); if(!res) throw new InputFormatException();
// calculate max time of database // calculate max time of database
for(IWaveform waveform:signals) { for(IWaveform waveform:signals) {
NavigableMap<Long, ?> events =((ISignal<?>)waveform).getEvents(); NavigableMap<Long, IEvent[]> events =waveform.getEvents();
if(events.size()>0) if(events.size()>0)
maxTime= Math.max(maxTime, events.lastKey()); maxTime= Math.max(maxTime, events.lastKey());
} }
@ -108,8 +109,8 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
Object val = events.lastEntry().getValue(); Object val = events.lastEntry().getValue();
if(val instanceof BitVector) { if(val instanceof BitVector) {
((VCDSignal<BitVector>)s).addSignalChange(maxTime, (BitVector) val); ((VCDSignal<BitVector>)s).addSignalChange(maxTime, (BitVector) val);
} else if(val instanceof Double) } else if(val instanceof DoubleVal)
((VCDSignal<Double>)s).addSignalChange(maxTime, (Double) val); ((VCDSignal<DoubleVal>)s).addSignalChange(maxTime, (DoubleVal) val);
} }
} }
} }
@ -162,8 +163,8 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
int id = signals.size(); int id = signals.size();
assert(width>=0); assert(width>=0);
if(width==0) { if(width==0) {
signals.add( i<0 ? new VCDSignal<Double>(db, id, netName, width) : signals.add( i<0 ? new VCDSignal<DoubleVal>(db, id, netName, width) :
new VCDSignal<Double>((VCDSignal<Double>)signals.get(i), id, netName)); new VCDSignal<DoubleVal>((VCDSignal<DoubleVal>)signals.get(i), id, netName));
} else if(width>0){ } else if(width>0){
signals.add( i<0 ? new VCDSignal<BitVector>(db, id, netName, width) : signals.add( i<0 ? new VCDSignal<BitVector>(db, id, netName, width) :
new VCDSignal<BitVector>((VCDSignal<BitVector>)signals.get(i), id, netName)); new VCDSignal<BitVector>((VCDSignal<BitVector>)signals.get(i), id, netName));
@ -188,7 +189,7 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
public void appendTransition(int signalId, long currentTime, BitVector value) { public void appendTransition(int signalId, long currentTime, BitVector value) {
VCDSignal<BitVector> signal = (VCDSignal<BitVector>) signals.get(signalId); VCDSignal<BitVector> signal = (VCDSignal<BitVector>) signals.get(signalId);
Long time = currentTime* TIME_RES; Long time = currentTime* TIME_RES;
signal.getEvents().put(time, value); signal.addSignalChange(time, value);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -197,11 +198,9 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void appendTransition(int signalId, long currentTime, double value) { public void appendTransition(int signalId, long currentTime, double value) {
VCDSignal<?> signal = (VCDSignal<?>) signals.get(signalId); VCDSignal<DoubleVal> signal = (VCDSignal<DoubleVal>) signals.get(signalId);
Long time = currentTime* TIME_RES; Long time = currentTime* TIME_RES;
if(signal.getWidth()==0){ signal.addSignalChange(time, new DoubleVal(value));
((VCDSignal<Double>)signal).getEvents().put(time, value);
}
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -15,12 +15,11 @@ import java.util.NavigableMap;
import java.util.TreeMap; import java.util.TreeMap;
import com.minres.scviewer.database.HierNode; import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.ISignal; import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformEvent;
public class VCDSignal<T> extends HierNode implements ISignal<T> { public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
private long id; private long id;
@ -34,7 +33,7 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
private IWaveformDb db; private IWaveformDb db;
private TreeMap<Long, T> values; private NavigableMap<Long, IEvent[]> values;
public VCDSignal(IWaveformDb db, String name) { public VCDSignal(IWaveformDb db, String name) {
this(db, 0, name, 1); this(db, 0, name, 1);
@ -50,17 +49,17 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
fullName=name; fullName=name;
this.id=id; this.id=id;
this.width=width; this.width=width;
this.values=new TreeMap<Long, T>(); this.values=new TreeMap<Long, IEvent[]>();
} }
@SuppressWarnings("unchecked") public VCDSignal(VCDSignal<T> other, int id, String name) {
public VCDSignal(ISignal<T> other, int id, String name) {
super(name); super(name);
fullName=name; fullName=name;
this.id=id; this.id=id;
assert(other instanceof VCDSignal<?>); assert(other instanceof VCDSignal<?>);
this.width=((VCDSignal<? extends IWaveformEvent>)other).width; VCDSignal<T> o = (VCDSignal<T>)other;
this.values=((VCDSignal<T>)other).values; this.width=o.width;
this.values=o.values;
this.db=other.getDb(); this.db=other.getDb();
} }
@ -93,22 +92,30 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
} }
public void addSignalChange(Long time, T value){ public void addSignalChange(Long time, T value){
values.put(time, value); if(values.containsKey(time)) {
IEvent[] oldV = values.get(time);
IEvent[] newV = new IEvent[oldV.length+1];
System.arraycopy(oldV, 0, newV, 0, oldV.length);
newV[oldV.length]=value;
values.put(time, newV);
} else {
values.put(time, new IEvent[] {value});
}
} }
@Override @Override
public NavigableMap<Long, T> getEvents() { public NavigableMap<Long, IEvent[]> getEvents() {
return values; return values;
} }
@Override @Override
public T getWaveformValueAtTime(Long time) { public IEvent[] getEventsAtTime(Long time) {
return values.get(time); return values.get(time);
} }
@Override @Override
public T getWaveformValueBeforeTime(Long time) { public IEvent[] getEventsBeforeTime(Long time) {
Entry<Long, T> e = values.floorEntry(time); Entry<Long, IEvent[]> e = values.floorEntry(time);
if(e==null) if(e==null)
return null; return null;
else else
@ -125,6 +132,9 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
return dummy.getClass(); return dummy.getClass();
} }
@Override
public int getMaxConcurrency() {
return 1;
}
} }

View File

@ -10,7 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database; package com.minres.scviewer.database;
public class BitVector { public class BitVector implements IEvent {
private final int width; private final int width;
@ -166,5 +166,20 @@ public class BitVector {
} }
return res; return res;
} }
@Override
public EventKind getKind() {
return EventKind.SINGLE;
}
@Override
public Class<?> getType() {
return this.getClass();
}
@Override
public IEvent duplicate() throws CloneNotSupportedException {
return (IEvent)this.clone();
}
} }

View File

@ -0,0 +1,26 @@
package com.minres.scviewer.database;
public class DoubleVal implements IEvent {
final double value;
public DoubleVal(double value) {
this.value=value;
}
@Override
public EventKind getKind() {
return EventKind.SINGLE;
}
@Override
public Class<?> getType() {
return this.getClass();
}
@Override
public IEvent duplicate() throws CloneNotSupportedException {
return (IEvent) clone();
}
}

View File

@ -0,0 +1,5 @@
package com.minres.scviewer.database;
public enum EventKind {
SINGLE, BEGIN, END
}

View File

@ -0,0 +1,11 @@
package com.minres.scviewer.database;
public interface IEvent {
public IEvent duplicate() throws CloneNotSupportedException;
public EventKind getKind();
public Class<?> getType();
}

View File

@ -1,26 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database;
import java.util.NavigableMap;
public interface ISignal<T> extends IWaveform{
public NavigableMap<Long, T> getEvents();
public T getWaveformValueAtTime(Long time);
public T getWaveformValueBeforeTime(Long time);
public Class<?> getType();
}

View File

@ -17,7 +17,7 @@ public interface ITx extends Comparable<ITx>{
public Long getId(); public Long getId();
public ITxStream<ITxEvent> getStream(); public IWaveform getStream();
public ITxGenerator getGenerator(); public ITxGenerator getGenerator();

View File

@ -10,10 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database; package com.minres.scviewer.database;
public interface ITxEvent extends IWaveformEvent { public interface ITxEvent extends IEvent {
enum Type {BEGIN, END};
public Long getTime();
public ITx getTransaction(); public ITx getTransaction();
public Type getType();
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public interface ITxGenerator { public interface ITxGenerator {
public Long getId(); public Long getId();
public ITxStream<ITxEvent> getStream(); public IWaveform getStream();
public String getName(); public String getName();
public List<ITx> getTransactions(); public List<ITx> getTransactions();
} }

View File

@ -1,27 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database;
import java.util.Collection;
import java.util.List;
import java.util.NavigableMap;
public interface ITxStream<T extends ITxEvent> extends IWaveform {
public List<ITxGenerator> getGenerators();
public int getMaxConcurrency();
public NavigableMap<Long, List<ITxEvent>> getEvents();
public Collection<T> getWaveformEventsAtTime(Long time);
}

View File

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database; package com.minres.scviewer.database;
import java.util.NavigableMap;
public interface IWaveform extends IHierNode { public interface IWaveform extends IHierNode {
@ -21,4 +22,14 @@ public interface IWaveform extends IHierNode {
public Boolean equals(IWaveform other); public Boolean equals(IWaveform other);
public NavigableMap<Long, IEvent[]> getEvents();
public IEvent[] getEventsAtTime(Long time);
public IEvent[] getEventsBeforeTime(Long time);
public Class<?> getType();
public int getMaxConcurrency();
} }

View File

@ -1,20 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database;
public interface IWaveformEvent extends Comparable<IWaveformEvent>{
public Long getTime();
public IWaveformEvent duplicate() throws CloneNotSupportedException;
}

View File

@ -25,12 +25,11 @@ import org.junit.Test;
import com.minres.scviewer.database.AssociationType; import com.minres.scviewer.database.AssociationType;
import com.minres.scviewer.database.DataType; import com.minres.scviewer.database.DataType;
import com.minres.scviewer.database.ISignal; import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxAttribute; import com.minres.scviewer.database.ITxAttribute;
import com.minres.scviewer.database.ITxEvent; import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.ITxEvent.Type;
import com.minres.scviewer.database.ITxStream;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory; import com.minres.scviewer.database.IWaveformDbFactory;
@ -71,13 +70,11 @@ public class DatabaseServicesTest {
assertEquals(14, waves.size()); assertEquals(14, waves.size());
assertEquals(2, waveformDb.getChildNodes().size()); assertEquals(2, waveformDb.getChildNodes().size());
IWaveform bus_data_wave = waves.get(0); IWaveform bus_data_wave = waves.get(0);
ISignal<?> bus_data_sig = (ISignal<?>) bus_data_wave; Entry<Long, IEvent[]> bus_data_entry = bus_data_wave.getEvents().floorEntry(1400000000L);
Entry<Long, ?> bus_data_entry = bus_data_sig.getEvents().floorEntry(1400000000L); assertTrue("01111000".equals(bus_data_entry.getValue()[0].toString()));
assertTrue("01111000".equals(bus_data_entry.getValue().toString()));
IWaveform rw_wave = waves.get(2); IWaveform rw_wave = waves.get(2);
ISignal<?> rw_sig = (ISignal<?>) rw_wave; Entry<Long, IEvent[]> rw_entry = rw_wave.getEvents().floorEntry(2360000000L);
Entry<Long, ?> rw_entry = rw_sig.getEvents().floorEntry(2360000000L); assertTrue("1".equals(rw_entry.getValue()[0].toString()));
assertTrue("1".equals(rw_entry.getValue().toString()));
} }
@Test @Test
@ -119,19 +116,17 @@ public class DatabaseServicesTest {
assertEquals(1, waveformDb.getChildNodes().size()); assertEquals(1, waveformDb.getChildNodes().size());
List<IWaveform> waves = waveformDb.getAllWaves(); List<IWaveform> waves = waveformDb.getAllWaves();
assertEquals(3, waves.size()); assertEquals(3, waves.size());
IWaveform wave = waves.get(0); IWaveform stream = waves.get(0);
assertTrue(wave instanceof ITxStream<?>); NavigableMap<Long, IEvent[]> eventsList = stream.getEvents();
ITxStream<?> stream = (ITxStream<?>) wave;
assertEquals(2, stream.getGenerators().size());
NavigableMap<Long, List<ITxEvent>> eventsList = stream.getEvents();
assertEquals(27, eventsList.size()); assertEquals(27, eventsList.size());
Entry<Long, List<ITxEvent>> eventEntry = eventsList.firstEntry(); Entry<Long, IEvent[]> eventEntry = eventsList.firstEntry();
assertEquals(100000000L, (long) eventEntry.getKey()); assertEquals(100000000L, (long) eventEntry.getKey());
List<ITxEvent> events = eventEntry.getValue(); IEvent[] events = eventEntry.getValue();
assertEquals(1, events.size()); assertEquals(1, events.length);
ITxEvent event = events.get(0); IEvent event = events[0];
assertEquals(Type.BEGIN, event.getType()); assertEquals(EventKind.BEGIN, event.getKind());
ITx tx = event.getTransaction(); assertTrue(event instanceof ITxEvent);
ITx tx = ((ITxEvent)event).getTransaction();
assertEquals(3L, (long) tx.getId()); assertEquals(3L, (long) tx.getId());
List<ITxAttribute> attrs = tx.getAttributes(); List<ITxAttribute> attrs = tx.getAttributes();
assertEquals(1, attrs.size()); assertEquals(1, attrs.size());