From 36cd4335ab71df191f438a0a400a4bc32eb3c2ac Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Wed, 16 Oct 2013 11:30:38 +0200 Subject: [PATCH] Preparation for reworking messaging format --- .../fda/core/messages/ComponentMetadata.java | 21 -------- .../ch/psi/fda/core/messages/DataMessage.java | 37 +++++++++---- .../ch/psi/fda/core/messages/Metadata.java | 54 +++++++++++++++++++ 3 files changed, 80 insertions(+), 32 deletions(-) create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/core/messages/Metadata.java diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/ComponentMetadata.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/ComponentMetadata.java index 92af1e9..2c7779f 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/ComponentMetadata.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/ComponentMetadata.java @@ -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+"]"; - } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/DataMessage.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/DataMessage.java index 3efb4b3..15b0f74 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/DataMessage.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/DataMessage.java @@ -29,25 +29,40 @@ public class DataMessage extends Message{ private static final long serialVersionUID = 1L; - /** - * Data payload of the message - */ - private List data; + private final List data; + private final List metadata; - /** - * Create message object with data payload - */ public DataMessage(){ this.data = new ArrayList(); + this.metadata = new ArrayList<>(); + } + + public DataMessage(List metadata){ + this.data = new ArrayList(); + this.metadata = metadata; } - /** - * Get data object of the message - * @return Data object of the message - */ public List getData(){ return(data); } + public List getMetadata(){ + return 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); + } @Override public String toString() { diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/Metadata.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/Metadata.java new file mode 100644 index 0000000..f78ccc9 --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/messages/Metadata.java @@ -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 . + * + */ + +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; + } +}