All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.ipk_gatersleben.bit.bi.isa4j.components.Sample Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2020 Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany.
 * All rights reserved. This program and the accompanying materials are made available under the terms of the MIT License (https://spdx.org/licenses/MIT.html)
 *
 * Contributors:
 *      Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany
 */
package de.ipk_gatersleben.bit.bi.isa4j.components;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import de.ipk_gatersleben.bit.bi.isa4j.constants.StudyAssayAttribute;
import de.ipk_gatersleben.bit.bi.isa4j.exceptions.RedundantItemException;

public class Sample extends Source implements Commentable {
	
	private CommentCollection comments = new CommentCollection();
	
	private List factorValues = new ArrayList();
	
	public Sample(String name) {
		super(name);
	}
	
	public Sample(String name, List characteristics) {
		super(name, characteristics);
	}

	public void addFactorValue(FactorValue factorValue) {
		if(this.factorValues.stream().map(FactorValue::getCategory).anyMatch(factorValue.getCategory()::equals))
			throw new RedundantItemException("Multiple FactorValues for Factor: " + factorValue.getCategory().getName());
		this.factorValues.add(factorValue);
	}
	
	public CommentCollection comments() {
		return this.comments;
	}

	/**
	 * @return the factorValues
	 */
	public List getFactorValues() {
		return factorValues;
	}
	
	Map getFields() {
		HashMap fields = new HashMap();
		
		fields.put(StudyAssayAttribute.SAMPLE_NAME.toString(), new String[]{this.getName()});
		fields.putAll(this.getFieldsForCharacteristics());
		fields.putAll(this.getFieldsForComments(this.comments));
		fields.putAll(this.getFieldsForValues(StudyAssayAttribute.FACTOR_VALUE, this.factorValues, fv -> fv.getCategory().getName()));

		return fields;
	}
	
	LinkedHashMap getHeaders() {
		LinkedHashMap headers = new LinkedHashMap();
		
		headers.put(StudyAssayAttribute.SAMPLE_NAME.toString(), new String[]{StudyAssayAttribute.SAMPLE_NAME.toString()});
		headers.putAll(this.getHeadersForCharacteristics());
		headers.putAll(this.getHeadersForComments(this.comments));
		headers.putAll(this.getHeadersForValues(StudyAssayAttribute.FACTOR_VALUE, this.factorValues, fv -> fv.getCategory().getName()));
		
		return headers;
	}
	
	/**
	 * @param factorValues the factorValues to set
	 */
	public void setFactorValues(List factorValues) {
		factorValues.stream().forEach(Objects::requireNonNull);
		this.factorValues = factorValues;
	}
	
	@Override
	public String toString() {
		return " '" + this.name + "'";
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy