// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java
// public static <T> T checkNotNull(T instance, String message) {
//   if (instance == null) {
//     throw new NullPointerException(message);
//   }
//   return instance;
// }
// 
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java
// public interface LocalizationContext {
// 
//   /**
//    * Localization context factory.
//    */
//   interface Factory {
// 
//     /**
//      * Creates a root localization context for the specified locale.
//      *
//      * @param locale the locale
//      * @return a root localization context for the specified locale
//      */
//     LocalizationContext createRootLocalizationContext(Locale locale);
//   }
// 
//   /**
//    * Returns the locale.
//    *
//    * @return the locale
//    */
//   Locale getLocale();
// 
//   /**
//    * Returns the key prefix of the context, which can be used for property namespacing.
//    *
//    * @return the key prefix of the context
//    */
//   String getKeyPrefix();
// 
//   /**
//    * Returns a localized value for the specified localization key suffix components,
//    * or the specified default value if a localized value cannot be determined.
//    *
//    * @param defaultValue  the default value to return if a localized value cannot be determined
//    * @param keyComponents the localization key suffix components
//    * @return a localized value for the specified localization key suffix components,
//    * or the specified default value if a localized value cannot be determined
//    */
//   String localize(String defaultValue, String... keyComponents);
// }
// 
// Path: src/main/java/com/cloudera/director/spi/v2/model/Resource.java
// public interface Resource<T extends ResourceTemplate> {
// 
//   /**
//    * Represents a type of cloud resource.
//    */
//   interface Type {
// 
//     /**
//      * Returns a localized human-readable description of the resource type.
//      *
//      * @param localizationContext the localization context
//      * @return a loczlized human-readable description of the resource type
//      */
//     String getDescription(LocalizationContext localizationContext);
//   }
// 
//   /**
//    * Returns the type of the resource.
//    *
//    * @return the type of the resource
//    */
//   Type getType();
// 
//   /**
//    * Returns the template from which the resource was created.
//    *
//    * @return the template from which the resource was created
//    */
//   T getTemplate();
// 
//   /**
//    * Returns an external identifier which uniquely identifies the resource within its type and scope.
//    *
//    * @return the identifier
//    */
//   String getId();
// 
//   /**
//    * Returns a localized human-readable description of the resource.
//    *
//    * @param localizationContext the localization context
//    * @return a localized human-readable description of the resource
//    */
//   String getDescription(LocalizationContext localizationContext);
// 
//   /**
//    * Returns a map representing the properties of the resource.
//    *
//    * @return a map representing the properties of the resource
//    */
//   Map<String, String> getProperties();
// 
//   /**
//    * <p>Returns the provider specific underlying implementation of this resource.</p>
//    * <p>Intended for internal provider use only. The consumer of the API will not try
//    * to use this in any way.</p>
//    */
//   Object unwrap();
// 
// }
// 
// Path: src/main/java/com/cloudera/director/spi/v2/model/ResourceTemplate.java
// public interface ResourceTemplate extends Configured {
// 
//   /**
//    * Returns the name of the template.
//    *
//    * @return the name of the template
//    */
//   String getName();
// 
//   /**
//    * Returns the unique ID of the group containing instances created from this template.
//    *
//    * @return the unique ID of the group containing instances created from this template
//    */
//   String getGroupId();
// 
//   /**
//    * Returns the map of tags to be applied to resources created from the template.
//    *
//    * @return the map of tags to be applied to resources created from the template
//    */
//   Map<String, String> getTags();
// 
//   /**
//    * <p>Return the underlying cloud provider specific implementation or null</p>
//    * <p>Intended for internal provider use only. The consumer of the API will not try
//    * to use this in any way.</p>
//    */
//   Object unwrap();
// }


import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull;
import com.cloudera.director.spi.v2.model.LocalizationContext;
import com.cloudera.director.spi.v2.model.Resource;
import com.cloudera.director.spi.v2.model.ResourceTemplate;
// (c) Copyright 2015 Cloudera, Inc.
//
// 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.cloudera.director.spi.v2.model.util;



/**
 * Abstract base class for resource implementations.
 *
 * @param <T> the type of resource template from which resources are constructed
 * @param <D> the type of resource details
 */
public abstract class AbstractResource<T extends ResourceTemplate, D> implements Resource<T> {

  /**
   * The resource type representing a generic resource.
   */
  public static final Type TYPE = new ResourceType("Resource");

  /**
   * Resource type.
   */
  protected static class ResourceType implements Type {

    /**
     * The description of the resource type.
     */
    private final String description;

    public ResourceType(String description) {
      if (description == null) {
        throw new NullPointerException("description is null");
      }
      this.description = description;
    }

