Don't throw NPE if we fail to find ChildOf interface
[mdsal.git] / yang / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / HashCodeBuilder.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.yangtools.yang.binding;
9
10 import org.opendaylight.yangtools.concepts.Builder;
11
12 final class HashCodeBuilder<T> implements Builder<Integer> {
13     private int currentHash;
14
15     public HashCodeBuilder() {
16         this(1);
17     }
18
19     public HashCodeBuilder(final int seedHash) {
20         this.currentHash = seedHash;
21     }
22
23     public static int nextHashCode(final int hashCode, final Object arg) {
24         return 31 * hashCode + arg.hashCode();
25     }
26
27     void addArgument(final T arg) {
28         currentHash = nextHashCode(currentHash, arg);
29     }
30
31     @Override
32     public Integer toInstance() {
33         return currentHash;
34     }
35 }