<commit_before>/*
 * Copyright  2015 Google Inc. All Rights Reserved.
 * 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.google.blockly.model;

import android.graphics.Color;
import android.support.annotation.IntDef;
import android.support.v4.util.SimpleArrayMap;
import android.text.TextUtils;
import android.util.Log;

import com.google.blockly.ui.FieldWorkspaceParams;
import com.google.blockly.ui.fieldview.FieldView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * The base class for Fields in Blockly. A field is the smallest piece of a {@link Block} and is
 * wrapped by an {@link Input}.
 */
public abstract class Field implements Cloneable {
    private static final String TAG = "Field";

    @IntDef({TYPE_LABEL, TYPE_INPUT, TYPE_ANGLE, TYPE_CHECKBOX, TYPE_COLOUR, TYPE_DATE,
            TYPE_VARIABLE, TYPE_DROPDOWN, TYPE_IMAGE})
    public @interface FieldType {}

    public static final int TYPE_LABEL = 0;
    public static final String TYPE_LABEL_STRING = "field_label";

    public static final int TYPE_INPUT = 1;
    public static final String TYPE_INPUT_STRING = "field_input";

    public static final int TYPE_ANGLE = 2;
    public static final String TYPE_ANGLE_STRING = "field_angle";

    public static final int TYPE_CHECKBOX = 3;
    public static final String TYPE_CHECKBOX_STRING = "field_checkbox";

    public static final int TYPE_COLOUR = 4;
    public static final String TYPE_COLOUR_STRING = "field_colour";

    public static final int TYPE_DATE = 5;
    public static final String TYPE_DATE_STRING = "field_date";

    public static final int TYPE_VARIABLE = 6;
    public static final String TYPE_VARIABLE_STRING = "field_variable";

    public static final int TYPE_DROPDOWN = 7;
    public static final String TYPE_DROPDOWN_STRING = "field_dropdown";

    public static final int TYPE_IMAGE = 8;
    public static final String TYPE_IMAGE_STRING = "field_image";

    /**
     * The list of known FIELD_TYPES. If this list changes {@link #fromJson(JSONObject)} should
     * also be updated to support the new fields.
     */
    protected static final Set<String> FIELD_TYPES = new HashSet<>();
    static {
        FIELD_TYPES.add(TYPE_LABEL_STRING);
        FIELD_TYPES.add(TYPE_INPUT_STRING);
        FIELD_TYPES.add(TYPE_ANGLE_STRING);
        FIELD_TYPES.add(TYPE_CHECKBOX_STRING);
        FIELD_TYPES.add(TYPE_COLOUR_STRING);
        FIELD_TYPES.add(TYPE_DATE_STRING);
        FIELD_TYPES.add(TYPE_VARIABLE_STRING);
        FIELD_TYPES.add(TYPE_DROPDOWN_STRING);
        FIELD_TYPES.add(TYPE_IMAGE_STRING);
    }

    private final String mName;
    private final int mType;

    private FieldView mView;
    private FieldWorkspaceParams mLayoutParams;

<<<<<<< HEAD
    public Field(String name, String type) {
        if (TextUtils.isEmpty(type)) {
            throw new IllegalArgumentException("type may not be empty");
        }

        if (!isFieldType(type)) {<commit_msg>String constants can be package-private<commit_after>/*
 * Copyright  2015 Google Inc. All Rights Reserved.
 * 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.google.blockly.model;

import android.graphics.Color;
import android.support.annotation.IntDef;
import android.support.v4.util.SimpleArrayMap;
import android.text.TextUtils;
import android.util.Log;

import com.google.blockly.ui.FieldWorkspaceParams;
import com.google.blockly.ui.fieldview.FieldView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * The base class for Fields in Blockly. A field is the smallest piece of a {@link Block} and is
 * wrapped by an {@link Input}.
 */
public abstract class Field implements Cloneable {
    private static final String TAG = "Field";

    @IntDef({TYPE_LABEL, TYPE_INPUT, TYPE_ANGLE, TYPE_CHECKBOX, TYPE_COLOUR, TYPE_DATE,
            TYPE_VARIABLE, TYPE_DROPDOWN, TYPE_IMAGE})
    public @interface FieldType {}

    public static final int TYPE_LABEL = 0;
    static final String TYPE_LABEL_STRING = "field_label";

    public static final int TYPE_INPUT = 1;
    static final String TYPE_INPUT_STRING = "field_input";

    public static final int TYPE_ANGLE = 2;
    static final String TYPE_ANGLE_STRING = "field_angle";

    public static final int TYPE_CHECKBOX = 3;
    static final String TYPE_CHECKBOX_STRING = "field_checkbox";

    public static final int TYPE_COLOUR = 4;
    static final String TYPE_COLOUR_STRING = "field_colour";

    public static final int TYPE_DATE = 5;
    static final String TYPE_DATE_STRING = "field_date";

    public static final int TYPE_VARIABLE = 6;
    static final String TYPE_VARIABLE_STRING = "field_variable";

    public static final int TYPE_DROPDOWN = 7;
    static final String TYPE_DROPDOWN_STRING = "field_dropdown";

    public static final int TYPE_IMAGE = 8;
    static final String TYPE_IMAGE_STRING = "field_image";

    /**
     * The list of known FIELD_TYPES. If this list changes {@link #fromJson(JSONObject)} should
     * also be updated to support the new fields.
     */
    protected static final Set<String> FIELD_TYPES = new HashSet<>();
    static {
        FIELD_TYPES.add(TYPE_LABEL_STRING);
        FIELD_TYPES.add(TYPE_INPUT_STRING);
        FIELD_TYPES.add(TYPE_ANGLE_STRING);
        FIELD_TYPES.add(TYPE_CHECKBOX_STRING);
        FIELD_TYPES.add(TYPE_COLOUR_STRING);
        FIELD_TYPES.add(TYPE_DATE_STRING);
        FIELD_TYPES.add(TYPE_VARIABLE_STRING);
        FIELD_TYPES.add(TYPE_DROPDOWN_STRING);
        FIELD_TYPES.add(TYPE_IMAGE_STRING);
    }

    private final String mName;
    private final int mType;

    private FieldView mView;
    private FieldWorkspaceParams mLayoutParams;

<<<<<<< HEAD
    public Field(String name, String type) {
        if (TextUtils.isEmpty(type)) {
            throw new IllegalArgumentException("type may not be empty");
        }

        if (!isFieldType(type)) {
{'fraction_non_alphanumeric': 0.08050565535595476, 'fraction_numerical': 0.0050565535595475716, 'mean_word_length': 3.82723185613359, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '6642318', 'n_tokens_mistral': 2214, 'n_tokens_neox': 2163, 'n_words': 699}