Merge "BUG-868: do not use InstanceIdentifier.getPath()"
[controller.git] / opendaylight / md-sal / sal-common-util / src / main / java / org / opendaylight / controller / sal / common / util / Arguments.java
1 /*
2  * Copyright (c) 2013 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.controller.sal.common.util;
9
10 public final class Arguments {
11
12     private Arguments() {
13         throw new UnsupportedOperationException("Utility class");
14     }
15
16     /**
17      * Checks if value is instance of provided class
18      *
19      *
20      * @param value Value to check
21      * @param type Type to check
22      * @return Reference which was checked
23      */
24     @SuppressWarnings("unchecked")
25     public static <T> T checkInstanceOf(Object value, Class<T> type) {
26         if(!type.isInstance(value))
27             throw new IllegalArgumentException(String.format("Value %s is not of type %s", value, type));
28         return (T) value;
29     }
30 }