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

t.21.120.2.source-code.DeveloperFieldDefinition Maven / Gradle / Ivy

There is a newer version: 21.141.0
Show newest version
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2023 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING****  This file is auto-generated!  Do NOT edit this file.
// Profile Version = 21.120Release
// Tag = production/release/21.120.00-0-g2d77811
/////////////////////////////////////////////////////////////////////////////////////////////


package com.garmin.fit;

import java.io.OutputStream;

public class DeveloperFieldDefinition extends FieldDefinitionBase {
    private FieldDescriptionMesg fieldDescriptionMesg;
    private DeveloperDataIdMesg developerDataIdMesg;
    private int size;
    private int type;
    private short num;

    public DeveloperFieldDefinition() {
        fieldDescriptionMesg = null;
        type = (int) FitBaseType.UINT8;
    }

    public DeveloperFieldDefinition(FieldDescriptionMesg mesg, DeveloperDataIdMesg developerDataIdMesg) {
        setFieldDescription(mesg);
        this.developerDataIdMesg = developerDataIdMesg;
    }

    public DeveloperFieldDefinition(DeveloperField field) {
        this(field.getFieldDefinition());
        this.size = field.getSize();
    }

    public DeveloperFieldDefinition(final DeveloperFieldDefinition other) {
        setFieldDescription(other.fieldDescriptionMesg);
        this.developerDataIdMesg = other.developerDataIdMesg;
        size = other.getSize();
    }

    public long getAppVersion() {
        Long val = null;

        if (isDefined()) {
            val = developerDataIdMesg.getApplicationVersion();
        }

        if( null == val ) {
            return Fit.UINT32_INVALID;
        }

        return (long)val;
    }

    public Byte[] getAppId() {
        if (isDefined()) {
            return developerDataIdMesg.getApplicationId();
        }

        return null;
    }

    public short getDeveloperDataIndex() {
        Short val = null;
        if (isDefined()) {
            val = fieldDescriptionMesg.getDeveloperDataIndex();
        }

        if( null == val ) {
            return Fit.UINT8_INVALID;
        }

        return (short)val;
    }

    public boolean isDefined() {
        return (fieldDescriptionMesg != null) && (developerDataIdMesg != null);
    }

    public String getFieldName() {
        if (isDefined()) {
            return fieldDescriptionMesg.getFieldName(0);
        }

        return null;
    }

    public short getScale() {
        if (isDefined() &&
             (fieldDescriptionMesg.getScale() != null) &&
             (!fieldDescriptionMesg.getScale().equals(Fit.UINT8_INVALID))) {
            return fieldDescriptionMesg.getScale();
        }

        return (short) Fit.FIELD_DEFAULT_SCALE;
    }

    public short getOffset() {
        if (isDefined() &&
             (fieldDescriptionMesg.getOffset() != null) &&
             (!fieldDescriptionMesg.getOffset().equals(Fit.SINT8_INVALID))) {
            return fieldDescriptionMesg.getOffset();
        }

        return (short) Fit.FIELD_DEFAULT_OFFSET;
    }

    public String getUnits() {
        if (isDefined()) {
            return fieldDescriptionMesg.getUnits(0);
        }

        return null;
    }

    public DeveloperField getDefaultField() {
        return new DeveloperField(this);
    }

    protected void write(OutputStream out) {
        try {
            out.write(fieldDescriptionMesg.getFieldDefinitionNumber());
            out.write(size);
            out.write(fieldDescriptionMesg.getDeveloperDataIndex());
        } catch (java.io.IOException e) {
            throw new FitRuntimeException(e);
        }
    }

    public short getNum() {
        return num;
    }

    public void setNum(short num) {
        this.num = num;
    }

    @Override
    public int getSize() {
        return size;
    }

    @Override
    public void setSize(int size) {
        this.size = size;
    }

    public int getType() {
        return type;
    }

    /**
     * Retrieve the Overridden Native Field Number
     *
     * @return Overridden field number if field overrides a value, {@link Fit#UINT8_INVALID} otherwise.
     */
    public short getNativeOverride() {
        if (isDefined()) {
            Short nativeNum = fieldDescriptionMesg.getNativeFieldNum();
            if (null != nativeNum) {
                return nativeNum;
            }
        }

        return Fit.UINT8_INVALID;
    }

    void setFieldDescription(FieldDescriptionMesg description) {
        this.fieldDescriptionMesg = description;
        this.num = fieldDescriptionMesg.getFieldDefinitionNumber();
        this.type = fieldDescriptionMesg.getFitBaseTypeId();
    }

    void setDeveloperDataIdMesg(DeveloperDataIdMesg developerDataIdMesg) {
        this.developerDataIdMesg = developerDataIdMesg;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy