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

com.hedera.hapi.node.base.schema.SemanticVersionSchema Maven / Gradle / Ivy

There is a newer version: 0.54.0
Show newest version
package com.hedera.hapi.node.base.schema;

import com.hedera.pbj.runtime.FieldDefinition;
import com.hedera.pbj.runtime.FieldType;
import com.hedera.pbj.runtime.Schema;


/**
 * Schema for SemanticVersion model object. Generate based on protobuf schema.
 */
public final class SemanticVersionSchema implements Schema {

    // -- FIELD DEFINITIONS ---------------------------------------------

    /**
     * (1) Increases with incompatible API changes
     */
    public static final FieldDefinition MAJOR = new FieldDefinition("major", FieldType.INT32, false, false, false, 1);


    /**
     * (2) Increases with backwards-compatible new functionality
     */
    public static final FieldDefinition MINOR = new FieldDefinition("minor", FieldType.INT32, false, false, false, 2);


    /**
     * (3) Increases with backwards-compatible bug fixes
     */
    public static final FieldDefinition PATCH = new FieldDefinition("patch", FieldType.INT32, false, false, false, 3);


    /**
     * (4) A pre-release version MAY be denoted by appending a hyphen and a series of dot separated
     * identifiers (https://semver.org/#spec-item-9); so given a semver 0.14.0-alpha.1+21AF26D3,
     * this field would contain 'alpha.1'
     */
    public static final FieldDefinition PRE = new FieldDefinition("pre", FieldType.STRING, false, false, false, 4);


    /**
     * (5) Build metadata MAY be denoted by appending a plus sign and a series of dot separated
     * identifiers immediately following the patch or pre-release version
     * (https://semver.org/#spec-item-10); so given a semver 0.14.0-alpha.1+21AF26D3, this field
     * would contain '21AF26D3'
     */
    public static final FieldDefinition BUILD = new FieldDefinition("build", FieldType.STRING, false, false, false, 5);


    // -- OTHER METHODS -------------------------------------------------

    /**
     * Check if a field definition belongs to this schema.
     *
     * @param f field def to check
     * @return true if it belongs to this schema
     */
    public static boolean valid(FieldDefinition f) {
    	return f != null && getField(f.number()) == f;
    }

	/**
	 * Get a field definition given a field number
	 *
	 * @param fieldNumber the fields number to get def for
	 * @return field def or null if field number does not exist
	 */
	public static FieldDefinition getField(final int fieldNumber) {
	    return switch(fieldNumber) {
	        case 1 -> MAJOR;
            case 2 -> MINOR;
            case 3 -> PATCH;
            case 4 -> PRE;
            case 5 -> BUILD;
	        default -> null;
	    };
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy