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 com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableSet;
12 import java.math.BigDecimal;
13 import java.math.BigInteger;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.concepts.Mutable;
18 public final class Immutables {
20 private Immutables() {
21 throw new UnsupportedOperationException("Helper class");
24 public static final Set<Class<?>> KNOWN_IMMUTABLES = ImmutableSet.of(
25 Integer.class, Short.class, BigDecimal.class, BigInteger.class, Byte.class, Character.class, Double.class,
26 Float.class, String.class, Boolean.class, Void.class);
29 * Determines if object is known to be immutable
31 * <p>Note: This method may return false to immutable objects which
32 * immutability is not known, was defined not using concepts term.
36 * @return true if object is known to be immutable false otherwise.
38 public static boolean isImmutable(final Object o) {
39 Preconditions.checkArgument(o != null,"Object should not be null");
40 if (o instanceof Mutable) {
42 } else if (o instanceof Immutable) {
44 } else if (o instanceof String) {
46 } else if (KNOWN_IMMUTABLES.contains(o.getClass())) {