<commit_before>package com.wordpress.nprogramming;

import java.util.Stack;

import static com.google.common.base.Preconditions.*;

final class BitTranslatorImpl implements BitTranslator {
    private final static Byte one = 1;
    private final static Byte zero = 0;

    @Override
    public String getBitRepresentation(Long number) {
        checkNotNull(number);

        if (number == 0)
            return "0000000000000000000000000000000000000000000000000000000000000000";
        else
            return analyzeNumber(number, 64);
    }

    @Override
    public String getBitRepresentation(Integer number) {
        checkNotNull(number);

        if (number == 0)
            return "00000000000000000000000000000000";
        else
            return analyzeNumber(Long.valueOf(number), 32);
    }

    @Override
    public String getBitRepresentation(Short number) {
        checkNotNull(number);

        if (number == 0)
            return "0000000000000000";
        else
            return analyzeNumber(Long.valueOf(number), 16);
    }

    @Override
    public String getBitRepresentation(Byte number) {
        checkNotNull(number);

        if (number == 0)
            return "00000000";
        else
            return analyzeNumber(Long.valueOf(number), 8);
    }

    private String analyzeNumber(Long number, int numberOfBits) {
        Stack<Number> stack = new Stack<>();

        if (number > 0) {
            processPositiveNumber(number, stack);
            enrichWithLeadingByte(stack, zero, numberOfBits);
        } else {
            processNegativeNumber(number, stack);
            enrichWithLeadingByte(stack, one, numberOfBits);
        }

        return getResult(stack);
    }

    private String getResult(Stack<Number> stack) {
        StringBuilder result = new StringBuilder();
        while (!stack.isEmpty())
            result.append(stack.pop().toString());

        return result.toString();
    }

    private void processNegativeNumber(long x, Stack<Number> stack) {
        x = -1 * x - 1;

        while (x > 0) {
            if (x % 2 == 1)
                stack.push(zero);
            else
                stack.push(one);
            x = x / 2;
        }
    }

    private void processPositiveNumber(long x, Stack<Number> stack) {
        while (x > 0) {
            if (x % 2 == 0)
                stack.push(zero);
            else
                stack.push(one);
            x = x / 2;
        }
    }

    private void enrichWithLeadingByte(Stack<Number> stack, Byte leadingByte, int numberOfBits) {
        int numberOfZerosToAdd = numberOfBits - stack.size();

        for (int i = 0; i < numberOfZerosToAdd; i++)
            stack.push(leadingByte);
    }
}<commit_msg>- apply bit optimizations to code<commit_after>package com.wordpress.nprogramming;

import java.util.Stack;

import static com.google.common.base.Preconditions.*;

final class BitTranslatorImpl implements BitTranslator {
    private final static Byte one = 1;
    private final static Byte zero = 0;

    @Override
    public String getBitRepresentation(Long number) {
        checkNotNull(number);

        if (number == 0)
            return "0000000000000000000000000000000000000000000000000000000000000000";
        else
            return analyzeNumber(number, 64);
    }

    @Override
    public String getBitRepresentation(Integer number) {
        checkNotNull(number);

        if (number == 0)
            return "00000000000000000000000000000000";
        else
            return analyzeNumber(Long.valueOf(number), 32);
    }

    @Override
    public String getBitRepresentation(Short number) {
        checkNotNull(number);

        if (number == 0)
            return "0000000000000000";
        else
            return analyzeNumber(Long.valueOf(number), 16);
    }

    @Override
    public String getBitRepresentation(Byte number) {
        checkNotNull(number);

        if (number == 0)
            return "00000000";
        else
            return analyzeNumber(Long.valueOf(number), 8);
    }

    private String analyzeNumber(Long number, int numberOfBits) {
        Stack<Number> stack = new Stack<>();

        if (number > 0) {
            processPositiveNumber(number, stack);
            enrichWithLeadingByte(stack, zero, numberOfBits);
        } else {
            processNegativeNumber(number, stack);
            enrichWithLeadingByte(stack, one, numberOfBits);
        }

        return getResult(stack);
    }

    private String getResult(Stack<Number> stack) {
        StringBuilder result = new StringBuilder();
        while (!stack.isEmpty())
            result.append(stack.pop().toString());

        return result.toString();
    }

    private void processNegativeNumber(long x, Stack<Number> stack) {
        x = -1 * x - 1;

        while (x > 0) {
            if ((x & 1) == 1)
                stack.push(zero);
            else
                stack.push(one);
            x = x >> 1;
        }
    }

    private void processPositiveNumber(long x, Stack<Number> stack) {
        while (x > 0) {
            if ((x & 1) == 0)
                stack.push(zero);
            else
                stack.push(one);
            x = x >> 1;
        }
    }

    private void enrichWithLeadingByte(Stack<Number> stack, Byte leadingByte, int numberOfBits) {
        int numberOfZerosToAdd = numberOfBits - stack.size();

        for (int i = 0; i < numberOfZerosToAdd; i++)
            stack.push(leadingByte);
    }
}
{'fraction_non_alphanumeric': 0.09781420765027322, 'fraction_numerical': 0.052823315118397086, 'mean_word_length': 2.0320265046935395, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '677655', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1396, 'n_words': 375}