com.netflix.spectator.api.Functions Maven / Gradle / Ivy
/**
* Copyright 2015 Netflix, 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.netflix.spectator.api;
import com.netflix.spectator.impl.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Predicate;
import java.util.function.ToDoubleFunction;
/**
* Common functions for use with gauges.
*/
public final class Functions {
private static final Logger LOGGER = LoggerFactory.getLogger(Functions.class);
private Functions() {
}
/**
* Identity function that just returns the passed in value if it implements the
* {@link java.lang.Number} interface.
*/
public static final DoubleFunction extends Number> IDENTITY = new DoubleFunction() {
@Override public double apply(double v) {
return v;
}
};
/**
* Returns the size of the collection.
*
* @deprecated Use {@code Collection::size} instead.
*/
@Deprecated
public static final ValueFunction> COLLECTION_SIZE = Collection::size;
/**
* Returns the size of the map.
*
* @deprecated Use {@code Map::size} instead.
*/
@Deprecated
public static final ValueFunction