SCViewer/plugins/com.minres.scviewer.databas.../src/com/minres/scviewer/database/text/Tx.java

232 lines
4.5 KiB
Java
Raw Normal View History

/*******************************************************************************
* Copyright (c) 2012 IT Just working.
* Copyright (c) 2020 MINRES Technologies GmbH
* 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:
* IT Just working - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database.text;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.database.tx.ITxAttribute;
import com.minres.scviewer.database.tx.ITxRelation;
/**
* The Class Tx.
*/
class Tx implements ITx {
/** The loader. */
private final TextDbLoader loader;
2021-01-14 23:36:29 +01:00
private ScvTx scvTx =null;
/** The id. */
2021-01-14 23:13:11 +01:00
private final long id;
2021-01-14 23:36:29 +01:00
private final long generatorId;
private final long streamId;
/** The begin time. */
long beginTime = -1;
/** The end time. */
long endTime = -1;
/**
* Instantiates a new tx.
*
* @param loader the loader
* @param scvTx the scv tx
*/
public Tx(TextDbLoader loader, ScvTx scvTx) {
this.loader = loader;
id = scvTx.id;
2021-01-14 23:36:29 +01:00
generatorId=scvTx.generatorId;
streamId=scvTx.streamId;
2021-01-14 23:13:11 +01:00
beginTime=scvTx.beginTime;
endTime=scvTx.endTime;
2021-01-08 15:04:30 +01:00
}
/**
* Instantiates a new tx.
*
* @param loader the loader
* @param txId the tx id
*/
2021-01-14 23:36:29 +01:00
public Tx(TextDbLoader loader, long id, long generatorId, long streamId) {
this.loader = loader;
2021-01-14 23:36:29 +01:00
this.id = id;
this.generatorId=generatorId;
this.streamId = streamId;
}
/**
* Gets the incoming relations.
*
* @return the incoming relations
*/
@Override
public Collection<ITxRelation> getIncomingRelations() {
2021-01-08 15:04:30 +01:00
Set<ScvRelation> rels = loader.relationsIn.get(id);
return rels.stream().map(rel -> new TxRelation(loader, rel)).collect(Collectors.toList());
}
/**
* Gets the outgoing relations.
*
* @return the outgoing relations
*/
@Override
public Collection<ITxRelation> getOutgoingRelations() {
2021-01-08 15:04:30 +01:00
Set<ScvRelation> rels = loader.relationsOut.get(id);
return rels.stream().map(rel -> new TxRelation(loader, rel)).collect(Collectors.toList());
}
/**
* Compare to.
*
* @param o the o
* @return the int
*/
@Override
public int compareTo(ITx o) {
2021-02-27 14:59:00 +01:00
int res = Long.compare(getBeginTime(), o.getBeginTime());
if (res != 0)
return res;
else
2021-02-27 14:59:00 +01:00
return Long.compare(getId(), o.getId());
}
/**
* Equals.
*
* @param obj the obj
* @return true, if successful
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
2021-01-14 23:13:11 +01:00
return this.getScvTx().equals(((Tx) obj).getScvTx());
}
/**
* Hash code.
*
* @return the int
*/
@Override
public int hashCode() {
2021-01-14 23:13:11 +01:00
return getScvTx().hashCode();
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return "tx#" + getId() + "[" + getBeginTime() / 1000000 + "ns - " + getEndTime() / 1000000 + "ns]";
}
/**
* Gets the id.
*
* @return the id
*/
@Override
2021-02-27 14:59:00 +01:00
public long getId() {
2021-01-14 23:13:11 +01:00
return getScvTx().id;
}
/**
* Gets the stream.
*
* @return the stream
*/
@Override
public IWaveform getStream() {
2021-01-14 23:36:29 +01:00
return loader.txStreams.get(streamId);
}
/**
* Gets the generator.
*
* @return the generator
*/
@Override
2021-01-14 23:55:47 +01:00
public IWaveform getGenerator() {
2021-01-14 23:36:29 +01:00
return loader.txGenerators.get(generatorId);
}
/**
* Gets the begin time.
*
* @return the begin time
*/
@Override
2021-02-27 14:59:00 +01:00
public long getBeginTime() {
2021-01-14 23:36:29 +01:00
if (beginTime < 0) {
ScvTx tx = scvTx==null?loader.getScvTx(id):getScvTx();
beginTime = tx.beginTime;
endTime = tx.endTime;
}
2021-01-08 15:04:30 +01:00
return beginTime;
}
/**
* Gets the end time.
*
* @return the end time
*/
@Override
2021-02-27 14:59:00 +01:00
public long getEndTime() {
2021-01-14 23:36:29 +01:00
if (endTime < 0) {
ScvTx tx = scvTx==null?loader.getScvTx(id):getScvTx();
beginTime = tx.beginTime;
endTime = tx.endTime;
}
2021-01-08 15:04:30 +01:00
return endTime;
}
/**
* Sets the end time.
*
* @param time the new end time
*/
void setEndTime(Long time) {
2021-01-14 23:13:11 +01:00
getScvTx().endTime = time;
}
/**
* Gets the attributes.
*
* @return the attributes
*/
@Override
public List<ITxAttribute> getAttributes() {
2021-01-14 23:13:11 +01:00
return getScvTx().attributes;
}
2021-01-14 23:13:11 +01:00
private ScvTx getScvTx() {
2021-01-14 23:36:29 +01:00
if(scvTx==null)
scvTx=loader.getScvTx(id);
2021-01-14 23:13:11 +01:00
return scvTx;
}
}