<commit_before>package net.darkmist.alib.osgi.metatype;

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

import org.osgi.service.metatype.AttributeDefinition;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleAttribute implements AttributeDefinition
{
	private static final Class<SimpleAttribute> CLASS = SimpleAttribute.class;
	private static final Logger logger = LoggerFactory.getLogger(CLASS);
	private final String name;
	private final String id;
	private final String desc;
	private final int card;
	private final int type;
	private final Validator validator;
	private final String[] optVals;
	private final String[] optLabels;
	private final String[] defaults;

	public SimpleAttribute(String name, String id, String desc, int card, int type, Validator validator, String[] optVals, String[] optLabels, String[] defaults)
	{
		this.name = name;
		this.id = id;
		this.desc = desc;
		this.card = card;
		this.type = Attributes.validTypeOrThrow(type);
		this.validator = validator;
		this.optVals = optVals;
		this.optLabels = optLabels;
		this.defaults = defaults;
	}

	public SimpleAttribute(String name, String id, String desc, int card, int type, String[] optVals, String[] optLabels, String[] defaults)
	{
		this(name, id, desc, card, type, null, optVals, optLabels, defaults);
	}

	public static class Builder
	{
		private String name;
		private String id;
		private String desc;
		private int card = 0;
		private int type = AttributeDefinition.STRING;
		private List<String> optVals = null;
		private List<String> optLabels = null;
		private List<String> defaults = null;
		private Validator validator = null;

		private static <T> List<T> arrayToMutableList(T...array)
		{
			if(array == null)
				return null;
			return new ArrayList<T>(Arrays.asList(array));
		}

		private static String[] listToArray(List<String> strs)
		{
			if(strs == null)
				return null;
			return strs.toArray(new String[strs.size()]);
		}
		
		Builder()
		{
		}

		public SimpleAttribute build()
		{
			return new SimpleAttribute(name, id, desc, card, type, validator, listToArray(optVals), listToArray(optLabels), listToArray(defaults));
		}

		public Builder name(String name_)
		{
			this.name = name_;
			return this;
		}
	
		public Builder id(String id_)
		{
			this.id = id_;
			return this;
		}
	
		public Builder description(String desc_)
		{
			this.desc = desc_;
			return this;
		}

		public Builder type(int type_)
		{
			this.type = Attributes.validTypeOrThrow(type_);
			return this;
		}

		public Builder optionValues(String[] optVals_)
		{
			optVals = arrayToMutableList(optVals_);
			return this;
		}

		public Builder addOptionValue(String val)
		{
			if(optVals == null)
				optVals = new ArrayList<String>();
			optVals.add(val);
			return this;
		}

		public Builder optionLabels(String[] optLabels_)
		{
			optLabels = arrayToMutableList(optLabels_);<commit_msg>Add instance and cardinality to Builder<commit_after>package net.darkmist.alib.osgi.metatype;

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

import org.osgi.service.metatype.AttributeDefinition;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleAttribute implements AttributeDefinition
{
	private static final Class<SimpleAttribute> CLASS = SimpleAttribute.class;
	private static final Logger logger = LoggerFactory.getLogger(CLASS);
	private final String name;
	private final String id;
	private final String desc;
	private final int card;
	private final int type;
	private final Validator validator;
	private final String[] optVals;
	private final String[] optLabels;
	private final String[] defaults;

	public SimpleAttribute(String name, String id, String desc, int card, int type, Validator validator, String[] optVals, String[] optLabels, String[] defaults)
	{
		this.name = name;
		this.id = id;
		this.desc = desc;
		this.card = card;
		this.type = Attributes.validTypeOrThrow(type);
		this.validator = validator;
		this.optVals = optVals;
		this.optLabels = optLabels;
		this.defaults = defaults;
	}

	public SimpleAttribute(String name, String id, String desc, int card, int type, String[] optVals, String[] optLabels, String[] defaults)
	{
		this(name, id, desc, card, type, null, optVals, optLabels, defaults);
	}

	public static class Builder
	{
		private String name;
		private String id;
		private String desc;
		private int card = 0;
		private int type = AttributeDefinition.STRING;
		private List<String> optVals = null;
		private List<String> optLabels = null;
		private List<String> defaults = null;
		private Validator validator = null;

		private static <T> List<T> arrayToMutableList(T...array)
		{
			if(array == null)
				return null;
			return new ArrayList<T>(Arrays.asList(array));
		}

		private static String[] listToArray(List<String> strs)
		{
			if(strs == null)
				return null;
			return strs.toArray(new String[strs.size()]);
		}
		
		Builder()
		{
		}

		public static Builder instance()
		{
			return new Builder();
		}

		public SimpleAttribute build()
		{
			return new SimpleAttribute(name, id, desc, card, type, validator, listToArray(optVals), listToArray(optLabels), listToArray(defaults));
		}

		public Builder name(String name_)
		{
			this.name = name_;
			return this;
		}
	
		public Builder id(String id_)
		{
			this.id = id_;
			return this;
		}
	
		public Builder description(String desc_)
		{
			this.desc = desc_;
			return this;
		}

		public Builder cardinality(int card)
		{
			this.card = card;
			return this;
		}

		public Builder type(int type_)
		{
			this.type = Attributes.validTypeOrThrow(type_);
			return this;
		}

		public Builder optionValues(String[] optVals_)
		{
			optVals = arrayToMutableList(optVals_);
			return this;
		}

		public Builder addOptionValue(String val)
		{
			if(optVals == null)
				optVals = new ArrayList<String>();
			optVals.add(val);
			return this;
		}

		public Builder optionLabels(String[] optLabels_)
		{
			optLabels = arrayToMutableList(optLabels_);
{'fraction_non_alphanumeric': 0.10109199205823957, 'fraction_numerical': 0.0009927200529450694, 'mean_word_length': 4.062814070351759, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '1222744', 'n_tokens_mistral': 2133, 'n_tokens_neox': 1880, 'n_words': 547}