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 com.google.common.base.Function;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Iterables;
13 import java.util.Collection;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
16 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializer;
18 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 * Abstract(base) serializer for ListNodes (MapNode, UnkeyedListNode), serializes elements of type E.
24 * type of serialized elements
26 * containing node type
28 * entry node type which is inside containing (N) type
30 public abstract class ListNodeBaseSerializer<E, N extends DataContainerChild<NodeIdentifier, Collection<O>>, O extends DataContainerNode<?>>
31 implements FromNormalizedNodeSerializer<E, N, ListSchemaNode> {
34 public final Iterable<E> serialize(final ListSchemaNode schema, final N node) {
35 return Iterables.concat(Iterables.transform(node.getValue(), new Function<O, Iterable<E>>() {
37 public Iterable<E> apply(final O input) {
38 final Iterable<E> serializedChild = getListEntryNodeSerializer().serialize(schema, input);
39 final int size = Iterables.size(serializedChild);
41 Preconditions.checkState(size == 1,
42 "Unexpected count of entries for list serialized from: %s, should be 1, was: %s", input, size);
43 return serializedChild;
50 * @return serializer for inner ListEntryNodes (MapEntryNode, UnkeyedListEntryNode) used to serialize every entry of
51 * ListNode, might be the same instance in case its immutable
53 protected abstract FromNormalizedNodeSerializer<E, O, ListSchemaNode> getListEntryNodeSerializer();