2 * Copyright (c) 2013 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.yang.data.impl.schema.transform.base.serializer;
10 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
11 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
12 import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializer;
13 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
15 import com.google.common.base.Function;
16 import com.google.common.base.Preconditions;
17 import com.google.common.collect.Iterables;
20 * Abstract(base) serializer for MapNodes, serializes elements of type E.
22 * @param <E> type of serialized elements
24 public abstract class MapNodeBaseSerializer<E> implements FromNormalizedNodeSerializer<E, MapNode, ListSchemaNode> {
27 public final Iterable<E> serialize(final ListSchemaNode schema, final MapNode node) {
28 return Iterables.concat(Iterables.transform(node.getValue(), new Function<MapEntryNode, Iterable<E>>() {
30 public Iterable<E> apply(MapEntryNode input) {
31 final Iterable<E> serializedChild = getMapEntryNodeDomSerializer().serialize(schema, input);
32 final int size = Iterables.size(serializedChild);
34 Preconditions.checkState(size == 1,
35 "Unexpected count of entries for list serialized from: %s, should be 1, was: %s",
37 return serializedChild;
44 * @return serializer for inner MapEntryNodes used to serialize every entry of MapNode, might be the same instance in case its immutable
46 protected abstract FromNormalizedNodeSerializer<E, MapEntryNode, ListSchemaNode> getMapEntryNodeDomSerializer();