<commit_before>package ru.parallel.octotron.core.attributes;

import ru.parallel.octotron.core.primitive.exception.ExceptionModelFail;
import ru.parallel.octotron.core.primitive.exception.ExceptionParseError;
import ru.parallel.utils.JavaUtils;

import java.text.DecimalFormat;

public class Value
{
	private static class Undefined
	{
		private Undefined() {};

		public static final Undefined value = new Undefined();

		@Override
		public final String toString()
		{
			return "undefined";
		}
	}

	private final Object value;
	private final Class<?> my_class;

	private Value(Object value, Class<?> my_class)
	{
		this.value = value;
		this.my_class = my_class;
	}

	public Value(Value value)
	{
		this.value = value.value;
		this.my_class = value.my_class;
	}

	public static final Value undefined = new Value(Undefined.value, Undefined.class);

	public boolean IsDefined()
	{
		return !equals(undefined);
	}

	/**
	 * tries to convert unchecked Object to the checked Value
	 * if it is a value already - does nothing
	 * */
	public static Value Construct(Object value)
	{
		if(value == null)
			throw new ExceptionModelFail("Value can not be null");

		if(value instanceof Value)
			return (Value) value;
		else if(value instanceof Long)
			return new Value(value, Long.class);
		else if(value instanceof Integer)
			return new Value(((Integer)value).longValue(), Long.class);
		else if(value instanceof Double)
			return new Value(value, Double.class);
		else if(value instanceof Float)
			return new Value(((Float)value).doubleValue(), Double.class);
		else if(value instanceof Boolean)
			return new Value(value, Boolean.class);
		else if(value instanceof String)
			return new Value(value, String.class);

		else
			throw new ExceptionModelFail("unsupported value type: " + value + " : " + value.getClass().getName());
	}

	public Value(Long value)
	{
		this(value, value.getClass());
	}

	public Value(Double value)
	{
		this(value, value.getClass());
	}

	public Value(Boolean value)
	{
		this(value, value.getClass());
	}

	public Value(String value)
	{
		this(value, value.getClass());
	}

	public Value(Integer value)
	{
		this(value.longValue(), Long.class);
	}

	public Value(Float value)
	{
		this(value.doubleValue(), Double.class);
	}

	private static final DecimalFormat df = new DecimalFormat("0.00"); // TODO: is it ok?

	public final String ValueToString()
	{
		if(my_class.equals(Long.class))
			return value.toString();
		else if(my_class.equals(Double.class))
			return df.format(value);
		if(my_class.equals(Boolean.class))
			return value.toString();
		else if(my_class.equals(String.class))
			return JavaUtils.Quotify((String)value);
		else if(value instanceof Undefined)
			return undefined.toString();<commit_msg>wrong toString for undefined value<commit_after>package ru.parallel.octotron.core.attributes;

import ru.parallel.octotron.core.primitive.exception.ExceptionModelFail;
import ru.parallel.octotron.core.primitive.exception.ExceptionParseError;
import ru.parallel.utils.JavaUtils;

import java.text.DecimalFormat;

public class Value
{
	private static class Undefined
	{
		private Undefined() {};

		public static final Undefined value = new Undefined();

		@Override
		public final String toString()
		{
			return "undefined";
		}
	}

	private final Object value;
	private final Class<?> my_class;

	private Value(Object value, Class<?> my_class)
	{
		this.value = value;
		this.my_class = my_class;
	}

	public Value(Value value)
	{
		this.value = value.value;
		this.my_class = value.my_class;
	}

	public static final Value undefined = new Value(Undefined.value, Undefined.class);

	public boolean IsDefined()
	{
		return !equals(undefined);
	}

	/**
	 * tries to convert unchecked Object to the checked Value
	 * if it is a value already - does nothing
	 * */
	public static Value Construct(Object value)
	{
		if(value == null)
			throw new ExceptionModelFail("Value can not be null");

		if(value instanceof Value)
			return (Value) value;
		else if(value instanceof Long)
			return new Value(value, Long.class);
		else if(value instanceof Integer)
			return new Value(((Integer)value).longValue(), Long.class);
		else if(value instanceof Double)
			return new Value(value, Double.class);
		else if(value instanceof Float)
			return new Value(((Float)value).doubleValue(), Double.class);
		else if(value instanceof Boolean)
			return new Value(value, Boolean.class);
		else if(value instanceof String)
			return new Value(value, String.class);

		else
			throw new ExceptionModelFail("unsupported value type: " + value + " : " + value.getClass().getName());
	}

	public Value(Long value)
	{
		this(value, value.getClass());
	}

	public Value(Double value)
	{
		this(value, value.getClass());
	}

	public Value(Boolean value)
	{
		this(value, value.getClass());
	}

	public Value(String value)
	{
		this(value, value.getClass());
	}

	public Value(Integer value)
	{
		this(value.longValue(), Long.class);
	}

	public Value(Float value)
	{
		this(value.doubleValue(), Double.class);
	}

	private static final DecimalFormat df = new DecimalFormat("0.00"); // TODO: is it ok?

	public final String ValueToString()
	{
		if(my_class.equals(Long.class))
			return value.toString();
		else if(my_class.equals(Double.class))
			return df.format(value);
		if(my_class.equals(Boolean.class))
			return value.toString();
		else if(my_class.equals(String.class))
			return JavaUtils.Quotify((String)value);
		else if(value instanceof Undefined)
			return value.toString();
{'fraction_non_alphanumeric': 0.11839477029235518, 'fraction_numerical': 0.0010895224260032686, 'mean_word_length': 4.311475409836065, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2767661', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1689, 'n_words': 459}