<commit_before>/*
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 *
 * 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 uk.org.ngo.squeezer.model;

import android.os.Build;
import android.os.Parcel;
import android.support.annotation.NonNull;

import com.google.common.base.Charsets;
import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;

import java.io.UnsupportedEncodingException;
import java.util.Comparator;
import java.util.Map;

import uk.org.ngo.squeezer.Util;
import uk.org.ngo.squeezer.framework.Item;


public class Player extends Item {

    private String mName;

    private final String mIp;

    private final String mModel;

    private final boolean mCanPowerOff;

    /** Hash function to generate at least 64 bits of hashcode from a player's ID. */
    private static final HashFunction mHashFunction = Hashing.goodFastHash(64);

    /**  A hash of the player's ID. */
    private final HashCode mHashCode;

    private PlayerState mPlayerState = new PlayerState();

    /** Is the player connected? */
    private boolean mConnected;

    public Player(Map<String, String> record) {
        setId(record.get("playerid"));
        mIp = record.get("ip");
        mName = record.get("name");
        mModel = record.get("model");
        mCanPowerOff = Util.parseDecimalIntOrZero(record.get("canpoweroff")) == 1;
        mConnected = Util.parseDecimalIntOrZero(record.get("connected")) == 1;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
            mHashCode = mHashFunction.hashString(getId(), Charsets.UTF_8);
        } else {
            // API versions < GINGERBREAD do not have String.getBytes(Charset charset),
            // which hashString() ends up calling. This will trigger an exception.
            byte[] bytes;
            try {
                bytes = getId().getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                // Can't happen, Android's native charset is UTF-8. But just in case
                // we're running on something wacky, fallback to the un-parsed bytes..
                bytes = getId().getBytes();
            }
            mHashCode = mHashFunction.hashBytes(bytes);
        }
    }

    private Player(Parcel source) {
        setId(source.readString());<commit_msg>Remove extraneous period in a comment.<commit_after>/*
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 *
 * 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 uk.org.ngo.squeezer.model;

import android.os.Build;
import android.os.Parcel;
import android.support.annotation.NonNull;

import com.google.common.base.Charsets;
import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;

import java.io.UnsupportedEncodingException;
import java.util.Comparator;
import java.util.Map;

import uk.org.ngo.squeezer.Util;
import uk.org.ngo.squeezer.framework.Item;


public class Player extends Item {

    private String mName;

    private final String mIp;

    private final String mModel;

    private final boolean mCanPowerOff;

    /** Hash function to generate at least 64 bits of hashcode from a player's ID. */
    private static final HashFunction mHashFunction = Hashing.goodFastHash(64);

    /**  A hash of the player's ID. */
    private final HashCode mHashCode;

    private PlayerState mPlayerState = new PlayerState();

    /** Is the player connected? */
    private boolean mConnected;

    public Player(Map<String, String> record) {
        setId(record.get("playerid"));
        mIp = record.get("ip");
        mName = record.get("name");
        mModel = record.get("model");
        mCanPowerOff = Util.parseDecimalIntOrZero(record.get("canpoweroff")) == 1;
        mConnected = Util.parseDecimalIntOrZero(record.get("connected")) == 1;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
            mHashCode = mHashFunction.hashString(getId(), Charsets.UTF_8);
        } else {
            // API versions < GINGERBREAD do not have String.getBytes(Charset charset),
            // which hashString() ends up calling. This will trigger an exception.
            byte[] bytes;
            try {
                bytes = getId().getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                // Can't happen, Android's native charset is UTF-8. But just in case
                // we're running on something wacky, fallback to the un-parsed bytes.
                bytes = getId().getBytes();
            }
            mHashCode = mHashFunction.hashBytes(bytes);
        }
    }

    private Player(Parcel source) {
        setId(source.readString());
{'fraction_non_alphanumeric': 0.10132311977715877, 'fraction_numerical': 0.005919220055710306, 'mean_word_length': 2.8922764227642275, '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': '4553341', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1584, 'n_words': 506}