2 * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.yang.model.util.type;
10 import com.google.common.collect.ImmutableMap;
11 import com.google.common.collect.ImmutableMap.Builder;
12 import java.util.HashMap;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
19 public final class BitsTypeBuilder extends TypeBuilder<BitsTypeDefinition> {
20 private final Builder<String, Bit> builder = ImmutableMap.builder();
22 BitsTypeBuilder(final SchemaPath path) {
26 public BitsTypeBuilder addBit(@Nonnull final Bit item) {
27 builder.put(item.getName(), item);
32 public BitsTypeDefinition build() {
33 final Map<String, Bit> map = builder.build();
34 final Map<Long, Bit> positionMap = new HashMap<>();
36 for (Bit b : map.values()) {
37 final Bit conflict = positionMap.put(b.getPosition(), b);
38 if (conflict != null) {
39 throw new InvalidBitDefinitionException(b, "Bit %s conflicts on position with bit ", conflict);
43 return new BaseBitsType(getPath(), getUnknownSchemaNodes(), positionMap.values());