com.orange.ngsi2.model.Attribute.java Source code

Java tutorial

Introduction

Here is the source code for com.orange.ngsi2.model.Attribute.java

Source

/*
 * Copyright (C) 2016 Orange
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.orange.ngsi2.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * Attribute Model
 */
public class Attribute {

    private Object value;

    @JsonInclude(JsonInclude.Include.NON_ABSENT)
    private Optional<String> type;

    @JsonInclude(JsonInclude.Include.ALWAYS)
    private Map<String, Metadata> metadata;

    public Attribute() {
    }

    public Attribute(Object value) {
        this.value = value;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public Optional<String> getType() {
        return type;
    }

    public void setType(Optional<String> type) {
        this.type = type;
    }

    public Map<String, Metadata> getMetadata() {
        if (metadata == null) {
            return Collections.emptyMap();
        }
        return metadata;
    }

    public void setMetadata(Map<String, Metadata> metadata) {
        this.metadata = metadata;
    }

    @JsonIgnore
    public void addMetadata(String key, Metadata metadata) {
        if (this.metadata == null) {
            this.metadata = new HashMap<String, Metadata>();
        }
        this.metadata.put(key, metadata);
    }
}