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

org.javafmi.modeldescription.v2.ScalarVariable Maven / Gradle / Ivy

Go to download

javaFMI is a Java Library for the functional mock-up interface (or FMI). FMI defines a standardized interface to be used in computer simulations. The FMI Standard has beed developed by a large number of software companies and research centers that have worked in a cooperation project under the name of MODELISAR. This library addresses the connection of a java application with a FMU (functional mock-up unit).

There is a newer version: 2.26.5
Show newest version
/*
 *  Copyright 2013-2016 SIANI - ULPGC
 *
 *  This File is part of JavaFMI Project
 *
 *  JavaFMI Project 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.
 *
 *  JavaFMI Project 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 JavaFMI. If not, see .
 */

package org.javafmi.modeldescription.v2;

import org.javafmi.modeldescription.SimpleType;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;

import java.util.List;

public class ScalarVariable implements org.javafmi.modeldescription.ScalarVariable {

    private static final String DEFAULT_CAUSALITY = "local";
    private static final String DEFAULT_VARIABILITY = "continuous";
    @Attribute(required = false)
    private String causality = DEFAULT_CAUSALITY;
    @Attribute(required = false)
    private String variability = DEFAULT_VARIABILITY;
    @Attribute(required = true)
    private String name;
    @Attribute(required = false)
    private long valueReference;
    @Attribute(required = false)
    private String description;
    @Attribute(required = false)
    private String initial;
    @Attribute(required = false)
    private int previous;
    @Attribute(required = false)
    private boolean canHandleMultipleSetPerTimeInstant;

    @Element(name = "Real", required = false)
    private RealType real;
    @Element(name = "Integer", required = false)
    private IntegerType integer;
    @Element(name = "Boolean", required = false)
    private BooleanType booleann;
    @Element(name = "String", required = false)
    private StringType string;
    @Element(name = "Enumeration", required = false)
    private EnumerationType enumeration;
    @ElementList(name = "Annotations", required = false)
    private List annotations;
    private SimpleType type;
    private String typeName;

    public ScalarVariable() {
    }

    public ScalarVariable(String name) {
        this.name = name;
    }

    public void buildAttributes() {
        this.type = buildType();
        this.typeName = buildTypeName();
    }

    public String getName() {
        return name;
    }

    public Integer getValueReference() {
        return (int)valueReference;
    }

    @Override
    public String getTypeName() {
        return typeName;
    }

    @Override
    public boolean isEnumeration() {
        return getType() instanceof EnumerationType;
    }

    public SimpleType getType() {
        return type;
    }

    @Override
    public String getVariability() {
        return variability;
    }

    @Override
    public String getCausality() {
        return causality;
    }

    @Override
    public Object getStart() {
        return getType().getStart();
    }

    @Override
    public boolean hasStartValue() {
        return getStart() != null;
    }

    private SimpleType buildType() {
        if (real != null)
            return real;
        if (integer != null)
            return integer;
        if (booleann != null)
            return booleann;
        if (string != null)
            return string;
        if (enumeration != null)
            return enumeration;
        return null;
    }

    private String buildTypeName() {
        if (real != null)
            return "Real";
        if (integer != null)
            return "Integer";
        if (booleann != null)
            return "Boolean";
        if (string != null)
            return "String";
        if (enumeration != null)
            return "Enumeration";
        return "UndefinedType";
    }

    public void defineAsReal() {
        this.real = new RealType();
        this.typeName = RealType.REAL_TYPE;
    }

    public ScalarVariable withValueReference(Integer valueReference) {
        this.valueReference = valueReference;
        return this;
    }

    public void defineAsInteger() {
        this.type = new IntegerType();
        this.typeName = IntegerType.INTEGER_TYPE;
    }

    public void defineAsBoolean() {
        this.type = new BooleanType();
        this.typeName = BooleanType.BOOLEAN_TYPE;
    }

    public void defineAsString() {
        this.type = new StringType();
        this.typeName = StringType.STRING_TYPE;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public String getInitial() {
        if (initial != null) return initial;
        return initial = new UndefinedInitial().defineFrom(causality, variability);
    }

    public int getPrevious() {
        return previous;
    }

    public boolean canHandleMultipleSetPerTimeInstant() {
        return canHandleMultipleSetPerTimeInstant;
    }

    public List getAnnotations() {
        return annotations;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy