fix sonarlint issues, add IDerivedWaveform interface
This commit is contained in:
@ -13,9 +13,9 @@ package com.minres.scviewer.database;
|
||||
public class BitVector implements IEvent {
|
||||
|
||||
private final int width;
|
||||
|
||||
|
||||
private int[] packedValues;
|
||||
|
||||
|
||||
public BitVector(int netWidth) {
|
||||
this.width=netWidth;
|
||||
packedValues = new int[(netWidth+15)/16];
|
||||
@ -31,19 +31,19 @@ public class BitVector implements IEvent {
|
||||
}
|
||||
|
||||
public char[] getValue() {
|
||||
int bitOffset = 0;
|
||||
int wordOffset = 0;
|
||||
char[] res = new char[width];
|
||||
// Copy values out of packed array
|
||||
for (int i = 0; i < width; i++) {
|
||||
int currentWord = (packedValues[wordOffset] >> bitOffset)&3;
|
||||
res[width-i-1]=BitValue.fromInt(currentWord).toChar();
|
||||
bitOffset += 2;
|
||||
if (bitOffset == 32) {
|
||||
wordOffset++;
|
||||
bitOffset = 0;
|
||||
}
|
||||
}
|
||||
int bitOffset = 0;
|
||||
int wordOffset = 0;
|
||||
char[] res = new char[width];
|
||||
// Copy values out of packed array
|
||||
for (int i = 0; i < width; i++) {
|
||||
int currentWord = (packedValues[wordOffset] >> bitOffset)&3;
|
||||
res[width-i-1]=BitValue.fromInt(currentWord).toChar();
|
||||
bitOffset += 2;
|
||||
if (bitOffset == 32) {
|
||||
wordOffset++;
|
||||
bitOffset = 0;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public class BitVector implements IEvent {
|
||||
public String toString(){
|
||||
return new String(getValue());
|
||||
}
|
||||
|
||||
|
||||
public String toHexString(){
|
||||
int resWidth=(width-1)/4+1;
|
||||
char[] value=getValue();
|
||||
@ -76,33 +76,34 @@ public class BitVector implements IEvent {
|
||||
for(int i=resWidth-1; i>=0; i--){
|
||||
int digit=0;
|
||||
for(int j=3; j>=0; j--){
|
||||
if((4*i+j)>=value.length) continue;
|
||||
BitValue val = BitValue.fromChar(value[4*i+j]);
|
||||
switch(val) {
|
||||
case X:
|
||||
case Z:
|
||||
res[i]=val.toChar();
|
||||
continue;
|
||||
case ONE:
|
||||
digit+=1<<(3-j);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if((4*i+j)<value.length) {
|
||||
BitValue val = BitValue.fromChar(value[4*i+j]);
|
||||
switch(val) {
|
||||
case X:
|
||||
case Z:
|
||||
res[i]=val.toChar();
|
||||
continue;
|
||||
case ONE:
|
||||
digit+=1<<(3-j);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
res[i]=Character.forDigit(digit, 16); //((digit < 10) ? '0' + digit : 'a' + digit -10)
|
||||
}
|
||||
return new String(res);
|
||||
}
|
||||
|
||||
|
||||
public long toUnsignedValue() {
|
||||
long res = 0;
|
||||
int bitOffset = 0;
|
||||
int wordOffset = 0;
|
||||
int currentWord = 0;
|
||||
// Copy values out of packed array
|
||||
for (int i = 0; i < width; i++) {
|
||||
if(bitOffset==0) currentWord = packedValues[wordOffset];
|
||||
int bitOffset = 0;
|
||||
int wordOffset = 0;
|
||||
int currentWord = 0;
|
||||
// Copy values out of packed array
|
||||
for (int i = 0; i < width; i++) {
|
||||
if(bitOffset==0) currentWord = packedValues[wordOffset];
|
||||
switch (currentWord & 3) {
|
||||
case 1:
|
||||
res|=1<<i;
|
||||
@ -113,27 +114,27 @@ public class BitVector implements IEvent {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bitOffset += 2;
|
||||
if (bitOffset == 32) {
|
||||
wordOffset++;
|
||||
bitOffset = 0;
|
||||
} else {
|
||||
currentWord >>= 2;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
bitOffset += 2;
|
||||
if (bitOffset == 32) {
|
||||
wordOffset++;
|
||||
bitOffset = 0;
|
||||
} else {
|
||||
currentWord >>= 2;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public long toSignedValue() {
|
||||
long res = 0;
|
||||
int bitOffset = 0;
|
||||
int wordOffset = 0;
|
||||
int currentWord = 0;
|
||||
int lastVal=0;
|
||||
// Copy values out of packed array
|
||||
for (int i = 0; i < width; i++) {
|
||||
if(bitOffset==0) currentWord = packedValues[wordOffset];
|
||||
lastVal=0;
|
||||
int bitOffset = 0;
|
||||
int wordOffset = 0;
|
||||
int currentWord = 0;
|
||||
int lastVal=0;
|
||||
// Copy values out of packed array
|
||||
for (int i = 0; i < width; i++) {
|
||||
if(bitOffset==0) currentWord = packedValues[wordOffset];
|
||||
lastVal=0;
|
||||
switch (currentWord & 3) {
|
||||
case 1:
|
||||
res|=1<<i;
|
||||
@ -144,16 +145,16 @@ public class BitVector implements IEvent {
|
||||
return 0;
|
||||
default:
|
||||
}
|
||||
bitOffset += 2;
|
||||
if (bitOffset == 32) {
|
||||
wordOffset++;
|
||||
bitOffset = 0;
|
||||
} else {
|
||||
currentWord >>= 2;
|
||||
}
|
||||
}
|
||||
if(lastVal!=0)
|
||||
res |= -1l<<width;
|
||||
bitOffset += 2;
|
||||
if (bitOffset == 32) {
|
||||
wordOffset++;
|
||||
bitOffset = 0;
|
||||
} else {
|
||||
currentWord >>= 2;
|
||||
}
|
||||
}
|
||||
if(lastVal!=0)
|
||||
res |= -1l<<width;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -25,4 +25,4 @@ public enum DataType {
|
||||
POINTER, // T*
|
||||
ARRAY, // T[N]
|
||||
STRING // string, std::string
|
||||
};
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class HierNode implements IHierNode {
|
||||
protected PropertyChangeSupport pcs;
|
||||
|
||||
public HierNode() {
|
||||
childs = new ArrayList<IHierNode>();
|
||||
childs = new ArrayList<>();
|
||||
pcs=new PropertyChangeSupport(this);
|
||||
}
|
||||
|
||||
@ -85,4 +85,9 @@ public class HierNode implements IHierNode {
|
||||
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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@ -13,6 +13,9 @@ package com.minres.scviewer.database;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The Interface IHierNode.
|
||||
*/
|
||||
public interface IHierNode extends Comparable<IHierNode>{
|
||||
|
||||
/**
|
||||
@ -33,14 +36,46 @@ public interface IHierNode extends Comparable<IHierNode>{
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) ;
|
||||
|
||||
/**
|
||||
* Gets the full name.
|
||||
*
|
||||
* @return the full name
|
||||
*/
|
||||
public String getFullName();
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
*
|
||||
* @param name the new name
|
||||
*/
|
||||
public void setName(String name);
|
||||
|
||||
/**
|
||||
* Sets the parent.
|
||||
*
|
||||
* @param parent the new parent
|
||||
*/
|
||||
public void setParent(IHierNode parent);
|
||||
|
||||
/**
|
||||
* Gets the child nodes.
|
||||
*
|
||||
* @return the child nodes
|
||||
*/
|
||||
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 Boolean equals(IWaveform other);
|
||||
public boolean isSame(IWaveform other);
|
||||
|
||||
public NavigableMap<Long, IEvent[]> getEvents();
|
||||
|
||||
|
@ -15,7 +15,7 @@ import java.util.Collection;
|
||||
|
||||
public interface IWaveformDbLoader {
|
||||
|
||||
public boolean load(IWaveformDb db, File inp) throws Exception;
|
||||
public boolean load(IWaveformDb db, File inp) throws InputFormatException;
|
||||
|
||||
public Long getMaxTime();
|
||||
|
||||
|
@ -50,4 +50,9 @@ public class RelationType {
|
||||
public int 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.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
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.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
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;
|
||||
|
||||
@ -55,7 +53,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
|
||||
public WaveformDb() {
|
||||
super();
|
||||
waveforms = new HashMap<String, IWaveform>();
|
||||
waveforms = new HashMap<>();
|
||||
relationTypes=new ArrayList<>();
|
||||
maxTime=0L;
|
||||
}
|
||||
@ -72,7 +70,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
|
||||
@Override
|
||||
public List<IWaveform> getAllWaves() {
|
||||
return new ArrayList<IWaveform>(waveforms.values());
|
||||
return new ArrayList<>(waveforms.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,9 +119,8 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
private void buildHierarchyNodes() {
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
//updateMaxTime(stream);
|
||||
String[] hier = stream.getName().split("\\.");
|
||||
IHierNode node = this;
|
||||
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) {
|
||||
Collections.sort(node.getChildNodes(), new Comparator<IHierNode>() {
|
||||
@Override
|
||||
public int compare(IHierNode o1, IHierNode o2) {
|
||||
return o1.getName().compareTo(o2.getName()); }
|
||||
|
||||
});
|
||||
Collections.sort(node.getChildNodes(), (IHierNode o1, IHierNode o2) -> o1.getName().compareTo(o2.getName()));
|
||||
for(IHierNode n:node.getChildNodes()) {
|
||||
if(n.getChildNodes().size()>0)
|
||||
if(!n.getChildNodes().isEmpty())
|
||||
sortRecursive(n);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user