15229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood/* 25229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * Copyright (C) 2010 The Android Open Source Project 35229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * 45229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * Licensed under the Apache License, Version 2.0 (the "License"); 55229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * you may not use this file except in compliance with the License. 65229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * You may obtain a copy of the License at 75229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * 85229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * http://www.apache.org/licenses/LICENSE-2.0 95229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * 105229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * Unless required by applicable law or agreed to in writing, software 115229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * distributed under the License is distributed on an "AS IS" BASIS, 125229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * See the License for the specific language governing permissions and 145229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * limitations under the License. 155229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood */ 165229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwoodpackage com.android.quicksearchbox; 175229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 185229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwoodimport android.database.AbstractCursor; 195229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 205229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwoodimport java.util.ArrayList; 215229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 225229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood/** 235229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood * Mock cursor providing suggestions data. 245229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood */ 255229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwoodpublic class MockSuggestionProviderCursor extends AbstractCursor { 265229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 275229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood private final String[] mColumns; 285229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood private final ArrayList<Row> mRows; 295229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 305229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public MockSuggestionProviderCursor(String[] columns) { 315229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood mColumns = columns; 325229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood mRows = new ArrayList<Row>(); 335229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 345229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 355229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public Row addRow(Object... values) { 365229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood Row row = new Row(values); 375229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood mRows.add(row); 385229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return row; 395229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 405229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 415229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public Object get(int column) { 425229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).get(column); 435229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 445229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 455229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 465229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public String[] getColumnNames() { 475229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mColumns; 485229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 495229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 505229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 515229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public int getCount() { 525229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.size(); 535229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 545229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 555229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 565229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public double getDouble(int column) { 575229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).getDouble(column); 585229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 595229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 605229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 615229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public float getFloat(int column) { 625229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).getFloat(column); 635229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 645229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 655229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 665229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public int getInt(int column) { 675229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).getInt(column); 685229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 695229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 705229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 715229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public long getLong(int column) { 725229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).getLong(column); 735229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 745229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 755229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 765229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public short getShort(int column) { 775229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).getShort(column); 785229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 795229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 805229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 815229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public String getString(int column) { 825229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).getString(column); 835229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 845229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 855229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood @Override 865229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public boolean isNull(int column) { 875229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mRows.get(getPosition()).isNull(column); 885229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 895229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 905229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood private class Row { 915229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood private final Object[] mValues; 925229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public Row(Object... values) { 935229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (values.length > mColumns.length) { 945229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood throw new IllegalArgumentException("Too many columns"); 955229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 965229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood mValues = new Object[mColumns.length]; 975229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood for (int i = 0; i < values.length; ++i) { 985229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood setColumn(i, values[i]); 995229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1005229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1015229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1025229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public Row setColumn(int column, Object value) { 1035229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood mValues[column] = value; 1045229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return this; 1055229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1065229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1075229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public Object get(int column) { 1085229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return mValues[column]; 1095229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1105229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1115229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public double getDouble(int column) { 1125229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood Object o = mValues[column]; 1135229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o == null) return 0d; 1145229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o instanceof Double) return (Double) o; 1155229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return Double.valueOf(o.toString()); 1165229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1175229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1185229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public float getFloat(int column) { 1195229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood Object o = mValues[column]; 1205229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o == null) return 0f; 1215229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o instanceof Float) return (Float) o; 1225229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return Float.valueOf(o.toString()); 1235229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1245229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1255229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public int getInt(int column) { 1265229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood Object o = mValues[column]; 1275229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o == null) return 0; 1285229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return Integer.valueOf(o.toString()); 1295229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1305229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1315229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public long getLong(int column) { 1325229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood Object o = mValues[column]; 1335229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o == null) return 0; 1345229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return Long.valueOf(o.toString()); 1355229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1365229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1375229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public short getShort(int column) { 1385229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood Object o = mValues[column]; 1395229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o == null) return 0; 1405229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return Short.valueOf(o.toString()); 1415229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1425229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1435229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public String getString(int column) { 1445229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood Object o = mValues[column]; 1455229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o == null) return null; 1465229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood if (o instanceof String) return (String) o; 1475229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return o.toString(); 1485229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1495229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1505229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood public boolean isNull(int column) { 1515229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood return (mValues[column] == null); 1525229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1535229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1545229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood } 1555229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood 1565229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood} 157