<commit_before>/**
 * Copyright (c) 2010-2018 by the respective copyright holders.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.fritzboxtr064.internal;

import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Class managing all Phonebook related work.
 *
 * @author gitbock
 * @since 1.8.0
 */
public class PhonebookManager {

    // object for accessing fbox tr064
    private Tr064Comm _tr064comm = null;

    // default logger
    private static final Logger logger = LoggerFactory.getLogger(PhonebookManager.class);

    // all PhonebooksEntries
    private ArrayList<PhoneBookEntry> _alEntries = null;

    public PhonebookManager(Tr064Comm tr064comm) {
        this._tr064comm = tr064comm;
        this._alEntries = new ArrayList<PhoneBookEntry>();

    }

    /**
     * Looks up name in phone book entries and returns name and type if found.
     *
     * @param number number to look up name for
     * @param compareCount how many characters must match to accept a match
     * @return found name or null
     */
    public String getNameFromNumber(final String number, final int compareCount) {
        logger.info("Trying to resolve number {} to name comparing {} characters", number, compareCount);
        String reversedAskNumber = new StringBuilder(number).reverse().toString();    // reverse to be able to compare numbers from the end
        for (PhoneBookEntry pbe : _alEntries) {
            for (TelType t : TelType.values()) {
                final String phoneBookTel = getTel(t, pbe);
                if (phoneBookTel == null) {
                    continue;
                }
                String reversedPhonebookTel = new StringBuilder(phoneBookTel.trim()).reverse().toString();<commit_msg>replaced the trim method, to get rid of white spaces in between the number (#5656)<commit_after>/**
 * Copyright (c) 2010-2018 by the respective copyright holders.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.fritzboxtr064.internal;

import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Class managing all Phonebook related work.
 *
 * @author gitbock
 * @since 1.8.0
 */
public class PhonebookManager {

    // object for accessing fbox tr064
    private Tr064Comm _tr064comm = null;

    // default logger
    private static final Logger logger = LoggerFactory.getLogger(PhonebookManager.class);

    // all PhonebooksEntries
    private ArrayList<PhoneBookEntry> _alEntries = null;

    public PhonebookManager(Tr064Comm tr064comm) {
        this._tr064comm = tr064comm;
        this._alEntries = new ArrayList<PhoneBookEntry>();

    }

    /**
     * Looks up name in phone book entries and returns name and type if found.
     *
     * @param number number to look up name for
     * @param compareCount how many characters must match to accept a match
     * @return found name or null
     */
    public String getNameFromNumber(final String number, final int compareCount) {
        logger.info("Trying to resolve number {} to name comparing {} characters", number, compareCount);
        String reversedAskNumber = new StringBuilder(number).reverse().toString();    // reverse to be able to compare numbers from the end
        for (PhoneBookEntry pbe : _alEntries) {
            for (TelType t : TelType.values()) {
                final String phoneBookTel = getTel(t, pbe);
                if (phoneBookTel == null) {
                    continue;
                }
                String reversedPhonebookTel = new StringBuilder(phoneBookTel.replaceAll("\\s+","")).reverse().toString();
{'fraction_non_alphanumeric': 0.08829084041548631, 'fraction_numerical': 0.021718602455146365, 'mean_word_length': 2.9934024505183787, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6446329', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1119, 'n_words': 389}