<commit_before>/*
 * Created on Sep 30, 2011
 * Copyright 2010 by <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 org.sejda.cli.adapters;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.sejda.core.exception.SejdaRuntimeException;
import org.sejda.core.manipulation.model.RectangularBox;

/**
 * Adapter for {@link RectangularBox}, providing initialization from string
 * 
 * @author <NAME>
 * 
 */
public class RectangularBoxAdapter {

    private static final int MIN_TOKENS = 4;
    private RectangularBox rectangularBox;

    public RectangularBoxAdapter(String input) {
        try {
            doParse(input);
        } catch (SejdaRuntimeException e) {
            throw new SejdaRuntimeException("Unparsable rectangular box: '" + input + "'. " + e.getMessage(), e);
        }
    }

    /**
     * @param input
     */
    private void doParse(String input) {
        String[] tokens = doubleSplit(input.replaceFirst("^\\(", "").replaceFirst("\\)$", ""), "\\)\\(", ":");

        if (tokens.length < MIN_TOKENS) {
            throw new SejdaRuntimeException("Expected format is: '(bottom:left)(top:right)'");
        }

        int bottom = AdapterUtils.parseInt(tokens[0], "bottom");
        int left = AdapterUtils.parseInt(tokens[1], "left");
        int top = AdapterUtils.parseInt(tokens[2], "top");
        int right = AdapterUtils.parseInt(tokens[3], "right");
<commit_msg>0000016: sejda-console: sonar violations<commit_after>/*
 * Created on Sep 30, 2011
 * Copyright 2010 by <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 org.sejda.cli.adapters;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.sejda.core.exception.SejdaRuntimeException;
import org.sejda.core.manipulation.model.RectangularBox;

/**
 * Adapter for {@link RectangularBox}, providing initialization from string
 * 
 * @author <NAME>
 * 
 */
public class RectangularBoxAdapter {

    private static final int INDEX_OF_BOTTOM_TOKEN = 0;
    private static final int INDEX_OF_LEFT_TOKEN = 1;
    private static final int INDEX_OF_TOP_TOKEN = 2;
    private static final int INDEX_OF_RIGHT_TOKEN = 3;
    private static final int MIN_TOKENS = 4;
    private RectangularBox rectangularBox;

    public RectangularBoxAdapter(String input) {
        try {
            doParse(input);
        } catch (SejdaRuntimeException e) {
            throw new SejdaRuntimeException("Unparsable rectangular box: '" + input + "'. " + e.getMessage(), e);
        }
    }

    /**
     * @param input
     */
    private void doParse(String input) {
        String[] tokens = doubleSplit(input.replaceFirst("^\\(", "").replaceFirst("\\)$", ""), "\\)\\(", ":");

        if (tokens.length < MIN_TOKENS) {
            throw new SejdaRuntimeException("Expected format is: '(bottom:left)(top:right)'");
        }

        int bottom = AdapterUtils.parseInt(tokens[INDEX_OF_BOTTOM_TOKEN], "bottom");
        int left = AdapterUtils.parseInt(tokens[INDEX_OF_LEFT_TOKEN], "left");
        int top = AdapterUtils.parseInt(tokens[INDEX_OF_TOP_TOKEN], "top");
        int right = AdapterUtils.parseInt(tokens[INDEX_OF_RIGHT_TOKEN], "right");

{'fraction_non_alphanumeric': 0.11537561432249005, 'fraction_numerical': 0.010531242686637023, 'mean_word_length': 3.330293819655522, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 9, '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': '3143372', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1217, 'n_words': 375}