<commit_before>/*
 * Copyright 2014 the original author or authors
 *
 * 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 android.orm.sql;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.orm.util.Converter;
import android.orm.util.Maybe;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Pair;

import org.jetbrains.annotations.NonNls;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;

import static android.database.DatabaseUtils.sqlEscapeString;
import static android.orm.util.Maybes.nothing;
import static android.orm.util.Maybes.something;
import static java.lang.Double.parseDouble;
import static java.lang.Long.parseLong;

public final class Types {

    public static final Type<String> Text = new Type.Base<String>("text", "*") {

        @NonNls
        @NonNull
        @Override
        public String fromString(@NonNull final String value) {
            return value;
        }

        @NonNls
        @NonNull
        @Override
        public String toString(@NonNull final String value) {
            return value;
        }

        @NonNls
        @NonNull
        @Override
        public String escape(@NonNull final String value) {
            return sqlEscapeString(value);
        }

        @NonNull
        @Override
        public Maybe<String> read(@NonNull final Readable input,
                                  @NonNls @NonNull final String name) {
            return input.getAsString(name);
        }

        @Override
        public void write(@NonNull final Writable output,
                          @NonNls @NonNull final String name,
                          @NonNull final String value) {
            output.put(name, value);
        }
    };

    public static final Type<Long> Integer = new Type.Base<Long>("integer", "#") {

        @NonNull
        @Override
        public Long fromString(@NonNull final String value) {
            return parseLong(value);
        }

        @NonNls
        @NonNull
        @Override
        public String toString(@NonNull final Long value) {
            return value.toString();
        }

        @NonNls
        @NonNull
        @Override
        public String escape(@NonNull final Long value) {
            return value.toString();
        }

        @NonNull
        @Override
        public Maybe<Long> read(@NonNull final Readable input,
                                @NonNls @NonNull final String name) {
            return input.getAsLong(name);
        }

        @Override
        public void write(@NonNull final Writable output,
                          @NonNls @NonNull final String name,
                          @NonNull final Long value) {
            output.put(name, value);
        }
    };

    public static final Type<Double> Real = new Type.Base<Double>("real", "*") {

        @NonNull
        @Override
        public Double fromString(@NonNull final String value) {
            return parseDouble(value);
        }

        @NonNls
        @NonNull
        @Override
        public String toString(@NonNull final Double value) {
            return value.toString();
        }

        @NonNls
        @NonNull
        @Override
        public String escape(@NonNull final Double value) {
            return value.toString();
        }

        @NonNull
        @Override
        public Maybe<Double> read(@NonNull final Readable input,
                                  @NonNls @NonNull final String name) {
            return input.getAsDouble(name);
        }

        @Override
        public void write(@NonNull final Writable output,
                          @NonNls @NonNull final String name,
                          @NonNull final Double value) {
            output.put(name, value);
        }
    };

    @NonNull
    public static <V, T> Type<V> map(@NonNull final Type<T> type,
                                     @NonNull final Converter<V, T> converter) {
        return new Conversion<>(type, converter);
    }

    public static final Type<Boolean> Bool = map(
            Integer,
            new Converter<Boolean, Long>() {

                @NonNull
                @Override
                public Long from(@NonNull final Boolean value) {
                    return value ? 1L : 0L;
                }

                @NonNull
                @Override
                public Boolean to(@NonNull final Long value) {
                    return value > 0L;
                }
            }
    );

    public static final Type<BigDecimal> Decimal = map(
            Text,
            new Converter<BigDecimal, String>() {

                @NonNull
                @Override
                public String from(@NonNull final BigDecimal value) {
                    return value.toPlainString();
                }

                @NonNull
                @Override
                public BigDecimal to(@NonNull final String value) {
                    return new BigDecimal(value);
                }
            }
    );<commit_msg>Make Bool type true for all values except "0"<commit_after>/*
 * Copyright 2014 the original author or authors
 *
 * 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 android.orm.sql;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.orm.util.Converter;
import android.orm.util.Maybe;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Pair;

import org.jetbrains.annotations.NonNls;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;

import static android.database.DatabaseUtils.sqlEscapeString;
import static android.orm.util.Maybes.nothing;
import static android.orm.util.Maybes.something;
import static java.lang.Double.parseDouble;
import static java.lang.Long.parseLong;

public final class Types {

    public static final Type<String> Text = new Type.Base<String>("text", "*") {

        @NonNls
        @NonNull
        @Override
        public String fromString(@NonNull final String value) {
            return value;
        }

        @NonNls
        @NonNull
        @Override
        public String toString(@NonNull final String value) {
            return value;
        }

        @NonNls
        @NonNull
        @Override
        public String escape(@NonNull final String value) {
            return sqlEscapeString(value);
        }

        @NonNull
        @Override
        public Maybe<String> read(@NonNull final Readable input,
                                  @NonNls @NonNull final String name) {
            return input.getAsString(name);
        }

        @Override
        public void write(@NonNull final Writable output,
                          @NonNls @NonNull final String name,
                          @NonNull final String value) {
            output.put(name, value);
        }
    };

    public static final Type<Long> Integer = new Type.Base<Long>("integer", "#") {

        @NonNull
        @Override
        public Long fromString(@NonNull final String value) {
            return parseLong(value);
        }

        @NonNls
        @NonNull
        @Override
        public String toString(@NonNull final Long value) {
            return value.toString();
        }

        @NonNls
        @NonNull
        @Override
        public String escape(@NonNull final Long value) {
            return value.toString();
        }

        @NonNull
        @Override
        public Maybe<Long> read(@NonNull final Readable input,
                                @NonNls @NonNull final String name) {
            return input.getAsLong(name);
        }

        @Override
        public void write(@NonNull final Writable output,
                          @NonNls @NonNull final String name,
                          @NonNull final Long value) {
            output.put(name, value);
        }
    };

    public static final Type<Double> Real = new Type.Base<Double>("real", "*") {

        @NonNull
        @Override
        public Double fromString(@NonNull final String value) {
            return parseDouble(value);
        }

        @NonNls
        @NonNull
        @Override
        public String toString(@NonNull final Double value) {
            return value.toString();
        }

        @NonNls
        @NonNull
        @Override
        public String escape(@NonNull final Double value) {
            return value.toString();
        }

        @NonNull
        @Override
        public Maybe<Double> read(@NonNull final Readable input,
                                  @NonNls @NonNull final String name) {
            return input.getAsDouble(name);
        }

        @Override
        public void write(@NonNull final Writable output,
                          @NonNls @NonNull final String name,
                          @NonNull final Double value) {
            output.put(name, value);
        }
    };

    @NonNull
    public static <V, T> Type<V> map(@NonNull final Type<T> type,
                                     @NonNull final Converter<V, T> converter) {
        return new Conversion<>(type, converter);
    }

    public static final Type<Boolean> Bool = map(
            Integer,
            new Converter<Boolean, Long>() {

                private static final long False = 0L;
                private static final long True = 1L;

                @NonNull
                @Override
                public Long from(@NonNull final Boolean value) {
                    return value ? True : False;
                }

                @NonNull
                @Override
                public Boolean to(@NonNull final Long value) {
                    return value != False;
                }
            }
    );

    public static final Type<BigDecimal> Decimal = map(
            Text,
            new Converter<BigDecimal, String>() {

                @NonNull
                @Override
                public String from(@NonNull final BigDecimal value) {
                    return value.toPlainString();
                }

                @NonNull
                @Override
                public BigDecimal to(@NonNull final String value) {
                    return new BigDecimal(value);
                }
            }
    );
{'fraction_non_alphanumeric': 0.07924269682172536, 'fraction_numerical': 0.0018846911676518462, 'mean_word_length': 1.7403755868544601, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5207724', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2835, 'n_words': 898}