<commit_before>/*
 *
 *  * Copyright (C) 2014 EBay Software Foundation
 *  *
 *  * 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
 *  *
 *  * Authors : <NAME>
 *
 */

package org.opendaylight.ovsdb.lib.schema;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.opendaylight.ovsdb.lib.error.BadSchemaException;

import com.fasterxml.jackson.databind.JsonNode;

public class GenericTableSchema extends TableSchema<GenericTableSchema> {

    public GenericTableSchema() {
    }

    public GenericTableSchema(String tableName) {
        super(tableName);
    }

    public GenericTableSchema (TableSchema tableSchema) {
        super(tableSchema.getName(), tableSchema.getColumnSchemas());
    }

    public GenericTableSchema fromJson(String tableName, JsonNode json) {

        if (!json.isObject() || !json.has("columns")) {
            throw new BadSchemaException("bad tableschema root, expected \"columns\" as child");
        }

        Map<String, ColumnSchema> columns = new HashMap<>();
        for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("columns").fields(); iter.hasNext(); ) {
            Map.Entry<String, JsonNode> column = iter.next();
            logger.trace("{}:{}", tableName, column.getKey());
            columns.put(column.getKey(), ColumnSchema.fromJson(column.getKey(), column.getValue()));
        }

        this.setName(tableName);
        this.setColumns(columns);
        return this;
    }

//    public TableUpdate<GenericTableSchema> updatesFromJson(JsonNode value) {
//        ObjectNode new_ = (ObjectNode) value.get("new");
//        ObjectNode old = (ObjectNode) value.get("new");
//
//        Row<GenericTableSchema> newRow = createRow(new_);
//        Row<GenericTableSchema> oldRow = createRow(old);
//
//        TableUpdate<GenericTableSchema> tableUpdate = new TableUpdate<GenericTableSchema>();
//        tableUpdate.setNew(newRow);
//        tableUpdate.setNew(oldRow);
//
//
//        return null;
//    }
//
//    protected Row<GenericTableSchema> createRow(ObjectNode rowNode) {
//        List<Column<GenericTableSchema, ?>> columns = Lists.newArrayList();
//        for (Iterator<Map.Entry<String, JsonNode>> iter = rowNode.fields(); iter.hasNext();) {
//            Map.Entry<String, JsonNode> next = iter.next();
//            ColumnSchema schema = column(next.getKey());
//            Object o = schema.valueFromJson(next.getValue());
//            columns.add(new Column(schema, o));
//        }
//        return new Row<>(columns);
//    }
}<commit_msg>SonarBugFix:GenericTableSchema Signed-off-by: <NAME> <<EMAIL>><commit_after>/*
 *
 *  * Copyright (C) 2014 EBay Software Foundation
 *  *
 *  * 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
 *  *
 *  * Authors : <NAME>
 *
 */

package org.opendaylight.ovsdb.lib.schema;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.opendaylight.ovsdb.lib.error.BadSchemaException;

import com.fasterxml.jackson.databind.JsonNode;

public class GenericTableSchema extends TableSchema<GenericTableSchema> {

    public GenericTableSchema() {
    }

    public GenericTableSchema(String tableName) {
        super(tableName);
    }

    public GenericTableSchema (TableSchema tableSchema) {
        super(tableSchema.getName(), tableSchema.getColumnSchemas());
    }

    public GenericTableSchema fromJson(String tableName, JsonNode json) {

        if (!json.isObject() || !json.has("columns")) {
            throw new BadSchemaException("bad tableschema root, expected \"columns\" as child");
        }

        Map<String, ColumnSchema> columns = new HashMap<>();
        for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("columns").fields(); iter.hasNext(); ) {
            Map.Entry<String, JsonNode> column = iter.next();
            logger.trace("{}:{}", tableName, column.getKey());
            columns.put(column.getKey(), ColumnSchema.fromJson(column.getKey(), column.getValue()));
        }

        this.setName(tableName);
        this.setColumns(columns);
        return this;
    }
}
{'fraction_non_alphanumeric': 0.13571910871033085, 'fraction_numerical': 0.0036011703803736214, 'mean_word_length': 3.130111524163569, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '3406088', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1255, 'n_words': 274}