<commit_before>/*
 * Copyright © 2010 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.redhat.rhevm.api.powershell.model;

import java.util.ArrayList;
import java.util.List;

import com.redhat.rhevm.api.model.Network;
import com.redhat.rhevm.api.model.IP;
import com.redhat.rhevm.api.model.MAC;
import com.redhat.rhevm.api.model.NIC;
import com.redhat.rhevm.api.model.NicType;
import com.redhat.rhevm.api.model.VM;
import com.redhat.rhevm.api.powershell.util.PowerShellParser;

public class PowerShellNIC {

    private static final String NICS_TYPE = "RhevmCmd.CLIVmNetworkAdapter";

    static boolean isNIC(PowerShellParser.Entity entity) {
        return NICS_TYPE.equals(entity.getType());
    }

    public static List<NIC> parse(PowerShellParser parser, String vmId, String output) {
        List<NIC> ret = new ArrayList<NIC>();

        for (PowerShellParser.Entity entity : parser.parse(output)) {
            NIC nic = new NIC();

            nic.setId(entity.get("id"));
            nic.setName(entity.get("name"));

            nic.setVm(new VM());
            nic.getVm().setId(vmId);

            Network network = new Network();
            network.setName(entity.get("network"));
            nic.setNetwork(network);

            nic.setType(NicType.fromValue(entity.get("type").toUpperCase()));

            MAC mac = new MAC();
            mac.setAddress(entity.get("macaddress"));
            nic.setMac(mac);

            if (entity.get("address") != null ||
                entity.get("subnet") != null ||
                entity.get("gateway") != null) {
                IP ip = new IP();
                ip.setAddress(entity.get("address"));
                ip.setNetmask(entity.get("subnet"));
                ip.setGateway(entity.get("gateway"));
                nic.setIp(ip);
            }

            ret.add(nic);
        }

        return ret;
    }
}
<commit_msg>powershell: seperate parseEntity from parse for Nics<commit_after>/*
 * Copyright © 2010 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.redhat.rhevm.api.powershell.model;

import java.util.ArrayList;
import java.util.List;

import com.redhat.rhevm.api.model.Network;
import com.redhat.rhevm.api.model.IP;
import com.redhat.rhevm.api.model.MAC;
import com.redhat.rhevm.api.model.NIC;
import com.redhat.rhevm.api.model.NicType;
import com.redhat.rhevm.api.model.VM;
import com.redhat.rhevm.api.powershell.util.PowerShellParser;

public class PowerShellNIC {

    private static final String NICS_TYPE = "RhevmCmd.CLIVmNetworkAdapter";

    static boolean isNIC(PowerShellParser.Entity entity) {
        return NICS_TYPE.equals(entity.getType());
    }

    public static List<NIC> parse(PowerShellParser parser, String vmId, String output) {
        List<NIC> ret = new ArrayList<NIC>();

        for (PowerShellParser.Entity entity : parser.parse(output)) {
            ret.add(parseEntity(vmId, entity));
        }
        return ret;
    }

    public static NIC parseEntity(String vmId, PowerShellParser.Entity entity){
        NIC nic = new NIC();

        nic.setId(entity.get("id"));
        nic.setName(entity.get("name"));

        nic.setVm(new VM());
        nic.getVm().setId(vmId);

        Network network = new Network();
        network.setName(entity.get("network"));
        nic.setNetwork(network);

        nic.setType(NicType.fromValue(entity.get("type").toUpperCase()));

        MAC mac = new MAC();
        mac.setAddress(entity.get("macaddress"));
        nic.setMac(mac);

        if (entity.get("address") != null ||
            entity.get("subnet") != null ||
            entity.get("gateway") != null) {
            IP ip = new IP();
            ip.setAddress(entity.get("address"));
            ip.setNetmask(entity.get("subnet"));
            ip.setGateway(entity.get("gateway"));
            nic.setIp(ip);
        }

        return nic;
    }
}

{'fraction_non_alphanumeric': 0.11602004826434008, 'fraction_numerical': 0.0063114906255801, 'mean_word_length': 2.781052631578947, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1797699', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1565, 'n_words': 456}