fix sonarlint issues, add IDerivedWaveform interface
This commit is contained in:
parent
b2e269b67c
commit
6c5032da10
|
@ -13,7 +13,6 @@ package com.minres.scviewer.database.sqlite;
|
||||||
import java.beans.IntrospectionException;
|
import java.beans.IntrospectionException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -24,6 +23,7 @@ import java.util.List;
|
||||||
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;
|
||||||
|
import com.minres.scviewer.database.InputFormatException;
|
||||||
import com.minres.scviewer.database.RelationType;
|
import com.minres.scviewer.database.RelationType;
|
||||||
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabase;
|
import com.minres.scviewer.database.sqlite.db.SQLiteDatabase;
|
||||||
|
@ -42,16 +42,13 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
||||||
|
|
||||||
private ScvSimProps scvSimProps;
|
private ScvSimProps scvSimProps;
|
||||||
|
|
||||||
public SQLiteDbLoader() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getMaxTime() {
|
public Long getMaxTime() {
|
||||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<>(ScvTxEvent.class,
|
||||||
database, "time = (SELECT MAX(time) FROM ScvTxEvent)");
|
database, "time = (SELECT MAX(time) FROM ScvTxEvent)");
|
||||||
try {
|
try {
|
||||||
List<ScvTxEvent> event = handler.selectObjects();
|
List<ScvTxEvent> event = handler.selectObjects();
|
||||||
if(event.size()>0)
|
if(!event.isEmpty())
|
||||||
return event.get(0).getTime()*scvSimProps.getTime_resolution();
|
return event.get(0).getTime()*scvSimProps.getTime_resolution();
|
||||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||||
|
@ -62,8 +59,8 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<IWaveform> getAllWaves() {
|
public Collection<IWaveform> getAllWaves() {
|
||||||
SQLiteDatabaseSelectHandler<ScvStream> handler = new SQLiteDatabaseSelectHandler<ScvStream>(ScvStream.class, database);
|
SQLiteDatabaseSelectHandler<ScvStream> handler = new SQLiteDatabaseSelectHandler<>(ScvStream.class, database);
|
||||||
List<IWaveform> streams=new ArrayList<IWaveform>();
|
List<IWaveform> streams=new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for(ScvStream scvStream:handler.selectObjects()){
|
for(ScvStream scvStream:handler.selectObjects()){
|
||||||
TxStream stream = new TxStream(database, db, scvStream);
|
TxStream stream = new TxStream(database, db, scvStream);
|
||||||
|
@ -72,7 +69,6 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
||||||
}
|
}
|
||||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||||
// e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return streams;
|
return streams;
|
||||||
}
|
}
|
||||||
|
@ -80,25 +76,21 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
|
||||||
private byte[] x = "SQLite format 3".getBytes();
|
private byte[] x = "SQLite format 3".getBytes();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean load(IWaveformDb db, File file) throws Exception {
|
public boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||||
if(file.isDirectory() || !file.exists()) return false;
|
if(file.isDirectory() || !file.exists()) return false;
|
||||||
this.db=db;
|
this.db=db;
|
||||||
try {
|
try(FileInputStream fis = new FileInputStream(file)) {
|
||||||
FileInputStream fis = new FileInputStream(file);
|
|
||||||
byte[] buffer = new byte[x.length];
|
byte[] buffer = new byte[x.length];
|
||||||
int read = fis.read(buffer, 0, x.length);
|
int read = fis.read(buffer, 0, x.length);
|
||||||
fis.close();
|
|
||||||
if (read == x.length)
|
if (read == x.length)
|
||||||
for (int i = 0; i < x.length; i++)
|
for (int i = 0; i < x.length; i++)
|
||||||
if (buffer[i] != x[i]) return false;
|
if (buffer[i] != x[i]) return false;
|
||||||
} catch(FileNotFoundException e) {
|
} catch(IOException e) {
|
||||||
return false;
|
|
||||||
} catch(IOException e) { //if an I/O error occurs
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
database=new SQLiteDatabase(file.getAbsolutePath());
|
database=new SQLiteDatabase(file.getAbsolutePath());
|
||||||
database.setData("TIMERESOLUTION", 1L);
|
database.setData("TIMERESOLUTION", 1L);
|
||||||
SQLiteDatabaseSelectHandler<ScvSimProps> handler = new SQLiteDatabaseSelectHandler<ScvSimProps>(ScvSimProps.class, database);
|
SQLiteDatabaseSelectHandler<ScvSimProps> handler = new SQLiteDatabaseSelectHandler<>(ScvSimProps.class, database);
|
||||||
try {
|
try {
|
||||||
for(ScvSimProps simProps:handler.selectObjects()){
|
for(ScvSimProps simProps:handler.selectObjects()){
|
||||||
scvSimProps=simProps;
|
scvSimProps=simProps;
|
||||||
|
|
|
@ -38,8 +38,10 @@ public class Tx implements ITx {
|
||||||
private TxGenerator trGenerator;
|
private TxGenerator trGenerator;
|
||||||
private ScvTx scvTx;
|
private ScvTx scvTx;
|
||||||
private List<ITxAttribute> attributes;
|
private List<ITxAttribute> attributes;
|
||||||
private Long begin, end;
|
private Long begin;
|
||||||
private List<ITxRelation> incoming, outgoing;
|
private Long end;
|
||||||
|
private List<ITxRelation> incoming;
|
||||||
|
private List<ITxRelation> outgoing;
|
||||||
|
|
||||||
public Tx(IDatabase database, TxStream trStream, TxGenerator trGenerator, ScvTx scvTx) {
|
public Tx(IDatabase database, TxStream trStream, TxGenerator trGenerator, ScvTx scvTx) {
|
||||||
this.database=database;
|
this.database=database;
|
||||||
|
@ -71,7 +73,7 @@ public class Tx implements ITx {
|
||||||
@Override
|
@Override
|
||||||
public Long getBeginTime() {
|
public Long getBeginTime() {
|
||||||
if(begin==null){
|
if(begin==null){
|
||||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<>(ScvTxEvent.class,
|
||||||
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal());
|
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.BEGIN.ordinal());
|
||||||
try {
|
try {
|
||||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
||||||
|
@ -87,7 +89,7 @@ public class Tx implements ITx {
|
||||||
@Override
|
@Override
|
||||||
public Long getEndTime() {
|
public Long getEndTime() {
|
||||||
if(end==null){
|
if(end==null){
|
||||||
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<ScvTxEvent>(ScvTxEvent.class,
|
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<>(ScvTxEvent.class,
|
||||||
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal());
|
database, "tx="+scvTx.getId()+" AND type="+ AssociationType.END.ordinal());
|
||||||
try {
|
try {
|
||||||
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
for(ScvTxEvent scvEvent:handler.selectObjects()){
|
||||||
|
@ -103,10 +105,10 @@ public class Tx implements ITx {
|
||||||
@Override
|
@Override
|
||||||
public List<ITxAttribute> getAttributes() {
|
public List<ITxAttribute> getAttributes() {
|
||||||
if(attributes==null){
|
if(attributes==null){
|
||||||
SQLiteDatabaseSelectHandler<ScvTxAttribute> handler = new SQLiteDatabaseSelectHandler<ScvTxAttribute>(
|
SQLiteDatabaseSelectHandler<ScvTxAttribute> handler = new SQLiteDatabaseSelectHandler<>(
|
||||||
ScvTxAttribute.class, database, "tx="+scvTx.getId());
|
ScvTxAttribute.class, database, "tx="+scvTx.getId());
|
||||||
try {
|
try {
|
||||||
attributes = new ArrayList<ITxAttribute>();
|
attributes = new ArrayList<>();
|
||||||
for(ScvTxAttribute scvAttribute:handler.selectObjects()){
|
for(ScvTxAttribute scvAttribute:handler.selectObjects()){
|
||||||
attributes.add(new TxAttribute(this, scvAttribute));
|
attributes.add(new TxAttribute(this, scvAttribute));
|
||||||
|
|
||||||
|
@ -121,10 +123,10 @@ public class Tx implements ITx {
|
||||||
@Override
|
@Override
|
||||||
public Collection<ITxRelation> getIncomingRelations() {
|
public Collection<ITxRelation> getIncomingRelations() {
|
||||||
if(incoming==null){
|
if(incoming==null){
|
||||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<>(
|
||||||
ScvTxRelation.class, database, "sink="+scvTx.getId());
|
ScvTxRelation.class, database, "sink="+scvTx.getId());
|
||||||
try {
|
try {
|
||||||
incoming = new ArrayList<ITxRelation>();
|
incoming = new ArrayList<>();
|
||||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||||
incoming.add(createRelation(scvRelation, false));
|
incoming.add(createRelation(scvRelation, false));
|
||||||
}
|
}
|
||||||
|
@ -138,10 +140,10 @@ public class Tx implements ITx {
|
||||||
@Override
|
@Override
|
||||||
public Collection<ITxRelation> getOutgoingRelations() {
|
public Collection<ITxRelation> getOutgoingRelations() {
|
||||||
if(outgoing==null){
|
if(outgoing==null){
|
||||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<>(
|
||||||
ScvTxRelation.class, database, "src="+scvTx.getId());
|
ScvTxRelation.class, database, "src="+scvTx.getId());
|
||||||
try {
|
try {
|
||||||
outgoing = new ArrayList<ITxRelation>();
|
outgoing = new ArrayList<>();
|
||||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||||
outgoing.add(createRelation(scvRelation, true));
|
outgoing.add(createRelation(scvRelation, true));
|
||||||
}
|
}
|
||||||
|
@ -154,7 +156,7 @@ public class Tx implements ITx {
|
||||||
|
|
||||||
private ITxRelation createRelation(ScvTxRelation rel, boolean outgoing) {
|
private ITxRelation createRelation(ScvTxRelation rel, boolean outgoing) {
|
||||||
int otherId = outgoing?rel.getSink():rel.getSrc();
|
int otherId = outgoing?rel.getSink():rel.getSrc();
|
||||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, database,
|
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<>(ScvTx.class, database,
|
||||||
"id="+otherId);
|
"id="+otherId);
|
||||||
try {
|
try {
|
||||||
List<ScvTx> res = handler.selectObjects();
|
List<ScvTx> res = handler.selectObjects();
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.minres.scviewer.database.sqlite;
|
package com.minres.scviewer.database.sqlite;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
@ -45,7 +46,7 @@ public class TxGenerator implements ITxGenerator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ITx> getTransactions() {
|
public List<ITx> getTransactions() {
|
||||||
return null;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@ import com.minres.scviewer.database.tx.ITxRelation;
|
||||||
public class TxRelation implements ITxRelation {
|
public class TxRelation implements ITxRelation {
|
||||||
|
|
||||||
RelationType relationType;
|
RelationType relationType;
|
||||||
Tx source, target;
|
Tx source;
|
||||||
|
Tx target;
|
||||||
|
|
||||||
public TxRelation(RelationType relationType, Tx source, Tx target) {
|
public TxRelation(RelationType relationType, Tx source, Tx target) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
|
|
@ -80,9 +80,9 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
|
|
||||||
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.class, database, "stream="+scvStream.getId());
|
ScvGenerator.class, database, "stream="+scvStream.getId());
|
||||||
generators=new TreeMap<Integer, TxGenerator>();
|
generators=new TreeMap<>();
|
||||||
try {
|
try {
|
||||||
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
||||||
generators.put(scvGenerator.getId(), new TxGenerator(this, scvGenerator));
|
generators.put(scvGenerator.getId(), new TxGenerator(this, scvGenerator));
|
||||||
|
@ -92,22 +92,20 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ArrayList<ITxGenerator>(generators.values());
|
return new ArrayList<>(generators.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
if(maxConcurrency==null){
|
if(maxConcurrency==null){
|
||||||
java.sql.Connection connection=null;
|
|
||||||
java.sql.Statement statement=null;
|
|
||||||
java.sql.ResultSet resultSet=null;
|
|
||||||
try {
|
|
||||||
connection = database.createConnection();
|
|
||||||
statement = connection.createStatement();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("SELECT MAX(concurrencyLevel) as concurrencyLevel FROM ScvTx where stream=");
|
sb.append("SELECT MAX(concurrencyLevel) as concurrencyLevel FROM ScvTx where stream=");
|
||||||
sb.append(scvStream.getId());
|
sb.append(scvStream.getId());
|
||||||
resultSet = statement.executeQuery(sb.toString());
|
try(
|
||||||
|
java.sql.Connection connection = database.createConnection();
|
||||||
|
java.sql.Statement statement = connection.createStatement();
|
||||||
|
java.sql.ResultSet resultSet = statement.executeQuery(sb.toString());
|
||||||
|
) {
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
if(maxConcurrency==null) maxConcurrency=0;
|
if(maxConcurrency==null) maxConcurrency=0;
|
||||||
Object value = resultSet.getObject("concurrencyLevel");
|
Object value = resultSet.getObject("concurrencyLevel");
|
||||||
|
@ -116,12 +114,6 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if(maxConcurrency==null) maxConcurrency=0;
|
if(maxConcurrency==null) maxConcurrency=0;
|
||||||
} finally {
|
|
||||||
try{
|
|
||||||
if(resultSet!=null) resultSet.close();
|
|
||||||
if(statement!=null) statement.close();
|
|
||||||
if(connection!=null) connection.close();
|
|
||||||
} catch (SQLException e) { }
|
|
||||||
}
|
}
|
||||||
maxConcurrency+=1;
|
maxConcurrency+=1;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +123,7 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
@Override
|
@Override
|
||||||
public NavigableMap<Long, IEvent[]> getEvents(){
|
public NavigableMap<Long, IEvent[]> getEvents(){
|
||||||
if(events==null){
|
if(events==null){
|
||||||
events=new TreeMap<Long, IEvent[]>();
|
events=new TreeMap<>();
|
||||||
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
|
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
|
||||||
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
|
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
|
||||||
putEvent(new TxEvent(EventKind.END, entry.getValue()));
|
putEvent(new TxEvent(EventKind.END, entry.getValue()));
|
||||||
|
@ -156,8 +148,8 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
protected Map<Integer, ITx> getTransactions() {
|
protected Map<Integer, ITx> getTransactions() {
|
||||||
if(transactions==null){
|
if(transactions==null){
|
||||||
if(generators==null) getGenerators();
|
if(generators==null) getGenerators();
|
||||||
transactions = new TreeMap<Integer, ITx>();
|
transactions = new TreeMap<>();
|
||||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, database,
|
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<>(ScvTx.class, database,
|
||||||
"stream="+scvStream.getId());
|
"stream="+scvStream.getId());
|
||||||
try {
|
try {
|
||||||
for(ScvTx scvTx:handler.selectObjects()){
|
for(ScvTx scvTx:handler.selectObjects()){
|
||||||
|
@ -187,7 +179,7 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean equals(IWaveform other) {
|
public boolean isSame(IWaveform other) {
|
||||||
return(other instanceof TxStream && this.getId().equals(other.getId()));
|
return(other instanceof TxStream && this.getId().equals(other.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +187,7 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
public IEvent[] getEventsBeforeTime(Long time) {
|
public IEvent[] getEventsBeforeTime(Long time) {
|
||||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||||
if(e==null)
|
if(e==null)
|
||||||
return null;
|
return new IEvent[]{};
|
||||||
else
|
else
|
||||||
return events.floorEntry(time).getValue();
|
return events.floorEntry(time).getValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.minres.scviewer.database.DataType
|
||||||
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
|
||||||
|
import com.minres.scviewer.database.InputFormatException
|
||||||
import com.minres.scviewer.database.RelationType
|
import com.minres.scviewer.database.RelationType
|
||||||
import com.minres.scviewer.database.tx.ITxGenerator
|
import com.minres.scviewer.database.tx.ITxGenerator
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
static final byte[] x = "scv_tr_stream".bytes
|
static final byte[] x = "scv_tr_stream".bytes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean load(IWaveformDb db, File file) throws Exception {
|
boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||||
if(file.isDirectory() || !file.exists()) return false;
|
if(file.isDirectory() || !file.exists()) return false;
|
||||||
this.db=db
|
this.db=db
|
||||||
this.streams=[]
|
this.streams=[]
|
||||||
|
|
|
@ -33,11 +33,6 @@ class TxEvent implements ITxEvent {
|
||||||
return new TxEvent(kind, transaction, time);
|
return new TxEvent(kind, transaction, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// int compareTo(IWaveformEvent o) {
|
|
||||||
// time.compareTo(o.time)
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
String toString() {
|
String toString() {
|
||||||
|
|
|
@ -114,7 +114,7 @@ class TxStream extends HierNode implements IWaveform {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean equals(IWaveform other) {
|
public boolean isSame(IWaveform other) {
|
||||||
return(other instanceof TxStream && this.getId()==other.getId());
|
return(other instanceof TxStream && this.getId()==other.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1184,7 +1184,7 @@ public class WaveformView implements IWaveformView {
|
||||||
|
|
||||||
public TrackEntry getEntryForStream(IWaveform source) {
|
public TrackEntry getEntryForStream(IWaveform source) {
|
||||||
for(TrackEntry trackEntry:streams)
|
for(TrackEntry trackEntry:streams)
|
||||||
if(trackEntry.waveform.equals(source)) return trackEntry;
|
if(trackEntry.waveform.isSame(source)) return trackEntry;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,11 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
import java.util.Stack;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
@ -39,13 +39,13 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
||||||
|
|
||||||
|
|
||||||
/** The Constant TIME_RES. */
|
/** The Constant TIME_RES. */
|
||||||
private static final Long TIME_RES = 1000L; // ps;
|
private static final Long TIME_RES = 1000L; // ps
|
||||||
|
|
||||||
/** The db. */
|
/** The db. */
|
||||||
private IWaveformDb db;
|
private IWaveformDb db;
|
||||||
|
|
||||||
/** The module stack. */
|
/** The module stack. */
|
||||||
private Stack<String> moduleStack;
|
private ArrayDeque<String> moduleStack;
|
||||||
|
|
||||||
/** The signals. */
|
/** The signals. */
|
||||||
private List<IWaveform> signals;
|
private List<IWaveform> signals;
|
||||||
|
@ -53,23 +53,14 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
||||||
/** The max time. */
|
/** The max time. */
|
||||||
private long maxTime;
|
private long maxTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new VCD db.
|
|
||||||
*/
|
|
||||||
public VCDDbLoader() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isGzipped(File f) {
|
private static boolean isGzipped(File f) {
|
||||||
InputStream is = null;
|
try (InputStream is = new FileInputStream(f)) {
|
||||||
try {
|
|
||||||
is = new FileInputStream(f);
|
|
||||||
byte [] signature = new byte[2];
|
byte [] signature = new byte[2];
|
||||||
int nread = is.read( signature ); //read the gzip signature
|
int nread = is.read( signature ); //read the gzip signature
|
||||||
return nread == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b;
|
return nread == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b;
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e) {
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
|
||||||
try { is.close();} catch (IOException e) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,21 +70,27 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public boolean load(IWaveformDb db, File file) throws Exception {
|
public boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||||
if(file.isDirectory() || !file.exists()) return false;
|
if(file.isDirectory() || !file.exists()) return false;
|
||||||
this.db=db;
|
this.db=db;
|
||||||
this.maxTime=0;
|
this.maxTime=0;
|
||||||
|
boolean res = false;
|
||||||
|
try {
|
||||||
String name = file.getCanonicalFile().getName();
|
String name = file.getCanonicalFile().getName();
|
||||||
if(!(name.endsWith(".vcd") ||
|
if(!(name.endsWith(".vcd") ||
|
||||||
name.endsWith(".vcdz") ||
|
name.endsWith(".vcdz") ||
|
||||||
name.endsWith(".vcdgz") ||
|
name.endsWith(".vcdgz") ||
|
||||||
name.endsWith(".vcd.gz")) )
|
name.endsWith(".vcd.gz")) )
|
||||||
return false;
|
return false;
|
||||||
signals = new Vector<IWaveform>();
|
signals = new Vector<>();
|
||||||
moduleStack= new Stack<String>();
|
moduleStack= new ArrayDeque<>();
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
boolean res = new VCDFileParser(false).load(isGzipped(file)?new GZIPInputStream(fis):fis, this);
|
res = new VCDFileParser(false).load(isGzipped(file)?new GZIPInputStream(fis):fis, this);
|
||||||
moduleStack=null;
|
moduleStack=null;
|
||||||
|
} catch(IOException e) {
|
||||||
|
moduleStack=null;
|
||||||
|
throw new InputFormatException();
|
||||||
|
}
|
||||||
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) {
|
||||||
|
@ -159,9 +156,8 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Integer newNet(String name, int i, int width) {
|
public Integer newNet(String name, int i, int width) {
|
||||||
String netName = moduleStack.empty()? name: moduleStack.lastElement()+"."+name;
|
String netName = moduleStack.isEmpty()? name: moduleStack.peek()+"."+name;
|
||||||
int id = signals.size();
|
int id = signals.size();
|
||||||
assert(width>=0);
|
|
||||||
if(width==0) {
|
if(width==0) {
|
||||||
signals.add( i<0 ? new VCDSignal<DoubleVal>(db, id, netName, width) :
|
signals.add( i<0 ? new VCDSignal<DoubleVal>(db, id, netName, width) :
|
||||||
new VCDSignal<DoubleVal>((VCDSignal<DoubleVal>)signals.get(i), id, netName));
|
new VCDSignal<DoubleVal>((VCDSignal<DoubleVal>)signals.get(i), id, netName));
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package com.minres.scviewer.database.vcd;
|
package com.minres.scviewer.database.vcd;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import com.minres.scviewer.database.BitValue;
|
import com.minres.scviewer.database.BitValue;
|
||||||
|
@ -19,7 +20,7 @@ import com.minres.scviewer.database.BitVector;
|
||||||
class VCDFileParser {
|
class VCDFileParser {
|
||||||
private StreamTokenizer tokenizer;
|
private StreamTokenizer tokenizer;
|
||||||
private IVCDDatabaseBuilder traceBuilder;
|
private IVCDDatabaseBuilder traceBuilder;
|
||||||
private HashMap<String, Integer> nameToNetMap = new HashMap<String, Integer>();
|
private HashMap<String, Integer> nameToNetMap = new HashMap<>();
|
||||||
private long picoSecondsPerIncrement;
|
private long picoSecondsPerIncrement;
|
||||||
private boolean stripNetWidth;
|
private boolean stripNetWidth;
|
||||||
private boolean replaceColon;
|
private boolean replaceColon;
|
||||||
|
@ -50,19 +51,19 @@ class VCDFileParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseScope() throws Exception {
|
private void parseScope() throws IOException, ParseException {
|
||||||
nextToken(); // Scope type (ignore)
|
nextToken(); // Scope type (ignore)
|
||||||
nextToken();
|
nextToken();
|
||||||
traceBuilder.enterModule(tokenizer.sval);
|
traceBuilder.enterModule(tokenizer.sval);
|
||||||
match("$end");
|
match("$end");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseUpscope() throws Exception {
|
private void parseUpscope() throws IOException, ParseException {
|
||||||
match("$end");
|
match("$end");
|
||||||
traceBuilder.exitModule();
|
traceBuilder.exitModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseVar() throws Exception {
|
private void parseVar() throws IOException {
|
||||||
nextToken(); // type
|
nextToken(); // type
|
||||||
String type = tokenizer.sval;
|
String type = tokenizer.sval;
|
||||||
nextToken(); // size
|
nextToken(); // size
|
||||||
|
@ -72,11 +73,12 @@ class VCDFileParser {
|
||||||
nextToken();
|
nextToken();
|
||||||
String id = tokenizer.sval;
|
String id = tokenizer.sval;
|
||||||
nextToken();
|
nextToken();
|
||||||
String netName = tokenizer.sval;
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(tokenizer.sval);
|
||||||
while (nextToken() && !tokenizer.sval.equals("$end")) {
|
while (nextToken() && !tokenizer.sval.equals("$end")) {
|
||||||
netName+=tokenizer.sval;
|
sb.append(tokenizer.sval);
|
||||||
}
|
}
|
||||||
|
String netName = sb.toString();
|
||||||
Integer net = nameToNetMap.get(id);
|
Integer net = nameToNetMap.get(id);
|
||||||
if (net == null) { // We've never seen this net before
|
if (net == null) { // We've never seen this net before
|
||||||
int openBracket = netName.indexOf('[');
|
int openBracket = netName.indexOf('[');
|
||||||
|
@ -86,9 +88,9 @@ class VCDFileParser {
|
||||||
}
|
}
|
||||||
if(replaceColon) {
|
if(replaceColon) {
|
||||||
if (openBracket != -1) {
|
if (openBracket != -1) {
|
||||||
netName = netName.substring(0, openBracket).replaceAll(":", ".")+netName.substring(openBracket);
|
netName = netName.substring(0, openBracket).replace(":", ".")+netName.substring(openBracket);
|
||||||
} else
|
} else
|
||||||
netName=netName.replaceAll(":", ".");
|
netName=netName.replace(":", ".");
|
||||||
}
|
}
|
||||||
nameToNetMap.put(id, traceBuilder.newNet(netName, -1, width));
|
nameToNetMap.put(id, traceBuilder.newNet(netName, -1, width));
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,25 +99,28 @@ class VCDFileParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseComment() throws Exception {
|
private void parseComment() throws IOException {
|
||||||
nextToken();
|
nextToken();
|
||||||
String s = tokenizer.sval;
|
StringBuilder s = new StringBuilder();
|
||||||
|
s.append(tokenizer.sval);
|
||||||
nextToken();
|
nextToken();
|
||||||
while(!tokenizer.sval.equals("$end")){
|
while(!tokenizer.sval.equals("$end")){
|
||||||
s+=" "+tokenizer.sval;
|
s.append(" ").append(tokenizer.sval);
|
||||||
nextToken();
|
nextToken();
|
||||||
}
|
}
|
||||||
replaceColon|=s.contains("ARTERIS Architecture");
|
replaceColon|=s.toString().contains("ARTERIS Architecture");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseTimescale() throws Exception {
|
private void parseTimescale() throws IOException {
|
||||||
nextToken();
|
nextToken();
|
||||||
String s = tokenizer.sval;
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(tokenizer.sval);
|
||||||
nextToken();
|
nextToken();
|
||||||
while(!tokenizer.sval.equals("$end")){
|
while(!tokenizer.sval.equals("$end")){
|
||||||
s+=" "+tokenizer.sval;
|
sb.append(" ").append(tokenizer.sval);
|
||||||
nextToken();
|
nextToken();
|
||||||
}
|
}
|
||||||
|
String s = sb.toString();
|
||||||
switch (s.charAt(s.length() - 2)){
|
switch (s.charAt(s.length() - 2)){
|
||||||
case 'p': // Nano-seconds
|
case 'p': // Nano-seconds
|
||||||
picoSecondsPerIncrement = 1;
|
picoSecondsPerIncrement = 1;
|
||||||
|
@ -141,7 +146,7 @@ class VCDFileParser {
|
||||||
picoSecondsPerIncrement *= Long.parseLong(s);
|
picoSecondsPerIncrement *= Long.parseLong(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean parseDefinition() throws Exception {
|
private boolean parseDefinition() throws IOException, ParseException {
|
||||||
nextToken();
|
nextToken();
|
||||||
if (tokenizer.sval.equals("$scope"))
|
if (tokenizer.sval.equals("$scope"))
|
||||||
parseScope();
|
parseScope();
|
||||||
|
@ -166,7 +171,7 @@ class VCDFileParser {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean parseTransition() throws Exception {
|
private boolean parseTransition() throws IOException {
|
||||||
if (!nextToken()) return false;
|
if (!nextToken()) return false;
|
||||||
if (tokenizer.sval.charAt(0) == '#') { // If the line begins with a #, this is a timestamp.
|
if (tokenizer.sval.charAt(0) == '#') { // If the line begins with a #, this is a timestamp.
|
||||||
currentTime = Long.parseLong(tokenizer.sval.substring(1)) * picoSecondsPerIncrement;
|
currentTime = Long.parseLong(tokenizer.sval.substring(1)) * picoSecondsPerIncrement;
|
||||||
|
@ -179,16 +184,10 @@ class VCDFileParser {
|
||||||
}
|
}
|
||||||
if (tokenizer.sval.equals("$dumpvars") || tokenizer.sval.equals("$end"))
|
if (tokenizer.sval.equals("$dumpvars") || tokenizer.sval.equals("$end"))
|
||||||
return true;
|
return true;
|
||||||
String value, id;
|
String value;
|
||||||
if (tokenizer.sval.charAt(0) == 'b') {
|
String id;
|
||||||
// Multiple value net. Value appears first, followed by space,
|
if (tokenizer.sval.charAt(0) == 'b' || tokenizer.sval.charAt(0) == 'r') {
|
||||||
// then identifier
|
// Multiple value net. Value appears first, followed by space, then identifier
|
||||||
value = tokenizer.sval.substring(1);
|
|
||||||
nextToken();
|
|
||||||
id = tokenizer.sval;
|
|
||||||
}else if (tokenizer.sval.charAt(0) == 'r') {
|
|
||||||
// Multiple value net. Value appears first, followed by space,
|
|
||||||
// then identifier
|
|
||||||
value = tokenizer.sval.substring(1);
|
value = tokenizer.sval.substring(1);
|
||||||
nextToken();
|
nextToken();
|
||||||
id = tokenizer.sval;
|
id = tokenizer.sval;
|
||||||
|
@ -199,10 +198,8 @@ class VCDFileParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer net = nameToNetMap.get(id);
|
Integer net = nameToNetMap.get(id);
|
||||||
if (net == null) {
|
if (net == null)
|
||||||
System.out.println("unknown net " + id + " value " + value);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
int netWidth = traceBuilder.getNetWidth(net);
|
int netWidth = traceBuilder.getNetWidth(net);
|
||||||
if(netWidth==0) {
|
if(netWidth==0) {
|
||||||
|
@ -253,14 +250,14 @@ class VCDFileParser {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void match(String value) throws Exception {
|
private void match(String value) throws ParseException, IOException {
|
||||||
nextToken();
|
nextToken();
|
||||||
if (!tokenizer.sval.equals(value))
|
if (!tokenizer.sval.equals(value))
|
||||||
throw new Exception("Line "+tokenizer.lineno()+": parse error, expected "+value+" got "+tokenizer.sval);
|
throw new ParseException("Line "+tokenizer.lineno()+": parse error, expected "+value+" got "+tokenizer.sval, tokenizer.lineno());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean nextToken() throws IOException {
|
private boolean nextToken() throws IOException {
|
||||||
return tokenizer.nextToken() != StreamTokenizer.TT_EOF;
|
return tokenizer.nextToken() != StreamTokenizer.TT_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
|
@ -46,18 +46,16 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
|
||||||
fullName=name;
|
fullName=name;
|
||||||
this.id=id;
|
this.id=id;
|
||||||
this.width=width;
|
this.width=width;
|
||||||
this.values=new TreeMap<Long, IEvent[]>();
|
this.values=new TreeMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public VCDSignal(VCDSignal<T> other, int id, String name) {
|
public VCDSignal(VCDSignal<T> o, int id, String name) {
|
||||||
super(name);
|
super(name);
|
||||||
fullName=name;
|
fullName=name;
|
||||||
this.id=id;
|
this.id=id;
|
||||||
assert(other instanceof VCDSignal<?>);
|
|
||||||
VCDSignal<T> o = (VCDSignal<T>)other;
|
|
||||||
this.width=o.width;
|
this.width=o.width;
|
||||||
this.values=o.values;
|
this.values=o.values;
|
||||||
this.db=other.getDb();
|
this.db=o.getDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,13 +103,13 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
|
||||||
public IEvent[] getEventsBeforeTime(Long time) {
|
public IEvent[] getEventsBeforeTime(Long time) {
|
||||||
Entry<Long, IEvent[]> e = values.floorEntry(time);
|
Entry<Long, IEvent[]> e = values.floorEntry(time);
|
||||||
if(e==null)
|
if(e==null)
|
||||||
return null;
|
return new IEvent[] {};
|
||||||
else
|
else
|
||||||
return values.floorEntry(time).getValue();
|
return values.floorEntry(time).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean equals(IWaveform other) {
|
public boolean isSame(IWaveform other) {
|
||||||
return( other instanceof VCDSignal<?> && this.getId().equals(other.getId()));
|
return( other instanceof VCDSignal<?> && this.getId().equals(other.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class BitVector implements IEvent {
|
||||||
for(int i=resWidth-1; i>=0; i--){
|
for(int i=resWidth-1; i>=0; i--){
|
||||||
int digit=0;
|
int digit=0;
|
||||||
for(int j=3; j>=0; j--){
|
for(int j=3; j>=0; j--){
|
||||||
if((4*i+j)>=value.length) continue;
|
if((4*i+j)<value.length) {
|
||||||
BitValue val = BitValue.fromChar(value[4*i+j]);
|
BitValue val = BitValue.fromChar(value[4*i+j]);
|
||||||
switch(val) {
|
switch(val) {
|
||||||
case X:
|
case X:
|
||||||
|
@ -90,6 +90,7 @@ public class BitVector implements IEvent {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
res[i]=Character.forDigit(digit, 16); //((digit < 10) ? '0' + digit : 'a' + digit -10)
|
res[i]=Character.forDigit(digit, 16); //((digit < 10) ? '0' + digit : 'a' + digit -10)
|
||||||
}
|
}
|
||||||
return new String(res);
|
return new String(res);
|
||||||
|
|
|
@ -25,4 +25,4 @@ public enum DataType {
|
||||||
POINTER, // T*
|
POINTER, // T*
|
||||||
ARRAY, // T[N]
|
ARRAY, // T[N]
|
||||||
STRING // string, std::string
|
STRING // string, std::string
|
||||||
};
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class HierNode implements IHierNode {
|
||||||
protected PropertyChangeSupport pcs;
|
protected PropertyChangeSupport pcs;
|
||||||
|
|
||||||
public HierNode() {
|
public HierNode() {
|
||||||
childs = new ArrayList<IHierNode>();
|
childs = new ArrayList<>();
|
||||||
pcs=new PropertyChangeSupport(this);
|
pcs=new PropertyChangeSupport(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,4 +85,9 @@ public class HierNode implements IHierNode {
|
||||||
return getFullName().compareTo(o.getFullName());
|
return getFullName().compareTo(o.getFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IDerivedWaveform deriveWaveform() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2015, 2020 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Interface IDerivedWaveform.
|
||||||
|
*/
|
||||||
|
public interface IDerivedWaveform extends IWaveform {
|
||||||
|
|
||||||
|
void addSourceWaveform(IWaveform waveform);
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
* Copyright (c) 2015, 2020 MINRES Technologies GmbH and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -13,6 +13,9 @@ package com.minres.scviewer.database;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Interface IHierNode.
|
||||||
|
*/
|
||||||
public interface IHierNode extends Comparable<IHierNode>{
|
public interface IHierNode extends Comparable<IHierNode>{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,14 +36,46 @@ public interface IHierNode extends Comparable<IHierNode>{
|
||||||
*/
|
*/
|
||||||
public void removePropertyChangeListener(PropertyChangeListener l) ;
|
public void removePropertyChangeListener(PropertyChangeListener l) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the full name.
|
||||||
|
*
|
||||||
|
* @return the full name
|
||||||
|
*/
|
||||||
public String getFullName();
|
public String getFullName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name.
|
||||||
|
*
|
||||||
|
* @param name the new name
|
||||||
|
*/
|
||||||
public void setName(String name);
|
public void setName(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the parent.
|
||||||
|
*
|
||||||
|
* @param parent the new parent
|
||||||
|
*/
|
||||||
public void setParent(IHierNode parent);
|
public void setParent(IHierNode parent);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the child nodes.
|
||||||
|
*
|
||||||
|
* @return the child nodes
|
||||||
|
*/
|
||||||
public List<IHierNode> getChildNodes();
|
public List<IHierNode> getChildNodes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derive waveform.
|
||||||
|
*
|
||||||
|
* @return the i derived waveform or null if none could be created
|
||||||
|
*/
|
||||||
|
public IDerivedWaveform deriveWaveform();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public interface IWaveform extends IHierNode {
|
||||||
|
|
||||||
public IWaveformDb getDb();
|
public IWaveformDb getDb();
|
||||||
|
|
||||||
public Boolean equals(IWaveform other);
|
public boolean isSame(IWaveform other);
|
||||||
|
|
||||||
public NavigableMap<Long, IEvent[]> getEvents();
|
public NavigableMap<Long, IEvent[]> getEvents();
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.Collection;
|
||||||
|
|
||||||
public interface IWaveformDbLoader {
|
public interface IWaveformDbLoader {
|
||||||
|
|
||||||
public boolean load(IWaveformDb db, File inp) throws Exception;
|
public boolean load(IWaveformDb db, File inp) throws InputFormatException;
|
||||||
|
|
||||||
public Long getMaxTime();
|
public Long getMaxTime();
|
||||||
|
|
||||||
|
|
|
@ -50,4 +50,9 @@ public class RelationType {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return name.hashCode();
|
return name.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return name.equals(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ package com.minres.scviewer.database.internal;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -24,12 +23,11 @@ import com.minres.scviewer.database.IHierNode;
|
||||||
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;
|
||||||
import com.minres.scviewer.database.InputFormatException;
|
|
||||||
import com.minres.scviewer.database.RelationType;
|
import com.minres.scviewer.database.RelationType;
|
||||||
|
|
||||||
public class WaveformDb extends HierNode implements IWaveformDb {
|
public class WaveformDb extends HierNode implements IWaveformDb {
|
||||||
|
|
||||||
private static List<IWaveformDbLoader> loaders=new LinkedList<IWaveformDbLoader>();
|
private static List<IWaveformDbLoader> loaders=new LinkedList<>();
|
||||||
|
|
||||||
private boolean loaded;
|
private boolean loaded;
|
||||||
|
|
||||||
|
@ -55,7 +53,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||||
|
|
||||||
public WaveformDb() {
|
public WaveformDb() {
|
||||||
super();
|
super();
|
||||||
waveforms = new HashMap<String, IWaveform>();
|
waveforms = new HashMap<>();
|
||||||
relationTypes=new ArrayList<>();
|
relationTypes=new ArrayList<>();
|
||||||
maxTime=0L;
|
maxTime=0L;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +70,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IWaveform> getAllWaves() {
|
public List<IWaveform> getAllWaves() {
|
||||||
return new ArrayList<IWaveform>(waveforms.values());
|
return new ArrayList<>(waveforms.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,9 +119,8 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildHierarchyNodes() throws InputFormatException{
|
private void buildHierarchyNodes() {
|
||||||
for(IWaveform stream:getAllWaves()){
|
for(IWaveform stream:getAllWaves()){
|
||||||
//updateMaxTime(stream);
|
|
||||||
String[] hier = stream.getName().split("\\.");
|
String[] hier = stream.getName().split("\\.");
|
||||||
IHierNode node = this;
|
IHierNode node = this;
|
||||||
for(int i=0; i<hier.length-1; ++i){
|
for(int i=0; i<hier.length-1; ++i){
|
||||||
|
@ -152,14 +149,9 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortRecursive(IHierNode node) {
|
private void sortRecursive(IHierNode node) {
|
||||||
Collections.sort(node.getChildNodes(), new Comparator<IHierNode>() {
|
Collections.sort(node.getChildNodes(), (IHierNode o1, IHierNode o2) -> o1.getName().compareTo(o2.getName()));
|
||||||
@Override
|
|
||||||
public int compare(IHierNode o1, IHierNode o2) {
|
|
||||||
return o1.getName().compareTo(o2.getName()); }
|
|
||||||
|
|
||||||
});
|
|
||||||
for(IHierNode n:node.getChildNodes()) {
|
for(IHierNode n:node.getChildNodes()) {
|
||||||
if(n.getChildNodes().size()>0)
|
if(!n.getChildNodes().isEmpty())
|
||||||
sortRecursive(n);
|
sortRecursive(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.minres.scviewer.database.IDerivedWaveform;
|
||||||
import com.minres.scviewer.database.IHierNode;
|
import com.minres.scviewer.database.IHierNode;
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
import com.minres.scviewer.database.IWaveformDb;
|
import com.minres.scviewer.database.IWaveformDb;
|
||||||
|
@ -85,4 +86,9 @@ public class LoadingWaveformDb implements IWaveformDb {
|
||||||
public void clear() {
|
public void clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IDerivedWaveform deriveWaveform() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue