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.metrics.internal.cloudwatch;
    INSTANCE
    ;
    
Used to indicate the two objects being compared are both non-nulls.
    private static final int NON_NULLS = 2;
    @Override
    public int compare(Dimension dim1Dimension dim2) {
        int result = nullCompare(dim1dim2);
        if (result == ) {
            result = nullSafeCompare(dim1.getName(), dim2.getName());
            if (result == 0) {
                return nullSafeCompare(dim1.getValue(), dim2.getValue());
            }
        }
        return result;
    }

    
Compares the two given strings for order, handling null as necessary.

Returns:
a negative integer, zero, or a positive integer as the first object is less than, equal to, or greater than the second object.
    private int nullSafeCompare(String firstString second) {
        int result = nullCompare(firstsecond);
        return result ==  ? first.compareTo(second) : result;
    }

    
Partially compares the two given objects for order, handling null as necessary.

Returns:
a -1 if the first object is null but not the second, 0 if both objects are identical, 1 if the second object is null but not the first. Otherwise, NON_NULLS is returned which means both objects are non-null but not identical.
    private int nullCompare(Object firstObject second) {
        if (first == second) {
            return 0;
        }
        if (first == null) {
            return -1;
        }
        if (second == null) {
            return 1;
        }
        return ;
    }
New to GrepCode? Check out our FAQ X