commit 1f2c6849c458a7684779ef738334b3c05a97186e Author: Simon Ebner Date: Tue Dec 17 15:12:45 2013 +0100 Initial commit diff --git a/ch.psi.fda.core/.classpath b/ch.psi.fda.core/.classpath new file mode 100644 index 0000000..9fc2de7 --- /dev/null +++ b/ch.psi.fda.core/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ch.psi.fda.core/.gitignore b/ch.psi.fda.core/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/ch.psi.fda.core/.gitignore @@ -0,0 +1 @@ +/target diff --git a/ch.psi.fda.core/.project b/ch.psi.fda.core/.project new file mode 100644 index 0000000..408d81d --- /dev/null +++ b/ch.psi.fda.core/.project @@ -0,0 +1,23 @@ + + + ch.psi.fda.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/ch.psi.fda.core/.settings/org.eclipse.jdt.core.prefs b/ch.psi.fda.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..abec6ca --- /dev/null +++ b/ch.psi.fda.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/ch.psi.fda.core/.settings/org.eclipse.m2e.core.prefs b/ch.psi.fda.core/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/ch.psi.fda.core/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/ch.psi.fda.core/pom.xml b/ch.psi.fda.core/pom.xml new file mode 100644 index 0000000..2e5a3cf --- /dev/null +++ b/ch.psi.fda.core/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + ch.psi + ch.psi.fda.core + 0.0.1-SNAPSHOT + + + + com.google.guava + guava + 15.0 + + + \ No newline at end of file diff --git a/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/ControlMessage.java b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/ControlMessage.java new file mode 100644 index 0000000..b06f030 --- /dev/null +++ b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/ControlMessage.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2010 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ + +package ch.psi.fda.core.messages; + + +/** + * A control message that is not holding any data but + * control information (like end of loop, etc.) + */ +public abstract class ControlMessage extends Message{ + private static final long serialVersionUID = 1L; +} diff --git a/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/DataMessage.java b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/DataMessage.java new file mode 100644 index 0000000..bfbb128 --- /dev/null +++ b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/DataMessage.java @@ -0,0 +1,105 @@ +/** + * + * Copyright 2010 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ + +package ch.psi.fda.core.messages; + +import java.util.ArrayList; +import java.util.List; + +/** + * Message holding data + */ +public class DataMessage extends Message{ + + private static final long serialVersionUID = 1L; + + private final List data; + private List metadata; + +// public DataMessage(){ +// this.data = new ArrayList(); +// this.metadata = new ArrayList<>(); +// } +// + public DataMessage(List metadata){ + this.data = new ArrayList(); + this.metadata = metadata; + } + + public List getData(){ + return(data); + } + public List getMetadata(){ + return metadata; + } + public void setMetadata(List metadata){ + this.metadata = metadata; + } + + // Utility functions + + @SuppressWarnings("unchecked") + public T getData(String id){ + int i=0; + for(Metadata m: metadata){ + if(m.getId().equals(id)){ + return (T) data.get(i); + } + i++; + } + throw new IllegalArgumentException("No data found for id: "+id); + } + + public Metadata getMetadata(String id){ + for(Metadata m: metadata){ + if(m.getId().equals(id)){ + return m; + } + } + throw new IllegalArgumentException("No data found for id: "+id); + } + + @Override + public String toString() { + StringBuffer b = new StringBuffer(); + b.append("Message [ "); + for (Object o : data) { + if (o.getClass().isArray()) { + // If the array object is of type double[] display its content + if (o instanceof double[]) { + double[] oa = (double[]) o; + b.append("[ "); + for (double o1 : oa) { + b.append(o1); + b.append(" "); + } + b.append("]"); + } else { + b.append(o.toString()); + } + } else { + b.append(o); + } + + b.append(" "); + } + b.append("]"); + return b.toString(); + } +} diff --git a/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/EndOfStreamMessage.java b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/EndOfStreamMessage.java new file mode 100644 index 0000000..c85eec1 --- /dev/null +++ b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/EndOfStreamMessage.java @@ -0,0 +1,52 @@ +/** + * + * Copyright 2010 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ + +package ch.psi.fda.core.messages; + +/** + * Message that is send at the end of the action loop inside an ActionLoop implementation + * of just to indicate that a particular stream has finished + */ +public class EndOfStreamMessage extends ControlMessage { + + private static final long serialVersionUID = 1L; + + /** + * Intersect flag - flag to indicate that stream should be intersected + * after this message. + */ + private final boolean iflag; + + public EndOfStreamMessage(){ + this(false); + } + + public EndOfStreamMessage(boolean iflag){ + this.iflag = iflag; + } + + public boolean isIflag(){ + return(iflag); + } + + @Override + public String toString() { + return "Message[ c message: end of stream ]"; + } +} diff --git a/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/Message.java b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/Message.java new file mode 100644 index 0000000..0d4536a --- /dev/null +++ b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/Message.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2010 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ + +package ch.psi.fda.core.messages; + +import java.io.Serializable; + +/** + * Message that can be put to the data queue + */ +public abstract class Message implements Serializable{ + private static final long serialVersionUID = 1L; +} diff --git a/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/Metadata.java b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/Metadata.java new file mode 100644 index 0000000..4d8cf3c --- /dev/null +++ b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/Metadata.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2010 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ + +package ch.psi.fda.core.messages; + +import java.io.Serializable; + +/** + * Metadata of a component of a message. Each component has a global id. + * Optionally the component can also belong to a dimension. However, depending on the + * view the number of the dimension might vary. Therefore the dimension number + * might change during the lifetime of a message (component). + */ +public class Metadata implements Serializable{ + + private static final long serialVersionUID = 1L; + + private final String id; + private int dimension; + + public Metadata(String id){ + this.id = id; + this.dimension = 0; + } + + public Metadata(String id, int dimension){ + this.id = id; + this.dimension = dimension; + } + + public void setDimension(int dimension){ + this.dimension = dimension; + } + + public int getDimension() { + return dimension; + } + + public String getId() { + return id; + } +} diff --git a/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/StreamDelimiterMessage.java b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/StreamDelimiterMessage.java new file mode 100644 index 0000000..9d35ba8 --- /dev/null +++ b/ch.psi.fda.core/src/main/java/ch/psi/fda/core/messages/StreamDelimiterMessage.java @@ -0,0 +1,67 @@ +/** + * + * Copyright 2010 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ + +package ch.psi.fda.core.messages; + +/** + * Message that is send at the end of the action loop inside an ActionLoop implementation + */ +public class StreamDelimiterMessage extends ControlMessage{ + private static final long serialVersionUID = 1L; + /** + * Number of the dimension this delimiter belongs to. + */ + private final int number; + + /** + * Intersect flag - flag to indicate that stream should be intersected + * after this message. + */ + private final boolean iflag; + + /** + * @param number Number of the dimension this delimiter belongs to + */ + public StreamDelimiterMessage(int number){ + this(number, false); + } + + /** + * @param number + * @param iflag Flag to indicate that data is grouped + */ + public StreamDelimiterMessage(int number, boolean iflag){ + this.number = number; + this.iflag = iflag; + } + + public int getNumber() { + return number; + } + + public boolean isIflag(){ + return iflag; + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return "Message [ c message: delimiter dimension "+number+" ]"; + } +} diff --git a/ch.psi.fda.core/src/main/resources/.gitignore b/ch.psi.fda.core/src/main/resources/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/ch.psi.fda.core/src/test/java/.gitignore b/ch.psi.fda.core/src/test/java/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/ch.psi.fda.core/src/test/resources/.gitignore b/ch.psi.fda.core/src/test/resources/.gitignore new file mode 100644 index 0000000..e69de29