001package com.teamscale.commons; 002 003import java.util.Objects; 004import java.util.Optional; 005 006import javax.annotation.Nullable; 007 008import org.conqat.lib.commons.version.Version; 009 010import com.fasterxml.jackson.annotation.JsonProperty; 011import com.teamscale.commons.lang.ToStringHelpers; 012 013/** 014 * Transport object providing information about the server's service API. 015 */ 016public final class ServiceApiInfo { 017 018 /** The current version of the service API */ 019 @JsonProperty("maxApiVersion") 020 private final Version maxApiVersion; 021 022 /** The minimum version of the service API still supported by the server */ 023 @JsonProperty("minApiVersion") 024 private final Version minApiVersion; 025 026 /** 027 * Contact information in case of problems (e.g. the server admin's email). 028 */ 029 @JsonProperty("adminContact") 030 @Nullable 031 private final String adminContact; 032 033 public ServiceApiInfo(Version maxApiVersion, Version minApiVersion, String adminContact) { 034 Objects.requireNonNull(maxApiVersion); 035 Objects.requireNonNull(minApiVersion); 036 this.maxApiVersion = maxApiVersion; 037 this.minApiVersion = minApiVersion; 038 this.adminContact = adminContact; 039 } 040 041 /** @see #maxApiVersion */ 042 public Version getMaxApiVersion() { 043 return maxApiVersion; 044 } 045 046 /** @see #minApiVersion */ 047 public Version getMinApiVersion() { 048 return minApiVersion; 049 } 050 051 /** @see #adminContact */ 052 public Optional<String> getAdminContact() { 053 return Optional.ofNullable(adminContact); 054 } 055 056 /** Whether the required API version is supported by the server. */ 057 public boolean isSupported(Version requiredVersion) { 058 return requiredVersion.isSatisfied(maxApiVersion, minApiVersion); 059 } 060 061 @Override 062 public boolean equals(Object o) { 063 if (this == o) { 064 return true; 065 } 066 if (o == null || getClass() != o.getClass()) { 067 return false; 068 } 069 ServiceApiInfo that = (ServiceApiInfo) o; 070 return Objects.equals(maxApiVersion, that.maxApiVersion) && Objects.equals(minApiVersion, that.minApiVersion) 071 && Objects.equals(adminContact, that.adminContact); 072 } 073 074 @Override 075 public int hashCode() { 076 return Objects.hash(maxApiVersion, minApiVersion, adminContact); 077 } 078 079 @Override 080 public String toString() { 081 return ToStringHelpers.toReflectiveStringHelper(this).toString(); 082 } 083}