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

nl.topicus.jdbc.shaded.com.google.cloud.spanner.InstanceConfigId Maven / Gradle / Ivy

There is a newer version: 1.1.6
Show newest version
/*
 * Copyright 2017 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in nl.topicus.jdbc.shaded.com.liance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.nl.topicus.jdbc.shaded.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 nl.topicus.jdbc.shaded.com.google.cloud.spanner;

import nl.topicus.jdbc.shaded.com.google.api.pathtemplate.PathTemplate;
import nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.base.Preconditions;
import nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.collect.ImmutableMap;
import java.util.Map;
import java.util.Objects;

/** Returns id of a Cloud Spanner instance config. */
public final class InstanceConfigId {
  private static final PathTemplate NAME_TEMPLATE =
      PathTemplate.create("projects/{project}/instanceConfigs/{instanceconfig}");

  private final String project;
  private final String instanceConfig;

  InstanceConfigId(String project, String instanceConfig) {
    this.project = project;
    this.instanceConfig = instanceConfig;
  }

  /** Returns project of this instane config. */
  public String getProject() {
    return project;
  }

  /** Returns id of this instance config. */
  public String getInstanceConfig() {
    return instanceConfig;
  }

  /** Returns the name of the instance config. */
  public String getName() {
    return String.format("projects/%s/instanceConfigs/%s", project, instanceConfig);
  }

  @Override
  public int hashCode() {
    return Objects.hash(project, instanceConfig);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    InstanceConfigId that = (InstanceConfigId) o;
    return that.project.equals(project) && that.instanceConfig.equals(instanceConfig);
  }

  @Override
  public String toString() {
    return getName();
  }

  /**
   * Creates an {@code InstanceConfigId} from the name of the instance config.
   *
   * @param name the instance config name of the form {@code
   *     projects/PROJECT_ID/instanceConfigs/INSTANCE_CONFIG_ID}
   * @throws IllegalArgumentException if {@code instanceName} does not conform to the expected
   * pattern.
   */
  static InstanceConfigId of(String name) {
    Map parts = NAME_TEMPLATE.match(name);
    Preconditions.checkArgument(
        parts != null, "Name should confirm to pattern %s: %s", NAME_TEMPLATE, name);
    return new InstanceConfigId(parts.get("project"), parts.get("instanceconfig"));
  }

  /**
   * Creates an {@code InstanceConfigId} given project and instance config IDs.
   */
  public static InstanceConfigId of(String project, String instanceConfig) {
    return new InstanceConfigId(project, instanceConfig);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy