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

org.eclipse.ditto.wot.model.MutableStringSchemaBuilder Maven / Gradle / Ivy

Go to download

Eclipse Ditto is a framework for creating and managing digital twins in the IoT.

There is a newer version: 3.6.0
Show newest version
/*
 * Copyright (c) 2022 Contributors to the Eclipse Foundation
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.ditto.wot.model;

import java.util.regex.Pattern;

import javax.annotation.Nullable;

import org.eclipse.ditto.json.JsonObjectBuilder;

/**
 * Mutable builder for {@link StringSchema}s.
 */
final class MutableStringSchemaBuilder
        extends AbstractSingleDataSchemaBuilder
        implements StringSchema.Builder {

    MutableStringSchemaBuilder(final JsonObjectBuilder wrappedObjectBuilder) {
        super(wrappedObjectBuilder, MutableStringSchemaBuilder.class);
    }

    @Override
    DataSchemaType getDataSchemaType() {
        return DataSchemaType.STRING;
    }

    @Override
    public StringSchema.Builder setMinLength(@Nullable final Integer minLength) {
        putValue(StringSchema.JsonFields.MIN_LENGTH, minLength);
        return myself;
    }

    @Override
    public StringSchema.Builder setMaxLength(@Nullable final Integer maxLength) {
        putValue(StringSchema.JsonFields.MAX_LENGTH, maxLength);
        return myself;
    }

    @Override
    public StringSchema.Builder setPattern(@Nullable final Pattern pattern) {
        if (pattern != null) {
            putValue(StringSchema.JsonFields.PATTERN, pattern.toString());
        } else {
            remove(StringSchema.JsonFields.PATTERN);
        }
        return myself;
    }

    @Override
    public StringSchema.Builder setContentEncoding(@Nullable final String contentEncoding) {
        putValue(StringSchema.JsonFields.CONTENT_ENCODING, contentEncoding);
        return myself;
    }

    @Override
    public StringSchema.Builder setMediaType(@Nullable final String mediaType) {
        putValue(StringSchema.JsonFields.CONTENT_MEDIA_TYPE, mediaType);
        return myself;
    }

    @Override
    public StringSchema build() {
        return new ImmutableStringSchema(wrappedObjectBuilder.build());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy