<commit_before>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2010-2012 Ausenco Engineering Canada Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.input;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

import com.jaamsim.Samples.SampleConstant;
import com.jaamsim.Samples.SampleExpression;
import com.jaamsim.Samples.SampleOutput;
import com.jaamsim.Samples.SampleProvider;
import com.jaamsim.Samples.TimeSeriesConstantDouble;
import com.jaamsim.StringProviders.StringProvOutput;
import com.jaamsim.StringProviders.StringProvSample;
import com.jaamsim.StringProviders.StringProvider;
import com.jaamsim.basicsim.Entity;
import com.jaamsim.basicsim.Group;
import com.jaamsim.basicsim.ObjectType;
import com.jaamsim.datatypes.BooleanVector;
import com.jaamsim.datatypes.DoubleVector;
import com.jaamsim.datatypes.IntegerVector;
import com.jaamsim.math.Color4d;
import com.jaamsim.ui.NaturalOrderComparator;
import com.jaamsim.units.DimensionlessUnit;
import com.jaamsim.units.TimeUnit;
import com.jaamsim.units.Unit;
import com.jaamsim.units.UserSpecifiedUnit;

public abstract class Input<T> {
	protected static final String INP_ERR_COUNT = "Expected an input with %s value(s), received: %s";
	protected static final String INP_ERR_RANGECOUNT = "Expected an input with %d to %d values, received: %s";
	protected static final String INP_ERR_RANGECOUNTMIN = "Expected an input with at least %d values, received: %s";
	protected static final String INP_ERR_EVENCOUNT = "Expected an input with even number of values, received: %s";
	protected static final String INP_ERR_ODDCOUNT = "Expected an input with odd number of values, received: %s";
	protected static final String INP_ERR_BOOLEAN = "Expected a boolean value, received: %s";
	protected static final String INP_ERR_INTEGER = "Expected an integer value, received: %s";
	protected static final String INP_ERR_INTEGERRANGE = "Expected an integer between %d and %d, received: %d";
	protected static final String INP_ERR_DOUBLE = "Expected an numeric value, received: %s";
	protected static final String INP_ERR_DOUBLERANGE = "Expected a number between %f and %f, received: %f";
	protected static final String INP_ERR_TIME = "Expected a time value (hh:mm or hh:mm:ss), received: %s";
	protected static final String INP_ERR_TIMEVALUE = "Expected a numeric value, 12 numeric values, or a probabilty distribution, received: %s";
	protected static final String INP_ERR_BADSUM = "List must sum to %f, received:%f";
	protected static final String INP_ERR_MONOTONIC = "List must %s monotonically. Values starting at index %s are %s s, %s s, ...";
	protected static final String INP_ERR_BADCHOICE = "Expected one of %s, received: %s";
	protected static final String INP_ERR_ELEMENT = "Error parsing element %d: %s";
	protected static final String INP_ERR_ENTNAME = "Could not find an Entity named: %s";
	protected static final String INP_ERR_NOUNITFOUND = "A unit is required, could not parse '%s' as a %s";
	protected static final String INP_ERR_UNITNOTFOUND = "A unit of type '%s' is required";
	protected static final String INP_ERR_NOTUNIQUE = "List must contain unique entries, repeated entry: %s";
	protected static final String INP_ERR_NOTVALIDENTRY = "List must not contain: %s";
	protected static final String INP_ERR_ENTCLASS = "Expected a %s, %s is a %s";
	protected static final String INP_ERR_INTERFACE = "Expected an object implementing %s, %s does not";
	protected static final String INP_ERR_UNITS = "Unit types do not match";
	protected static final String INP_ERR_UNITUNSPECIFIED = "Unit type has not been specified";
	protected static final String INP_ERR_NOTSUBCLASS = "Expected a subclass of %s, got %s";
	protected static final String INP_ERR_BADDATE = "Expected a valid RFC8601 datetime, got: %s";
	protected static final String INP_VAL_LISTSET = "Values found for %s without %s being set";
	protected static final String INP_VAL_LISTSIZE = "%s and %s must be of equal size";

	public static final String POSITIVE_INFINITY = "Infinity";
	public static final String NEGATIVE_INFINITY = "-Infinity";
	public static final String SEPARATOR = "  ";

	private String keyword; // the preferred name for the input keyword
	private final String category;

	protected T defValue;
	protected T value;

	private boolean edited; // indicates if input has been edited for this entity
	private boolean promptReqd; // indicates whether to prompt the user to save the configuration file
	private boolean hidden; // Hide this input from the EditBox
	private boolean isDef; // Is this input still the default value?
	private String[] valueTokens; // value from .cfg file
	private String defText; // special text to show in the default column of the Input Editor
	private boolean isReqd;     // indicates whether this input must be provided by the user
	private boolean isValid;  // if false, the input is no longer valid and must be re-entered

	public static final Comparator<Object> uiSortOrder = new NaturalOrderComparator();

	public Input(String key, String cat, T def) {
		keyword = key;
		category = cat;
		setDefaultValue(def);

		edited = false;
		promptReqd = true;
		isDef = true;
		hidden = false;
		valueTokens = null;
		defText = null;
		isReqd = false;
		isValid = true;
	}

	public void reset() {
		this.setDefaultValue( this.getDefaultValue() );
		valueTokens = null;
		edited = false;
		isDef = true;
		isValid = true;
	}

