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

com.teamscale.commons.ServiceApiInfo Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) CQSE GmbH
 *
 * 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.teamscale.commons;

import java.util.Objects;
import java.util.Optional;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.conqat.lib.commons.version.Version;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.teamscale.commons.lang.ToStringHelpers;

/**
 * Transport object providing information about the server's service API.
 */
public final class ServiceApiInfo {

	private static final String MAX_API_VERSION_PROPERTY = "maxApiVersion";

	private static final String MIN_API_VERSION_PROPERTY = "minApiVersion";

	private static final String ADMIN_CONTACT_PROPERTY = "adminContact";

	/** The current version of the service API */
	@JsonProperty(MAX_API_VERSION_PROPERTY)
	private final Version maxApiVersion;

	/** The minimum version of the service API still supported by the server */
	@JsonProperty(MIN_API_VERSION_PROPERTY)
	private final Version minApiVersion;

	/**
	 * Contact information in case of problems (e.g. the server admin's email).
	 */
	@JsonProperty(ADMIN_CONTACT_PROPERTY)
	@Nullable
	private final String adminContact;

	@JsonCreator
	public ServiceApiInfo(@JsonProperty(MAX_API_VERSION_PROPERTY) Version maxApiVersion,
			@JsonProperty(MIN_API_VERSION_PROPERTY) Version minApiVersion,
			@JsonProperty(ADMIN_CONTACT_PROPERTY) String adminContact) {
		Objects.requireNonNull(maxApiVersion);
		Objects.requireNonNull(minApiVersion);
		this.maxApiVersion = maxApiVersion;
		this.minApiVersion = minApiVersion;
		this.adminContact = adminContact;
	}

	/** @see #maxApiVersion */
	public Version getMaxApiVersion() {
		return maxApiVersion;
	}

	/** @see #minApiVersion */
	public Version getMinApiVersion() {
		return minApiVersion;
	}

	/** @see #adminContact */
	public Optional getAdminContact() {
		return Optional.ofNullable(adminContact);
	}

	/** Whether the required API version is supported by the server. */
	public boolean isSupported(Version requiredVersion) {
		return requiredVersion.isSatisfied(maxApiVersion, minApiVersion);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || getClass() != o.getClass()) {
			return false;
		}
		ServiceApiInfo that = (ServiceApiInfo) o;
		return Objects.equals(maxApiVersion, that.maxApiVersion) && Objects.equals(minApiVersion, that.minApiVersion)
				&& Objects.equals(adminContact, that.adminContact);
	}

	@Override
	public int hashCode() {
		return Objects.hash(maxApiVersion, minApiVersion, adminContact);
	}

	@Override
	public String toString() {
		return ToStringHelpers.toReflectiveStringHelper(this).toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy