<commit_before>/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.binding.data.codec.impl;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class ChoiceNodeCodecContext extends DataContainerCodecContext<ChoiceNode> {
    private static final Logger LOG = LoggerFactory.getLogger(ChoiceNodeCodecContext.class);
    private final ImmutableMap<YangInstanceIdentifier.PathArgument, DataContainerCodecPrototype<?>> byYangCaseChild;
    private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byClass;
    private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byCaseChildClass;

    public ChoiceNodeCodecContext(final DataContainerCodecPrototype<ChoiceNode> prototype) {
        super(prototype);
        Map<YangInstanceIdentifier.PathArgument, DataContainerCodecPrototype<?>> byYangCaseChildBuilder = new HashMap<>();
        Map<Class<?>, DataContainerCodecPrototype<?>> byClassBuilder = new HashMap<>();
        Map<Class<?>, DataContainerCodecPrototype<?>> byCaseChildClassBuilder = new HashMap<>();
        Set<Class<?>> potentialSubstitutions = new HashSet<>();
        // Walks all cases for supplied choice in current runtime context
        for (Class<?> caze : factory().getRuntimeContext().getCases(bindingClass())) {
            // We try to load case using exact match thus name
            // and original schema must equals
            DataContainerCodecPrototype<ChoiceCaseNode> cazeDef = loadCase(caze);
            // If we have case definition, this case is instantiated
            // at current location and thus is valid in context of parent choice
            if (cazeDef != null) {
                byClassBuilder.put(cazeDef.getBindingClass(), cazeDef);
                // Updates collection of case children
                for (Class<? extends DataObject> cazeChild : BindingReflections.getChildrenClasses((Class) caze)) {
                    byCaseChildClassBuilder.put(cazeChild, cazeDef);
                }
                // Updates collection of YANG instance identifier to case
                for (DataSchemaNode cazeChild : cazeDef.getSchema().getChildNodes()) {
                    byYangCaseChildBuilder.put(new NodeIdentifier(cazeChild.getQName()), cazeDef);<commit_msg>BUG-2159: compilation failure with generics<commit_after>/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.binding.data.codec.impl;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class ChoiceNodeCodecContext extends DataContainerCodecContext<ChoiceNode> {
    private static final Logger LOG = LoggerFactory.getLogger(ChoiceNodeCodecContext.class);
    private final ImmutableMap<YangInstanceIdentifier.PathArgument, DataContainerCodecPrototype<?>> byYangCaseChild;
    private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byClass;
    private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byCaseChildClass;

    public ChoiceNodeCodecContext(final DataContainerCodecPrototype<ChoiceNode> prototype) {
        super(prototype);
        Map<YangInstanceIdentifier.PathArgument, DataContainerCodecPrototype<?>> byYangCaseChildBuilder = new HashMap<>();
        Map<Class<?>, DataContainerCodecPrototype<?>> byClassBuilder = new HashMap<>();
        Map<Class<?>, DataContainerCodecPrototype<?>> byCaseChildClassBuilder = new HashMap<>();
        Set<Class<?>> potentialSubstitutions = new HashSet<>();
        // Walks all cases for supplied choice in current runtime context
        for (Class caze : factory().getRuntimeContext().getCases(bindingClass())) {
            // We try to load case using exact match thus name
            // and original schema must equals
            DataContainerCodecPrototype<ChoiceCaseNode> cazeDef = loadCase(caze);
            // If we have case definition, this case is instantiated
            // at current location and thus is valid in context of parent choice
            if (cazeDef != null) {
                byClassBuilder.put(cazeDef.getBindingClass(), cazeDef);
                // Updates collection of case children
                for (Class<? extends DataObject> cazeChild : BindingReflections.getChildrenClasses((Class<? extends DataObject>) caze)) {
                    byCaseChildClassBuilder.put(cazeChild, cazeDef);
                }
                // Updates collection of YANG instance identifier to case
                for (DataSchemaNode cazeChild : cazeDef.getSchema().getChildNodes()) {
                    byYangCaseChildBuilder.put(new NodeIdentifier(cazeChild.getQName()), cazeDef);
{'fraction_non_alphanumeric': 0.09492494639027876, 'fraction_numerical': 0.0034310221586847747, 'mean_word_length': 4.129032258064516, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '540561', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1865, 'n_words': 441}