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

net.nemerosa.ontrack.model.structure.Property Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.model.structure;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Optional;

/**
 * Property value, associated with its type.
 */
@Data
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class Property {

    /**
     * Type for this property
     */
    @JsonIgnore
    private final PropertyType type;

    /**
     * Value for this property
     */
    private final T value;

    /**
     * Editable status
     */
    private final boolean editable;

    /**
     * Descriptor for the property type
     */
    public PropertyTypeDescriptor getTypeDescriptor() {
        return PropertyTypeDescriptor.of(type);
    }

    /**
     * Empty indicator
     */
    public boolean isEmpty() {
        return value == null;
    }

    /**
     * As an option
     */
    public Optional option() {
        return Optional.ofNullable(value);
    }

    /**
     * Editable property
     */
    public Property editable(boolean editable) {
        return new Property<>(type, value, editable);
    }

    public static  Property empty(PropertyType type) {
        return new Property<>(type, null, false);
    }

    public static  Property of(PropertyType type, T value) {
        return new Property<>(type, value, false);
    }

    public boolean containsValue(String propertyValue) {
        return value != null && type.containsValue(value, propertyValue);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy