1 |
|
package com.loopback.androidapps.saveapp; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
|
5 |
|
import android.content.ContentValues; |
6 |
|
import android.database.Cursor; |
7 |
|
import android.util.Log; |
8 |
|
|
|
|
| 65,1% |
Uncovered Elements: 30 (86) |
Complexity: 22 |
Complexity Density: 0,38 |
|
9 |
|
public class Item implements SaveAppTable { |
10 |
|
public static DBManager dbManager; |
11 |
|
private int id; |
12 |
|
private String type; |
13 |
|
private String description; |
14 |
|
private Cursor cursor; |
15 |
|
public static SaveApp saveApp; |
16 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
17 |
70
|
public Item() {... |
18 |
70
|
type = null; |
19 |
70
|
description = null; |
20 |
70
|
dbManager = saveApp.getDbManager(); |
21 |
|
} |
22 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
23 |
0
|
public Item(int id, String type, String description) {... |
24 |
0
|
dbManager = saveApp.getDbManager(); |
25 |
0
|
this.id = id; |
26 |
0
|
this.type = type; |
27 |
0
|
this.description = description; |
28 |
|
} |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
30 |
0
|
public void setId(int id) {... |
31 |
0
|
this.id = id; |
32 |
|
} |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
0
|
public int getId() {... |
35 |
0
|
return id; |
36 |
|
} |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0
|
public void setSymbol(String symbol) {... |
39 |
0
|
this.type = symbol; |
40 |
|
} |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
0
|
public String getSymbol() {... |
43 |
0
|
return type; |
44 |
|
} |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
0
|
public void setDescription(String description) {... |
47 |
0
|
this.description = description; |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
32
|
public String getDescription() {... |
51 |
32
|
return description; |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
54 |
3
|
public int insert() {... |
55 |
3
|
Log.i("IT", "Inserting..."); |
56 |
3
|
ContentValues cv = new ContentValues(); |
57 |
3
|
cv.put(DBManager.ITEM_COLUMN_TYPE, type); |
58 |
3
|
cv.put(DBManager.ITEM_COLUMN_DESC, description); |
59 |
3
|
return dbManager.insert(DBManager.ITEM_TABLE, cv); |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
62 |
0
|
public void update() {... |
63 |
0
|
Log.i("IT", "Updating..."); |
64 |
0
|
ContentValues cv = new ContentValues(); |
65 |
0
|
cv.put(DBManager.ITEM_COLUMN_TYPE, type); |
66 |
0
|
cv.put(DBManager.ITEM_COLUMN_DESC, description); |
67 |
0
|
dbManager.update(id, DBManager.ITEM_TABLE, cv); |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
70 |
0
|
public void delete() {... |
71 |
0
|
Log.i("IT", "Deleting..."); |
72 |
0
|
dbManager.delete(id, DBManager.ITEM_TABLE); |
73 |
|
} |
74 |
|
|
|
|
| 85,7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0,3 |
|
75 |
32
|
public void inflate(int _id) {... |
76 |
32
|
id=_id; |
77 |
32
|
Log.i("IT", "Selecting..."); |
78 |
32
|
cursor = dbManager.select(id, DBManager.ITEM_TABLE_ID); |
79 |
32
|
int i = 0; |
80 |
32
|
Log.i("IT", "Reading Cursor..."); |
81 |
32
|
if (cursor.moveToFirst()) |
82 |
32
|
do { |
83 |
32
|
description = cursor.getString(cursor |
84 |
|
.getColumnIndexOrThrow(DBManager.ITEM_COLUMN_DESC)); |
85 |
32
|
type = cursor.getString(cursor |
86 |
|
.getColumnIndexOrThrow(DBManager.ITEM_COLUMN_TYPE)); |
87 |
32
|
i++; |
88 |
32
|
} while (cursor.moveToNext()); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
91 |
0
|
public boolean existType(String value) {... |
92 |
0
|
Log.i("IT", "Exist?..."); |
93 |
0
|
return dbManager.exist(DBManager.ITEM_TABLE, |
94 |
|
DBManager.ITEM_COLUMN_TYPE, value); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
97 |
5
|
public boolean existDescription(String value) {... |
98 |
5
|
Log.i("IT", "Exist?..."); |
99 |
5
|
return dbManager.exist(DBManager.ITEM_TABLE, |
100 |
|
DBManager.ITEM_COLUMN_DESC, value); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
103 |
5
|
public int insertOrGetId(String value) {... |
104 |
5
|
Log.i("IT", "Inserting or Getting Id..."); |
105 |
5
|
if (existDescription(value)) { |
106 |
2
|
Log.i("IT", "Getting Id..."); |
107 |
2
|
return dbManager.getId(DBManager.ITEM_TABLE, |
108 |
|
DBManager.ITEM_COLUMN_DESC, value); |
109 |
|
} else{ |
110 |
3
|
description=value; |
111 |
3
|
return insert(); |
112 |
|
} |
113 |
|
} |
|
|
| 94,7% |
Uncovered Elements: 1 (19) |
Complexity: 4 |
Complexity Density: 0,31 |
|
114 |
14
|
public String[] selectItems() {... |
115 |
14
|
ArrayList<String> items = new ArrayList<String>(); |
116 |
14
|
cursor = dbManager.selectFilter(DBManager.ITEM_TABLE,DBManager.ITEM_COLUMN_DESC,1,"1"); |
117 |
14
|
int i = 0; |
118 |
14
|
Log.i("AC", "Read Cursor"); |
119 |
14
|
if (cursor.moveToFirst()) |
120 |
14
|
do { |
121 |
29
|
description = cursor.getString(cursor |
122 |
|
.getColumnIndexOrThrow(DBManager.ITEM_COLUMN_DESC)); |
123 |
29
|
items.add(description); |
124 |
29
|
i++; |
125 |
29
|
} while (cursor.moveToNext()); |
126 |
14
|
String[] itemStrings = new String[items.size()]; |
127 |
43
|
for (int j = 0; j< items.size();j++) { |
128 |
29
|
itemStrings[j]=items.get(j); |
129 |
|
} |
130 |
14
|
return itemStrings; |
131 |
|
} |
132 |
|
} |
133 |
|
|