	/**
	 * Assigns the internal state for this input to the same values as the
	 * specified input.
	 * @param in - input object to be copied.
	 */
	public void copyFrom(Input<?> in) {

		@SuppressWarnings("unchecked")
		Input<T> inp = (Input<T>) in;

		// Copy the internal state
		value = inp.value;
		valueTokens = inp.valueTokens;
		isDef = false;
		edited = true;<commit_msg>JS: set isValid to true for a copied input<commit_after>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2010-2012 Ausenco Engineering Canada Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.input;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

import com.jaamsim.Samples.SampleConstant;
import com.jaamsim.Samples.SampleExpression;
import com.jaamsim.Samples.SampleOutput;
import com.jaamsim.Samples.SampleProvider;
import com.jaamsim.Samples.TimeSeriesConstantDouble;
import com.jaamsim.StringProviders.StringProvOutput;
import com.jaamsim.StringProviders.StringProvSample;
import com.jaamsim.StringProviders.StringProvider;
import com.jaamsim.basicsim.Entity;
import com.jaamsim.basicsim.Group;
import com.jaamsim.basicsim.ObjectType;
import com.jaamsim.datatypes.BooleanVector;
import com.jaamsim.datatypes.DoubleVector;
import com.jaamsim.datatypes.IntegerVector;
import com.jaamsim.math.Color4d;
import com.jaamsim.ui.NaturalOrderComparator;
import com.jaamsim.units.DimensionlessUnit;
import com.jaamsim.units.TimeUnit;
import com.jaamsim.units.Unit;
import com.jaamsim.units.UserSpecifiedUnit;

public abstract class Input<T> {
	protected static final String INP_ERR_COUNT = "Expected an input with %s value(s), received: %s";
	protected static final String INP_ERR_RANGECOUNT = "Expected an input with %d to %d values, received: %s";
	protected static final String INP_ERR_RANGECOUNTMIN = "Expected an input with at least %d values, received: %s";
	protected static final String INP_ERR_EVENCOUNT = "Expected an input with even number of values, received: %s";
	protected static final String INP_ERR_ODDCOUNT = "Expected an input with odd number of values, received: %s";
	protected static final String INP_ERR_BOOLEAN = "Expected a boolean value, received: %s";
	protected static final String INP_ERR_INTEGER = "Expected an integer value, received: %s";
	protected static final String INP_ERR_INTEGERRANGE = "Expected an integer between %d and %d, received: %d";
	protected static final String INP_ERR_DOUBLE = "Expected an numeric value, received: %s";
	protected static final String INP_ERR_DOUBLERANGE = "Expected a number between %f and %f, received: %f";
	protected static final String INP_ERR_TIME = "Expected a time value (hh:mm or hh:mm:ss), received: %s";
	protected static final String INP_ERR_TIMEVALUE = "Expected a numeric value, 12 numeric values, or a probabilty distribution, received: %s";
	protected static final String INP_ERR_BADSUM = "List must sum to %f, received:%f";
	protected static final String INP_ERR_MONOTONIC = "List must %s monotonically. Values starting at index %s are %s s, %s s, ...";
	protected static final String INP_ERR_BADCHOICE = "Expected one of %s, received: %s";
	protected static final String INP_ERR_ELEMENT = "Error parsing element %d: %s";
	protected static final String INP_ERR_ENTNAME = "Could not find an Entity named: %s";
	protected static final String INP_ERR_NOUNITFOUND = "A unit is required, could not parse '%s' as a %s";
	protected static final String INP_ERR_UNITNOTFOUND = "A unit of type '%s' is required";
	protected static final String INP_ERR_NOTUNIQUE = "List must contain unique entries, repeated entry: %s";
	protected static final String INP_ERR_NOTVALIDENTRY = "List must not contain: %s";
	protected static final String INP_ERR_ENTCLASS = "Expected a %s, %s is a %s";
	protected static final String INP_ERR_INTERFACE = "Expected an object implementing %s, %s does not";
	protected static final String INP_ERR_UNITS = "Unit types do not match";
	protected static final String INP_ERR_UNITUNSPECIFIED = "Unit type has not been specified";
	protected static final String INP_ERR_NOTSUBCLASS = "Expected a subclass of %s, got %s";
	protected static final String INP_ERR_BADDATE = "Expected a valid RFC8601 datetime, got: %s";
	protected static final String INP_VAL_LISTSET = "Values found for %s without %s being set";
	protected static final String INP_VAL_LISTSIZE = "%s and %s must be of equal size";

	public static final String POSITIVE_INFINITY = "Infinity";
	public static final String NEGATIVE_INFINITY = "-Infinity";
	public static final String SEPARATOR = "  ";

	private String keyword; // the preferred name for the input keyword
	private final String category;

	protected T defValue;
	protected T value;

	private boolean edited; // indicates if input has been edited for this entity
	private boolean promptReqd; // indicates whether to prompt the user to save the configuration file
	private boolean hidden; // Hide this input from the EditBox
	private boolean isDef; // Is this input still the default value?
	private String[] valueTokens; // value from .cfg file
	private String defText; // special text to show in the default column of the Input Editor
	private boolean isReqd;     // indicates whether this input must be provided by the user
	private boolean isValid;  // if false, the input is no longer valid and must be re-entered

	public static final Comparator<Object> uiSortOrder = new NaturalOrderComparator();

	public Input(String key, String cat, T def) {
		keyword = key;
		category = cat;
		setDefaultValue(def);

		edited = false;
		promptReqd = true;
		isDef = true;
		hidden = false;
		valueTokens = null;
		defText = null;
		isReqd = false;
		isValid = true;
	}

	public void reset() {
		this.setDefaultValue( this.getDefaultValue() );
		valueTokens = null;
		edited = false;
		isDef = true;
		isValid = true;
	}

	/**
	 * Assigns the internal state for this input to the same values as the
	 * specified input.
	 * @param in - input object to be copied.
	 */
	public void copyFrom(Input<?> in) {

		@SuppressWarnings("unchecked")
		Input<T> inp = (Input<T>) in;

		// Copy the internal state
		value = inp.value;
		valueTokens = inp.valueTokens;
		isDef = false;
		edited = true;
		isValid = true;
{'fraction_non_alphanumeric': 0.08121866563825685, 'fraction_numerical': 0.0029309679907443117, 'mean_word_length': 4.788392857142857, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '121742', 'n_tokens_mistral': 3906, 'n_tokens_neox': 3802, 'n_words': 1507}