Organize Imports to be Checkstyle compliant in utils
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / Identifiables.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.util;
9
10 import com.google.common.base.Function;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.concepts.Identifiable;
14
15 public final class Identifiables {
16     private static final Function<Identifiable<Object>, Object> EXTRACT_IDENTIFIER = new Function<Identifiable<Object>, Object>() {
17         @Override
18         public Object apply(@Nonnull final Identifiable<Object> input) {
19             Preconditions.checkNotNull(input);
20             return input.getIdentifier();
21         }
22     };
23
24     private Identifiables() {
25         throw new UnsupportedOperationException("Utility class");
26     }
27
28     /**
29      * Return the {@link Function} to extract the identifier from a particular
30      * object implementing the {@link Identifiable} contract.
31      *
32      * @return Identificator associated with the object
33      */
34     /*
35      * Suppressing warnings here allows us to fool the compiler enough
36      * such that we can reuse a single function for all applicable types
37      * and present it in a type-safe manner to our users.
38      */
39     @SuppressWarnings({ "unchecked", "rawtypes" })
40     public static <V> Function<Identifiable<V>, V> identifierExtractor() {
41         return (Function) EXTRACT_IDENTIFIER;
42     }
43 }
44