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.binding.data.codec.impl;
10 import java.lang.reflect.InvocationTargetException;
11 import java.lang.reflect.Method;
12 import org.opendaylight.yangtools.concepts.Codec;
14 final class UnionValueOptionContext {
17 final Class<?> bindingType;
18 final Codec<Object,Object> codec;
20 UnionValueOptionContext(final Class<?> valueType,final Method getter, final Codec<Object, Object> codec) {
22 this.bindingType = valueType;
26 public Object serialize(final Object input) {
27 Object baValue = getValueFrom(input);
29 return codec.serialize(baValue);
34 public Object getValueFrom(final Object input) {
36 return getter.invoke(input);
37 } catch (IllegalAccessException | InvocationTargetException e) {
38 throw new IllegalStateException(e);
43 public int hashCode() {
44 return bindingType.hashCode();
48 public boolean equals(final Object obj) {
55 if (getClass() != obj.getClass()) {
58 UnionValueOptionContext other = (UnionValueOptionContext) obj;
59 return bindingType.equals(other.bindingType);