<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using IPTables.Net.Exceptions;
using IPTables.Net.Netfilter;
using IPTables.Net.Netfilter.TableSync;

namespace IPTables.Net.Iptables
{
    public class IpTablesChain : INetfilterChain, IEquatable<IpTablesChain>
    {
        private readonly String _name;
        private readonly List<IpTablesRule> _rules;
        private readonly NetfilterSystem _system;
        private readonly String _table;
        private readonly int _ipVersion;

        public IpTablesChain(String table, String chainName, int ipVersion, NetfilterSystem system, List<IpTablesRule> rules)
        {
            _name = chainName;
            _table = table;
            _system = system;
            _rules = rules;
            _ipVersion = ipVersion;
        }

        public IpTablesChain(String table, String chainName, int ipVersion, NetfilterSystem system)
        {
            _name = chainName;
            _table = table;
            _system = system;
            _rules = new List<IpTablesRule>();
            _ipVersion = ipVersion;
        }

        public bool IsEmpty
        {
            get { return !_rules.Any(); }
        }

        public String Name
        {
            get { return _name; }
        }

        public String Table
        {
            get { return _table; }
        }

        public List<IpTablesRule> Rules
        {
            get { return _rules; }
        }

        public int IpVersion
        {
            get { return _ipVersion; }
        }

        public void AddRule(INetfilterRule rule)
        {
            var ruleCast = rule as IpTablesRule;
            if(ruleCast == null)
                throw new IpTablesNetException("Invalid rule type for this chain");

            Rules.Add(ruleCast);
        }

        IEnumerable<INetfilterRule> INetfilterChain.Rules
        {
            get { return _rules.Cast<INetfilterRule>(); }
        } 

        public NetfilterSystem System
        {
            get { return _system; }
        }

        public void Sync(INetfilterAdapterClient client, IEnumerable<IpTablesRule> with,
            INetfilterSync<IpTablesRule> sync)
        {
            client.StartTransaction();

            SyncInternal(client, with, sync);

            client.EndTransactionCommit();
        }

        public void Delete(INetfilterAdapterClient client, bool flush = false)
        {
            _system.DeleteChain(client, _name, _table, _ipVersion, flush);
        }

        public void Delete(bool flush = false)
        {
            _system.DeleteChain(_name, _table, _ipVersion, flush);
        }

        public static bool ValidateChainName(String chainName)
        {
            if (chainName.Length > 30)
            {
                return false;
            }
            return true;<commit_msg>unnecessary if<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using IPTables.Net.Exceptions;
using IPTables.Net.Netfilter;
using IPTables.Net.Netfilter.TableSync;

namespace IPTables.Net.Iptables
{
    public class IpTablesChain : INetfilterChain, IEquatable<IpTablesChain>
    {
        private readonly String _name;
        private readonly List<IpTablesRule> _rules;
        private readonly NetfilterSystem _system;
        private readonly String _table;
        private readonly int _ipVersion;

        public IpTablesChain(String table, String chainName, int ipVersion, NetfilterSystem system, List<IpTablesRule> rules)
        {
            _name = chainName;
            _table = table;
            _system = system;
            _rules = rules;
            _ipVersion = ipVersion;
        }

        public IpTablesChain(String table, String chainName, int ipVersion, NetfilterSystem system)
        {
            _name = chainName;
            _table = table;
            _system = system;
            _rules = new List<IpTablesRule>();
            _ipVersion = ipVersion;
        }

        public bool IsEmpty
        {
            get { return !_rules.Any(); }
        }

        public String Name
        {
            get { return _name; }
        }

        public String Table
        {
            get { return _table; }
        }

        public List<IpTablesRule> Rules
        {
            get { return _rules; }
        }

        public int IpVersion
        {
            get { return _ipVersion; }
        }

        public void AddRule(INetfilterRule rule)
        {
            var ruleCast = rule as IpTablesRule;
            if(ruleCast == null)
                throw new IpTablesNetException("Invalid rule type for this chain");

            Rules.Add(ruleCast);
        }

        IEnumerable<INetfilterRule> INetfilterChain.Rules
        {
            get { return _rules.Cast<INetfilterRule>(); }
        } 

        public NetfilterSystem System
        {
            get { return _system; }
        }

        public void Sync(INetfilterAdapterClient client, IEnumerable<IpTablesRule> with,
            INetfilterSync<IpTablesRule> sync)
        {
            client.StartTransaction();

            SyncInternal(client, with, sync);

            client.EndTransactionCommit();
        }

        public void Delete(INetfilterAdapterClient client, bool flush = false)
        {
            _system.DeleteChain(client, _name, _table, _ipVersion, flush);
        }

        public void Delete(bool flush = false)
        {
            _system.DeleteChain(_name, _table, _ipVersion, flush);
        }

        public static bool ValidateChainName(String chainName)
        {
            return (chainName.Length <= 30);
{'fraction_non_alphanumeric': 0.07180756986204458, 'fraction_numerical': 0.0007074637424831977, 'mean_word_length': 1.7531645569620253, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5380158', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1451, 'n_words': 370}