    @Override
    // NOTE: This implementation does not do any actual localization, and simply returns the fixed description.
    // Plugin implementers may override to perform localization.
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java
// public static <T> T checkNotNull(T instance, String message) {
//   if (instance == null) {
//     throw new NullPointerException(message);
//   }
//   return instance;
// }
// 
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java
// public interface LocalizationContext {
// 
//   /**
//    * Localization context factory.
//    */
//   interface Factory {
// 
//     /**
//      * Creates a root localization context for the specified locale.
//      *
//      * @param locale the locale
//      * @return a root localization context for the specified locale
//      */
//     LocalizationContext createRootLocalizationContext(Locale locale);
//   }
// 
//   /**
//    * Returns the locale.
//    *
//    * @return the locale
//    */
//   Locale getLocale();
// 
//   /**
//    * Returns the key prefix of the context, which can be used for property namespacing.
//    *
//    * @return the key prefix of the context
//    */
//   String getKeyPrefix();
// 
//   /**
//    * Returns a localized value for the specified localization key suffix components,
//    * or the specified default value if a localized value cannot be determined.
//    *
//    * @param defaultValue  the default value to return if a localized value cannot be determined
//    * @param keyComponents the localization key suffix components
//    * @return a localized value for the specified localization key suffix components,
//    * or the specified default value if a localized value cannot be determined
//    */
//   String localize(String defaultValue, String... keyComponents);
// }
// 
// Path: src/main/java/com/cloudera/director/spi/v2/model/Resource.java
// public interface Resource<T extends ResourceTemplate> {
// 
//   /**
//    * Represents a type of cloud resource.
//    */
//   interface Type {
// 
//     /**
//      * Returns a localized human-readable description of the resource type.
//      *
//      * @param localizationContext the localization context
//      * @return a loczlized human-readable description of the resource type
//      */
//     String getDescription(LocalizationContext localizationContext);
//   }
// 
//   /**
//    * Returns the type of the resource.
//    *
//    * @return the type of the resource
//    */
//   Type getType();
// 
//   /**
//    * Returns the template from which the resource was created.
//    *
//    * @return the template from which the resource was created
//    */
//   T getTemplate();
// 
//   /**
//    * Returns an external identifier which uniquely identifies the resource within its type and scope.
//    *
//    * @return the identifier
//    */
//   String getId();
// 
//   /**
//    * Returns a localized human-readable description of the resource.
//    *
//    * @param localizationContext the localization context
//    * @return a localized human-readable description of the resource
//    */
//   String getDescription(LocalizationContext localizationContext);
// 
//   /**
//    * Returns a map representing the properties of the resource.
//    *
//    * @return a map representing the properties of the resource
//    */
//   Map<String, String> getProperties();
// 
//   /**
//    * <p>Returns the provider specific underlying implementation of this resource.</p>
//    * <p>Intended for internal provider use only. The consumer of the API will not try
//    * to use this in any way.</p>
//    */
//   Object unwrap();
// 
// }
// 
// Path: src/main/java/com/cloudera/director/spi/v2/model/ResourceTemplate.java
// public interface ResourceTemplate extends Configured {
// 
//   /**
//    * Returns the name of the template.
//    *
//    * @return the name of the template
//    */
//   String getName();
// 
//   /**
//    * Returns the unique ID of the group containing instances created from this template.
//    *
//    * @return the unique ID of the group containing instances created from this template
//    */
//   String getGroupId();
// 
//   /**
//    * Returns the map of tags to be applied to resources created from the template.
//    *
//    * @return the map of tags to be applied to resources created from the template
//    */
//   Map<String, String> getTags();
// 
//   /**
//    * <p>Return the underlying cloud provider specific implementation or null</p>
//    * <p>Intended for internal provider use only. The consumer of the API will not try
//    * to use this in any way.</p>
//    */
//   Object unwrap();
// }


// Path: src/main/java/com/cloudera/director/spi/v2/model/util/AbstractResource.java
import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull;
import com.cloudera.director.spi.v2.model.LocalizationContext;
import com.cloudera.director.spi.v2.model.Resource;
import com.cloudera.director.spi.v2.model.ResourceTemplate;

// (c) Copyright 2015 Cloudera, Inc.
//
// 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.cloudera.director.spi.v2.model.util;



/**
 * Abstract base class for resource implementations.
 *
 * @param <T> the type of resource template from which resources are constructed
 * @param <D> the type of resource details
 */
public abstract class AbstractResource<T extends ResourceTemplate, D> implements Resource<T> {

  /**
   * The resource type representing a generic resource.
   */
  public static final Type TYPE = new ResourceType("Resource");

  /**
   * Resource type.
   */
  protected static class ResourceType implements Type {

    /**
     * The description of the resource type.
     */
    private final String description;

    public ResourceType(String description) {
      if (description == null) {
        throw new NullPointerException("description is null");
      }
      this.description = description;
    }

    @Override
    // NOTE: This implementation does not do any actual localization, and simply returns the fixed description.
    // Plugin implementers may override to perform localization.
    public String getDescription(LocalizationContext localizationContext) {