2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.util;
10 import org.opendaylight.yangtools.concepts.Identifiable;
12 import com.google.common.base.Function;
14 public final class Identifiables {
15 private static final Function<Identifiable<Object>, Object> EXTRACT_IDENTIFIER = new Function<Identifiable<Object>, Object>() {
17 public Object apply(final Identifiable<Object> input) {
18 return input.getIdentifier();
22 private Identifiables() {
23 throw new UnsupportedOperationException("Utility class");
27 * Return the {@link Function} to extract the identifier from a particular
28 * object implementing the {@link Identifiable} contract.
30 * @return Identificator associated with the object
33 * Suppressing warnings here allows us to fool the compiler enough
34 * such that we can reuse a single function for all applicable types
35 * and present it in a type-safe manner to our users.
37 @SuppressWarnings({ "unchecked", "rawtypes" })
38 public static <V> Function<Identifiable<V>, V> identifierExtractor() {
39 return (Function) EXTRACT_IDENTIFIER;