Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   * 
   *  http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file 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.amazonaws.services.cloudwatch.model;
 

The Metric data type contains information about a specific metric. If you call ListMetrics, Amazon CloudWatch returns information contained by this data type.

 
 public class Metric implements SerializableCloneable {

    
The namespace of the metric.

Constraints:
Length: 1 - 255
Pattern: [^:].*

 
     private String namespace;

    
The name of the metric.

Constraints:
Length: 1 - 255

 
     private String metricName;

    
A list of dimensions associated with the metric.

Constraints:
Length: 0 - 10

 
The namespace of the metric.

Constraints:
Length: 1 - 255
Pattern: [^:].*

Returns:
The namespace of the metric.
 
     public String getNamespace() {
         return ;
     }
    
    
The namespace of the metric.

Constraints:
Length: 1 - 255
Pattern: [^:].*

Parameters:
namespace The namespace of the metric.
 
     public void setNamespace(String namespace) {
         this. = namespace;
     }
    
    
The namespace of the metric.

Returns a reference to this object so that method calls can be chained together.

Constraints:
Length: 1 - 255
Pattern: [^:].*

Parameters:
namespace The namespace of the metric.
Returns:
A reference to this updated object so that method calls can be chained together.
 
     public Metric withNamespace(String namespace) {
         this. = namespace;
         return this;
     }

    
The name of the metric.

Constraints:
Length: 1 - 255

Returns:
The name of the metric.
    public String getMetricName() {
        return ;
    }
    
    
The name of the metric.

Constraints:
Length: 1 - 255

Parameters:
metricName The name of the metric.
    public void setMetricName(String metricName) {
        this. = metricName;
    }
    
    
The name of the metric.

Returns a reference to this object so that method calls can be chained together.

Constraints:
Length: 1 - 255

Parameters:
metricName The name of the metric.
Returns:
A reference to this updated object so that method calls can be chained together.
    public Metric withMetricName(String metricName) {
        this. = metricName;
        return this;
    }

    
A list of dimensions associated with the metric.

Constraints:
Length: 0 - 10

Returns:
A list of dimensions associated with the metric.
    public java.util.List<DimensiongetDimensions() {
        if ( == null) {
               = new com.amazonaws.internal.ListWithAutoConstructFlag<Dimension>();
              .setAutoConstruct(true);
        }
        return ;
    }
    
    
A list of dimensions associated with the metric.

Constraints:
Length: 0 - 10

Parameters:
dimensions A list of dimensions associated with the metric.
    public void setDimensions(java.util.Collection<Dimensiondimensions) {
        if (dimensions == null) {
            this. = null;
            return;
        }
        dimensionsCopy.addAll(dimensions);
        this. = dimensionsCopy;
    }
    
    
A list of dimensions associated with the metric.

NOTE: This method appends the values to the existing list (if any). Use setDimensions(java.util.Collection) or withDimensions(java.util.Collection) if you want to override the existing values.

Returns a reference to this object so that method calls can be chained together.

Constraints:
Length: 0 - 10

Parameters:
dimensions A list of dimensions associated with the metric.
Returns:
A reference to this updated object so that method calls can be chained together.
    public Metric withDimensions(Dimension... dimensions) {
        if (getDimensions() == nullsetDimensions(new java.util.ArrayList<Dimension>(dimensions.length));
        for (Dimension value : dimensions) {
            getDimensions().add(value);
        }
        return this;
    }
    
    
A list of dimensions associated with the metric.

Returns a reference to this object so that method calls can be chained together.

Constraints:
Length: 0 - 10

Parameters:
dimensions A list of dimensions associated with the metric.
Returns:
A reference to this updated object so that method calls can be chained together.
    public Metric withDimensions(java.util.Collection<Dimensiondimensions) {
        if (dimensions == null) {
            this. = null;
        } else {
            dimensionsCopy.addAll(dimensions);
            this. = dimensionsCopy;
        }
        return this;
    }

    
Returns a string representation of this object; useful for testing and debugging.

Returns:
A string representation of this object.
See also:
java.lang.Object.toString()
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        if (getNamespace() != nullsb.append("Namespace: " + getNamespace() + ",");
        if (getMetricName() != nullsb.append("MetricName: " + getMetricName() + ",");
        if (getDimensions() != nullsb.append("Dimensions: " + getDimensions() );
        sb.append("}");
        return sb.toString();
    }
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int hashCode = 1;
        
        hashCode = prime * hashCode + ((getNamespace() == null) ? 0 : getNamespace().hashCode()); 
        hashCode = prime * hashCode + ((getMetricName() == null) ? 0 : getMetricName().hashCode()); 
        hashCode = prime * hashCode + ((getDimensions() == null) ? 0 : getDimensions().hashCode()); 
        return hashCode;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == objreturn true;
        if (obj == nullreturn false;
        if (obj instanceof Metric == falsereturn false;
        Metric other = (Metric)obj;
        
        if (other.getNamespace() == null ^ this.getNamespace() == nullreturn false;
        if (other.getNamespace() != null && other.getNamespace().equals(this.getNamespace()) == falsereturn false
        if (other.getMetricName() == null ^ this.getMetricName() == nullreturn false;
        if (other.getMetricName() != null && other.getMetricName().equals(this.getMetricName()) == falsereturn false
        if (other.getDimensions() == null ^ this.getDimensions() == nullreturn false;
        if (other.getDimensions() != null && other.getDimensions().equals(this.getDimensions()) == falsereturn false
        return true;
    }
    
    @Override
    public Metric clone() {
        try {
            return (Metricsuper.clone();
        
        } catch (CloneNotSupportedException e) {
            throw new IllegalStateException(
                    "Got a CloneNotSupportedException from Object.clone() "
                    + "even though we're Cloneable!",
                    e);
        }
        
    }
}
    
New to GrepCode? Check out our FAQ X