refactor database class hierarchy
This commit is contained in:
parent
db838efc65
commit
21d83f93dc
|
@ -20,10 +20,9 @@ import java.util.List;
|
|||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
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.SQLiteDatabaseSelectHandler;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvStream;
|
||||
|
@ -55,7 +54,7 @@ public class Tx implements ITx {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ITxStream<ITxEvent> getStream() {
|
||||
public IWaveform getStream() {
|
||||
return trStream;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,16 +10,17 @@
|
|||
*******************************************************************************/
|
||||
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.ITxEvent;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
|
||||
public class TxEvent implements ITxEvent {
|
||||
|
||||
private final Type type;
|
||||
private final EventKind type;
|
||||
private ITx tx;
|
||||
|
||||
public TxEvent(Type type, ITx tx) {
|
||||
public TxEvent(EventKind type, ITx tx) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.tx = tx;
|
||||
|
@ -27,26 +28,21 @@ public class TxEvent implements ITxEvent {
|
|||
|
||||
@Override
|
||||
public Long getTime() {
|
||||
return type==Type.BEGIN?tx.getBeginTime():tx.getEndTime();
|
||||
return type==EventKind.BEGIN?tx.getBeginTime():tx.getEndTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformEvent duplicate() throws CloneNotSupportedException {
|
||||
public IEvent duplicate() throws CloneNotSupportedException {
|
||||
return new TxEvent(type, tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IWaveformEvent o) {
|
||||
return getTime().compareTo(o.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITx getTransaction() {
|
||||
return tx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
public EventKind getKind() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -54,4 +50,9 @@ public class TxEvent implements ITxEvent {
|
|||
public String toString() {
|
||||
return type.toString()+"@"+getTime()+" of tx #"+tx.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getType() {
|
||||
return TxEvent.class;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,18 +13,17 @@ package com.minres.scviewer.database.sqlite;
|
|||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
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;
|
||||
|
||||
public class TxGenerator implements ITxGenerator {
|
||||
|
||||
private ITxStream<ITxEvent> stream;
|
||||
private IWaveform stream;
|
||||
|
||||
private ScvGenerator scvGenerator;
|
||||
|
||||
public TxGenerator(ITxStream<ITxEvent> stream, ScvGenerator scvGenerator) {
|
||||
public TxGenerator(IWaveform stream, ScvGenerator scvGenerator) {
|
||||
this.stream=stream;
|
||||
this.scvGenerator=scvGenerator;
|
||||
}
|
||||
|
@ -35,7 +34,7 @@ public class TxGenerator implements ITxGenerator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ITxStream<ITxEvent> getStream() {
|
||||
public IWaveform getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,19 +14,17 @@ import java.beans.IntrospectionException;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NavigableMap;
|
||||
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.IEvent;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
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.ScvTx;
|
||||
|
||||
public class TxStream extends HierNode implements ITxStream<ITxEvent> {
|
||||
public class TxStream extends HierNode implements IWaveform {
|
||||
|
||||
private IDatabase database;
|
||||
|
||||
|
@ -52,7 +50,7 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
|
|||
|
||||
private Integer maxConcurrency;
|
||||
|
||||
private TreeMap<Long, List<ITxEvent>> events;
|
||||
private TreeMap<Long, IEvent[]> events;
|
||||
|
||||
private List<RelationType> usedRelationsList;
|
||||
|
||||
|
@ -84,7 +82,6 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
|
|||
return scvStream.getKind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITxGenerator> getGenerators() {
|
||||
if(generators==null){
|
||||
SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<ScvGenerator>(
|
||||
|
@ -136,12 +133,12 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NavigableMap<Long, List<ITxEvent>> getEvents(){
|
||||
public NavigableMap<Long, IEvent[]> getEvents(){
|
||||
if(events==null){
|
||||
events=new TreeMap<Long, List<ITxEvent>>();
|
||||
events=new TreeMap<Long, IEvent[]>();
|
||||
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
|
||||
putEvent(new TxEvent(TxEvent.Type.BEGIN, entry.getValue()));
|
||||
putEvent(new TxEvent(TxEvent.Type.END, entry.getValue()));
|
||||
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
|
||||
putEvent(new TxEvent(EventKind.END, entry.getValue()));
|
||||
}
|
||||
}
|
||||
return events;
|
||||
|
@ -149,12 +146,14 @@ public class TxStream extends HierNode implements ITxStream<ITxEvent> {
|
|||
|
||||
private void putEvent(TxEvent ev){
|
||||
Long time = ev.getTime();
|
||||
if(!events.containsKey(time)){
|
||||
Vector<ITxEvent> vector=new Vector<ITxEvent>();
|
||||
vector.add(ev);
|
||||
events.put(time, vector);
|
||||
if(events.containsKey(time)) {
|
||||
IEvent[] oldV = events.get(time);
|
||||
IEvent[] newV = new IEvent[oldV.length+1];
|
||||
System.arraycopy(oldV, 0, newV, 0, oldV.length);
|
||||
newV[oldV.length]=ev;
|
||||
events.put(time, newV);
|
||||
} 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
|
||||
public Collection<ITxEvent> getWaveformEventsAtTime(Long time) {
|
||||
public IEvent[] getEventsAtTime(Long 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()));
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import groovy.io.FileType
|
|||
import com.minres.scviewer.database.AssociationType
|
||||
import com.minres.scviewer.database.DataType
|
||||
import com.minres.scviewer.database.ITxGenerator
|
||||
import com.minres.scviewer.database.ITxStream
|
||||
import com.minres.scviewer.database.IWaveform
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformDbLoader
|
||||
|
@ -163,7 +162,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|||
case "scv_tr_generator":
|
||||
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])
|
||||
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])
|
||||
stream.generators<<generator
|
||||
generatorsById[id]=generator
|
||||
|
|
|
@ -1,36 +1,41 @@
|
|||
package com.minres.scviewer.database.text;
|
||||
|
||||
import com.minres.scviewer.database.EventKind
|
||||
import com.minres.scviewer.database.ITx
|
||||
import com.minres.scviewer.database.ITxEvent
|
||||
import com.minres.scviewer.database.IWaveformEvent
|
||||
|
||||
class TxEvent implements ITxEvent {
|
||||
|
||||
final ITxEvent.Type type;
|
||||
final EventKind kind;
|
||||
|
||||
final Tx transaction;
|
||||
|
||||
final Long time
|
||||
|
||||
TxEvent(ITxEvent.Type type, ITx transaction) {
|
||||
TxEvent(EventKind kind, ITx transaction) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.kind = kind;
|
||||
this.transaction = transaction;
|
||||
this.time = type==ITxEvent.Type.BEGIN?transaction.beginTime:transaction.endTime
|
||||
this.time = kind==EventKind.BEGIN?transaction.beginTime:transaction.endTime
|
||||
}
|
||||
|
||||
@Override
|
||||
IWaveformEvent duplicate() throws CloneNotSupportedException {
|
||||
ITxEvent duplicate() throws CloneNotSupportedException {
|
||||
new TxEvent(type, transaction, time)
|
||||
}
|
||||
|
||||
@Override
|
||||
int compareTo(IWaveformEvent o) {
|
||||
time.compareTo(o.time)
|
||||
}
|
||||
// @Override
|
||||
// int compareTo(IWaveformEvent o) {
|
||||
// time.compareTo(o.time)
|
||||
// }
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
type.toString()+"@"+time+" of tx #"+transaction.id;
|
||||
kind.toString()+"@"+time+" of tx #"+transaction.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
Class<?> getType() {
|
||||
return this.getClass();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,13 @@ import java.util.List;
|
|||
|
||||
import com.minres.scviewer.database.ITxAttributeType
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
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.IWaveformEvent;
|
||||
|
||||
class TxGenerator implements ITxGenerator{
|
||||
Long id
|
||||
TxStream stream
|
||||
IWaveform stream
|
||||
String name
|
||||
Boolean active = false
|
||||
ArrayList<ITx> transactions=[]
|
||||
|
@ -39,7 +37,7 @@ class TxGenerator implements ITxGenerator{
|
|||
this.name=name
|
||||
}
|
||||
|
||||
ITxStream<? extends ITxEvent> getStream(){
|
||||
IWaveform getStream(){
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,20 +16,21 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Map.Entry
|
||||
|
||||
import org.mapdb.Serializer
|
||||
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformEvent
|
||||
import com.minres.scviewer.database.ITxGenerator
|
||||
import com.minres.scviewer.database.EventKind
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IEvent
|
||||
import com.minres.scviewer.database.IHierNode
|
||||
import com.minres.scviewer.database.ITxStream
|
||||
import com.minres.scviewer.database.ITx
|
||||
|
||||
class TxStream extends HierNode implements ITxStream {
|
||||
class TxStream extends HierNode implements IWaveform {
|
||||
|
||||
Long id
|
||||
|
||||
|
@ -43,7 +44,7 @@ class TxStream extends HierNode implements ITxStream {
|
|||
|
||||
int maxConcurrency
|
||||
|
||||
private TreeMap<Long, List<ITxEvent>> events
|
||||
private TreeMap<Long, IEvent[]> events
|
||||
|
||||
TxStream(TextDbLoader loader, int id, String name, String kind){
|
||||
super(name)
|
||||
|
@ -70,14 +71,14 @@ class TxStream extends HierNode implements ITxStream {
|
|||
if(!maxConcurrency){
|
||||
generators.each {TxGenerator generator ->
|
||||
generator.transactions.each{ Tx tx ->
|
||||
putEvent(new TxEvent(ITxEvent.Type.BEGIN, tx))
|
||||
putEvent(new TxEvent(ITxEvent.Type.END, tx))
|
||||
putEvent(new TxEvent(EventKind.BEGIN, tx))
|
||||
putEvent(new TxEvent(EventKind.END, tx))
|
||||
}
|
||||
}
|
||||
def rowendtime = [0]
|
||||
events.keySet().each{long 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 ->
|
||||
Tx tx = event.transaction
|
||||
def rowIdx = 0
|
||||
|
@ -102,12 +103,12 @@ class TxStream extends HierNode implements ITxStream {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NavigableMap getEvents() {
|
||||
public NavigableMap<Long, IEvent[]> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection getWaveformEventsAtTime(Long time) {
|
||||
public IEvent[] getEventsAtTime(Long time) {
|
||||
return events.get(time);
|
||||
}
|
||||
|
||||
|
@ -116,4 +117,18 @@ class TxStream extends HierNode implements ITxStream {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ import java.util.Vector;
|
|||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
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.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
|
@ -96,7 +97,7 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
if(!res) throw new InputFormatException();
|
||||
// calculate max time of database
|
||||
for(IWaveform waveform:signals) {
|
||||
NavigableMap<Long, ?> events =((ISignal<?>)waveform).getEvents();
|
||||
NavigableMap<Long, IEvent[]> events =waveform.getEvents();
|
||||
if(events.size()>0)
|
||||
maxTime= Math.max(maxTime, events.lastKey());
|
||||
}
|
||||
|
@ -108,8 +109,8 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
Object val = events.lastEntry().getValue();
|
||||
if(val instanceof BitVector) {
|
||||
((VCDSignal<BitVector>)s).addSignalChange(maxTime, (BitVector) val);
|
||||
} else if(val instanceof Double)
|
||||
((VCDSignal<Double>)s).addSignalChange(maxTime, (Double) val);
|
||||
} else if(val instanceof DoubleVal)
|
||||
((VCDSignal<DoubleVal>)s).addSignalChange(maxTime, (DoubleVal) val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,8 +163,8 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
int id = signals.size();
|
||||
assert(width>=0);
|
||||
if(width==0) {
|
||||
signals.add( i<0 ? new VCDSignal<Double>(db, id, netName, width) :
|
||||
new VCDSignal<Double>((VCDSignal<Double>)signals.get(i), id, netName));
|
||||
signals.add( i<0 ? new VCDSignal<DoubleVal>(db, id, netName, width) :
|
||||
new VCDSignal<DoubleVal>((VCDSignal<DoubleVal>)signals.get(i), id, netName));
|
||||
} else if(width>0){
|
||||
signals.add( i<0 ? new VCDSignal<BitVector>(db, id, netName, width) :
|
||||
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) {
|
||||
VCDSignal<BitVector> signal = (VCDSignal<BitVector>) signals.get(signalId);
|
||||
Long time = currentTime* TIME_RES;
|
||||
signal.getEvents().put(time, value);
|
||||
signal.addSignalChange(time, value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -197,11 +198,9 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
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;
|
||||
if(signal.getWidth()==0){
|
||||
((VCDSignal<Double>)signal).getEvents().put(time, value);
|
||||
}
|
||||
signal.addSignalChange(time, new DoubleVal(value));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -15,12 +15,11 @@ import java.util.NavigableMap;
|
|||
import java.util.TreeMap;
|
||||
|
||||
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.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;
|
||||
|
||||
|
@ -34,7 +33,7 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
|
|||
|
||||
private IWaveformDb db;
|
||||
|
||||
private TreeMap<Long, T> values;
|
||||
private NavigableMap<Long, IEvent[]> values;
|
||||
|
||||
public VCDSignal(IWaveformDb db, String name) {
|
||||
this(db, 0, name, 1);
|
||||
|
@ -50,17 +49,17 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
|
|||
fullName=name;
|
||||
this.id=id;
|
||||
this.width=width;
|
||||
this.values=new TreeMap<Long, T>();
|
||||
this.values=new TreeMap<Long, IEvent[]>();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public VCDSignal(ISignal<T> other, int id, String name) {
|
||||
public VCDSignal(VCDSignal<T> other, int id, String name) {
|
||||
super(name);
|
||||
fullName=name;
|
||||
this.id=id;
|
||||
assert(other instanceof VCDSignal<?>);
|
||||
this.width=((VCDSignal<? extends IWaveformEvent>)other).width;
|
||||
this.values=((VCDSignal<T>)other).values;
|
||||
VCDSignal<T> o = (VCDSignal<T>)other;
|
||||
this.width=o.width;
|
||||
this.values=o.values;
|
||||
this.db=other.getDb();
|
||||
}
|
||||
|
||||
|
@ -93,22 +92,30 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
|
|||
}
|
||||
|
||||
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
|
||||
public NavigableMap<Long, T> getEvents() {
|
||||
public NavigableMap<Long, IEvent[]> getEvents() {
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getWaveformValueAtTime(Long time) {
|
||||
public IEvent[] getEventsAtTime(Long time) {
|
||||
return values.get(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getWaveformValueBeforeTime(Long time) {
|
||||
Entry<Long, T> e = values.floorEntry(time);
|
||||
public IEvent[] getEventsBeforeTime(Long time) {
|
||||
Entry<Long, IEvent[]> e = values.floorEntry(time);
|
||||
if(e==null)
|
||||
return null;
|
||||
else
|
||||
|
@ -125,6 +132,9 @@ public class VCDSignal<T> extends HierNode implements ISignal<T> {
|
|||
return dummy.getClass();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaxConcurrency() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
public class BitVector {
|
||||
public class BitVector implements IEvent {
|
||||
|
||||
private final int width;
|
||||
|
||||
|
@ -166,5 +166,20 @@ public class BitVector {
|
|||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.minres.scviewer.database;
|
||||
|
||||
public enum EventKind {
|
||||
SINGLE, BEGIN, END
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.minres.scviewer.database;
|
||||
|
||||
public interface IEvent {
|
||||
|
||||
public IEvent duplicate() throws CloneNotSupportedException;
|
||||
|
||||
public EventKind getKind();
|
||||
|
||||
public Class<?> getType();
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ public interface ITx extends Comparable<ITx>{
|
|||
|
||||
public Long getId();
|
||||
|
||||
public ITxStream<ITxEvent> getStream();
|
||||
public IWaveform getStream();
|
||||
|
||||
public ITxGenerator getGenerator();
|
||||
|
||||
|
|
|
@ -10,10 +10,9 @@
|
|||
*******************************************************************************/
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
public interface ITxEvent extends IWaveformEvent {
|
||||
enum Type {BEGIN, END};
|
||||
public interface ITxEvent extends IEvent {
|
||||
|
||||
public Long getTime();
|
||||
|
||||
public ITx getTransaction();
|
||||
|
||||
public Type getType();
|
||||
public ITx getTransaction();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
|
||||
public interface ITxGenerator {
|
||||
public Long getId();
|
||||
public ITxStream<ITxEvent> getStream();
|
||||
public IWaveform getStream();
|
||||
public String getName();
|
||||
public List<ITx> getTransactions();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.util.NavigableMap;
|
||||
|
||||
public interface IWaveform extends IHierNode {
|
||||
|
||||
|
@ -21,4 +22,14 @@ public interface IWaveform extends IHierNode {
|
|||
|
||||
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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -25,12 +25,11 @@ import org.junit.Test;
|
|||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
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.ITxAttribute;
|
||||
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.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
@ -71,13 +70,11 @@ public class DatabaseServicesTest {
|
|||
assertEquals(14, waves.size());
|
||||
assertEquals(2, waveformDb.getChildNodes().size());
|
||||
IWaveform bus_data_wave = waves.get(0);
|
||||
ISignal<?> bus_data_sig = (ISignal<?>) bus_data_wave;
|
||||
Entry<Long, ?> bus_data_entry = bus_data_sig.getEvents().floorEntry(1400000000L);
|
||||
assertTrue("01111000".equals(bus_data_entry.getValue().toString()));
|
||||
Entry<Long, IEvent[]> bus_data_entry = bus_data_wave.getEvents().floorEntry(1400000000L);
|
||||
assertTrue("01111000".equals(bus_data_entry.getValue()[0].toString()));
|
||||
IWaveform rw_wave = waves.get(2);
|
||||
ISignal<?> rw_sig = (ISignal<?>) rw_wave;
|
||||
Entry<Long, ?> rw_entry = rw_sig.getEvents().floorEntry(2360000000L);
|
||||
assertTrue("1".equals(rw_entry.getValue().toString()));
|
||||
Entry<Long, IEvent[]> rw_entry = rw_wave.getEvents().floorEntry(2360000000L);
|
||||
assertTrue("1".equals(rw_entry.getValue()[0].toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -119,19 +116,17 @@ public class DatabaseServicesTest {
|
|||
assertEquals(1, waveformDb.getChildNodes().size());
|
||||
List<IWaveform> waves = waveformDb.getAllWaves();
|
||||
assertEquals(3, waves.size());
|
||||
IWaveform wave = waves.get(0);
|
||||
assertTrue(wave instanceof ITxStream<?>);
|
||||
ITxStream<?> stream = (ITxStream<?>) wave;
|
||||
assertEquals(2, stream.getGenerators().size());
|
||||
NavigableMap<Long, List<ITxEvent>> eventsList = stream.getEvents();
|
||||
IWaveform stream = waves.get(0);
|
||||
NavigableMap<Long, IEvent[]> eventsList = stream.getEvents();
|
||||
assertEquals(27, eventsList.size());
|
||||
Entry<Long, List<ITxEvent>> eventEntry = eventsList.firstEntry();
|
||||
Entry<Long, IEvent[]> eventEntry = eventsList.firstEntry();
|
||||
assertEquals(100000000L, (long) eventEntry.getKey());
|
||||
List<ITxEvent> events = eventEntry.getValue();
|
||||
assertEquals(1, events.size());
|
||||
ITxEvent event = events.get(0);
|
||||
assertEquals(Type.BEGIN, event.getType());
|
||||
ITx tx = event.getTransaction();
|
||||
IEvent[] events = eventEntry.getValue();
|
||||
assertEquals(1, events.length);
|
||||
IEvent event = events[0];
|
||||
assertEquals(EventKind.BEGIN, event.getKind());
|
||||
assertTrue(event instanceof ITxEvent);
|
||||
ITx tx = ((ITxEvent)event).getTransaction();
|
||||
assertEquals(3L, (long) tx.getId());
|
||||
List<ITxAttribute> attrs = tx.getAttributes();
|
||||
assertEquals(1, attrs.size());
|
||||
|
|
Loading…
Reference in New Issue