Preparation for reworking messaging format

This commit is contained in:
2013-10-16 11:30:38 +02:00
parent d92534ec37
commit 36cd4335ab
3 changed files with 80 additions and 32 deletions

View File

@@ -31,30 +31,14 @@ public class ComponentMetadata implements Serializable{
private static final long serialVersionUID = 1L;
/**
* Global id of the component
*/
private final String id;
/**
* Dimension of the component (optional)
*/
private final int dimension;
/**
* Default constructor - Create component metadata
* @param id Global id of the component
*/
public ComponentMetadata(String id){
this.id = id;
this.dimension = 0;
}
/**
* Initializes id and the dimension number
* @param id
* @param dimension
*/
public ComponentMetadata(String id, int dimension){
this.id = id;
this.dimension = dimension;
@@ -67,9 +51,4 @@ public class ComponentMetadata implements Serializable{
public String getId() {
return id;
}
@Override
public String toString() {
return "Component Metadata[id="+id+" dimension="+dimension+"]";
}
}

View File

@@ -29,25 +29,40 @@ public class DataMessage extends Message{
private static final long serialVersionUID = 1L;
/**
* Data payload of the message
*/
private List<Object> data;
private final List<Object> data;
private final List<Metadata> metadata;
/**
* Create message object with data payload
*/
public DataMessage(){
this.data = new ArrayList<Object>();
this.metadata = new ArrayList<>();
}
public DataMessage(List<Metadata> metadata){
this.data = new ArrayList<Object>();
this.metadata = metadata;
}
/**
* Get data object of the message
* @return Data object of the message
*/
public List<Object> getData(){
return(data);
}
public List<Metadata> getMetadata(){
return metadata;
}
// Utility functions
@SuppressWarnings("unchecked")
public <T> 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);
}
@Override
public String toString() {

View File

@@ -0,0 +1,54 @@
/**
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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 final 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 int getDimension() {
return dimension;
}
public String getId() {
return id;
}
}