1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer.dialpad;
18
19import android.util.Log;
20
21import java.util.ArrayList;
22
23/**
24 * Stores information about a range of characters matched in a display name The integers
25 * start and end indicate that the range start to end (exclusive) correspond to some characters
26 * in the query. Used to highlight certain parts of the contact's display name to indicate that
27 * those ranges matched the user's query.
28 */
29public class SmartDialMatchPosition {
30    private static final String TAG = SmartDialMatchPosition.class.getSimpleName();
31
32    public int start;
33    public int end;
34
35    public SmartDialMatchPosition(int start, int end) {
36        this.start = start;
37        this.end = end;
38    }
39
40    private void advance(int toAdvance) {
41        this.start += toAdvance;
42        this.end += toAdvance;
43    }
44
45    /**
46     * Used by {@link SmartDialNameMatcher} to advance the positions of a match position found in
47     * a sub query.
48     *
49     * @param inList ArrayList of SmartDialMatchPositions to modify.
50     * @param toAdvance Offset to modify by.
51     */
52    public static void advanceMatchPositions(ArrayList<SmartDialMatchPosition> inList,
53            int toAdvance) {
54        for (int i = 0; i < inList.size(); i++) {
55            inList.get(i).advance(toAdvance);
56        }
57    }
58
59    /**
60     * Used mainly for debug purposes. Displays contents of an ArrayList of SmartDialMatchPositions.
61     *
62     * @param list ArrayList of SmartDialMatchPositions to print out in a human readable fashion.
63     */
64    public static void print(ArrayList<SmartDialMatchPosition> list) {
65        for (int i = 0; i < list.size(); i ++) {
66            SmartDialMatchPosition m = list.get(i);
67            Log.d(TAG, "[" + m.start + "," + m.end + "]");
68        }
69    }
70}
71