blob: abda132732a8ec0b2f71194a6d4754e79d29e86a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*
* Copyright (C) 2012 The CyanogenMod Project
*
* 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 com.cyanogenmod.filemanager.model;
import android.text.TextUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* A class that restrict the number of queries that can
* be made to the application search system.
*/
public class Query implements Serializable {
private static final long serialVersionUID = 3485374541081012723L;
//IMP! This need to be sync which the command_list.xml resource
//to have the same slots as the filled for the find command
private static final int SLOTS_COUNT = 5;
private final String[] mQUERIES = new String[SLOTS_COUNT];
/**
* Constructor of <code>Query</code>.
*/
public Query() {
super();
}
/**
* Method that returns the value of an slot.
*
* @param slot The slot number
* @return String The text of the query at the slot
*/
public String getSlot(int slot) {
return this.mQUERIES[slot];
}
/**
* Method that sets the value of an slot.
*
* @param query The text of the query at the slot
* @param slot The slot number
* @return Query The query reference
*/
public Query setSlot(String query, int slot) {
this.mQUERIES[slot] = query;
return this;
}
/**
* Method that return the number of slots.
*
* @return int The number of slots
*/
public int getSlotsCount() {
return this.mQUERIES.length;
}
/**
* Method that fill all the available slots (filled from the minimum
* to the maximum slot).
*
* @param queries The queries which fill the slots
* @return Query The query reference
*/
public Query fillSlots(List<String> queries) {
int cc = queries.size();
for (int i = 0; i < cc; i++) {
if (i > this.mQUERIES.length) {
break;
}
this.mQUERIES[i] = queries.get(i);
}
return this;
}
/**
* Method that returns the list of queries.
*
* @return List<String> The list of queries
*/
public List<String> getQueries() {
List<String> queries = new ArrayList<String>(getSlotsCount());
int cc = this.mQUERIES.length;
for (int i = 0; i < cc; i++) {
if (this.mQUERIES[i] != null && this.mQUERIES[i].length() > 0) {
queries.add(this.mQUERIES[i]);
}
}
return queries;
}
/**
* Method that returns the terms of the query in a single string separated by ", " string.
*
* @return String The terms of the query
*/
public String getTerms() {
String terms = TextUtils.join(", ", getQueries().toArray(new String[]{})); //$NON-NLS-1$;
if (terms.endsWith(", ")) { //$NON-NLS-1$;
terms = ""; //$NON-NLS-1$;
}
return terms;
}
}
|