Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 6020d1c

Browse files
author
Evgenii Kanivets
committed
#70[1h]. Move from int to long.
1 parent 228f2ca commit 6020d1c

File tree

9 files changed

+69
-61
lines changed

9 files changed

+69
-61
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/entity/base/BaseEntity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ protected boolean equals(String str1, String str2) {
1919
else return str1.equals(str2);
2020
}
2121

22-
protected int getInteger(double value) {
23-
return (int) value;
22+
protected long getLong(double value) {
23+
return (long) value;
2424
}
2525

26-
protected int getDecimal(double value) {
26+
protected long getDecimal(double value) {
2727
// Strange calculation because of double type precision issue
28-
return (int) Math.round(value * 100 - getInteger(value) * 100);
28+
return (long) Math.round(value * 100 - getLong(value) * 100);
2929
}
3030
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/entity/data/Account.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
*/
1414
public class Account extends BaseEntity implements Parcelable {
1515
private final String title;
16-
private int curSum;
16+
private long curSum;
1717
private final String currency;
18-
private int decimals;
18+
private long decimals;
1919

20-
public Account(long id, String title, int curSum, String currency, int decimals) {
20+
public Account(long id, String title, long curSum, String currency, long decimals) {
2121
this.id = id;
2222
this.title = title;
2323
this.curSum = curSum;
@@ -29,16 +29,16 @@ public Account(String title, double curSum, String currency) {
2929
this.id = -1;
3030
this.title = title;
3131
this.currency = currency;
32-
this.curSum = getInteger(curSum);
32+
this.curSum = getLong(curSum);
3333
this.decimals = getDecimal(curSum);
3434
}
3535

3636
protected Account(Parcel in) {
3737
id = in.readLong();
3838
title = in.readString();
39-
curSum = in.readInt();
39+
curSum = in.readLong();
4040
currency = in.readString();
41-
decimals = in.readInt();
41+
decimals = in.readLong();
4242
}
4343

4444
public static final Creator<Account> CREATOR = new Creator<Account>() {
@@ -57,11 +57,11 @@ public String getTitle() {
5757
return title;
5858
}
5959

60-
public int getCurSum() {
60+
public long getCurSum() {
6161
return curSum;
6262
}
6363

64-
public int getDecimals() {
64+
public long getDecimals() {
6565
return decimals;
6666
}
6767

@@ -76,14 +76,14 @@ public String getCurrency() {
7676
public void put(double amount) {
7777
double sum = curSum + decimals / 100.0;
7878
sum += amount;
79-
curSum = getInteger(sum);
79+
curSum = getLong(sum);
8080
decimals = getDecimal(sum);
8181
}
8282

8383
public void take(double amount) {
8484
double sum = curSum + decimals / 100.0;
8585
sum -= amount;
86-
curSum = getInteger(sum);
86+
curSum = getLong(sum);
8787
decimals = getDecimal(sum);
8888
}
8989

@@ -124,8 +124,8 @@ public int describeContents() {
124124
public void writeToParcel(Parcel dest, int flags) {
125125
dest.writeLong(id);
126126
dest.writeString(title);
127-
dest.writeInt(curSum);
127+
dest.writeLong(curSum);
128128
dest.writeString(currency);
129-
dest.writeInt(decimals);
129+
dest.writeLong(decimals);
130130
}
131131
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/entity/data/Record.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public class Record extends BaseEntity implements Parcelable {
1919
private final int type;
2020
private final String title;
2121
private final Category category;
22-
private final int price;
22+
private final long price;
2323
private final Account account;
2424
private final String currency;
25-
private final int decimals;
25+
private final long decimals;
2626

27-
public Record(long id, long time, int type, String title, long categoryId, int price,
28-
long accountId, String currency, int decimals) {
27+
public Record(long id, long time, int type, String title, long categoryId, long price,
28+
long accountId, String currency, long decimals) {
2929
this.id = id;
3030
this.time = time;
3131
this.type = type;
@@ -37,8 +37,8 @@ public Record(long id, long time, int type, String title, long categoryId, int p
3737
this.decimals = decimals;
3838
}
3939

40-
public Record(long id, long time, int type, String title, Category category, int price,
41-
Account account, String currency, int decimals) {
40+
public Record(long id, long time, int type, String title, Category category, long price,
41+
Account account, String currency, long decimals) {
4242
this.id = id;
4343
this.time = time;
4444
this.type = type;
@@ -59,7 +59,7 @@ public Record(long id, long time, int type, String title, Category category, dou
5959
this.category = category;
6060
this.account = account;
6161
this.currency = currency;
62-
this.price = getInteger(price);
62+
this.price = getLong(price);
6363
this.decimals = getDecimal(price);
6464
}
6565

@@ -72,7 +72,7 @@ public Record(long time, int type, String title, Category category, double price
7272
this.category = category;
7373
this.account = account;
7474
this.currency = currency;
75-
this.price = getInteger(price);
75+
this.price = getLong(price);
7676
this.decimals = getDecimal(price);
7777
}
7878

@@ -82,10 +82,10 @@ protected Record(Parcel in) {
8282
type = in.readInt();
8383
title = in.readString();
8484
category = in.readParcelable(Category.class.getClassLoader());
85-
price = in.readInt();
85+
price = in.readLong();
8686
account = in.readParcelable(Account.class.getClassLoader());
8787
currency = in.readString();
88-
decimals = in.readInt();
88+
decimals = in.readLong();
8989
}
9090

9191
public static final Creator<Record> CREATOR = new Creator<Record>() {
@@ -118,11 +118,11 @@ public Category getCategory() {
118118
return category;
119119
}
120120

121-
public int getPrice() {
121+
public long getPrice() {
122122
return price;
123123
}
124124

125-
public int getDecimals() {
125+
public long getDecimals() {
126126
return decimals;
127127
}
128128

@@ -210,9 +210,9 @@ public void writeToParcel(Parcel dest, int flags) {
210210
dest.writeInt(type);
211211
dest.writeString(title);
212212
dest.writeParcelable(category, 0);
213-
dest.writeInt(price);
213+
dest.writeLong(price);
214214
dest.writeParcelable(account, 0);
215215
dest.writeString(currency);
216-
dest.writeInt(decimals);
216+
dest.writeLong(decimals);
217217
}
218218
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/entity/data/Transfer.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public class Transfer extends BaseEntity implements Parcelable {
1515
private final long time;
1616
private final long fromAccountId;
1717
private final long toAccountId;
18-
private final int fromAmount;
19-
private final int toAmount;
20-
private final int fromDecimals;
21-
private final int toDecimals;
18+
private final long fromAmount;
19+
private final long toAmount;
20+
private final long fromDecimals;
21+
private final long toDecimals;
2222

23-
public Transfer(long id, long time, long fromAccountId, long toAccountId, int fromAmount,
24-
int toAmount, int fromDecimals, int toDecimals) {
23+
public Transfer(long id, long time, long fromAccountId, long toAccountId, long fromAmount,
24+
long toAmount, long fromDecimals, long toDecimals) {
2525
this.fromDecimals = fromDecimals;
2626
this.toDecimals = toDecimals;
2727
this.id = id;
@@ -36,20 +36,20 @@ public Transfer(long time, long fromAccountId, long toAccountId, double fromAmou
3636
this.time = time;
3737
this.fromAccountId = fromAccountId;
3838
this.toAccountId = toAccountId;
39-
this.fromAmount = getInteger(fromAmount);
39+
this.fromAmount = getLong(fromAmount);
4040
this.fromDecimals = getDecimal(fromAmount);
41-
this.toAmount = getInteger(toAmount);
41+
this.toAmount = getLong(toAmount);
4242
this.toDecimals = getDecimal(toAmount);
4343
}
4444

4545
protected Transfer(Parcel in) {
4646
time = in.readLong();
4747
fromAccountId = in.readLong();
4848
toAccountId = in.readLong();
49-
fromAmount = in.readInt();
50-
toAmount = in.readInt();
51-
fromDecimals = in.readInt();
52-
toDecimals = in.readInt();
49+
fromAmount = in.readLong();
50+
toAmount = in.readLong();
51+
fromDecimals = in.readLong();
52+
toDecimals = in.readLong();
5353
}
5454

5555
public static final Creator<Transfer> CREATOR = new Creator<Transfer>() {
@@ -81,19 +81,19 @@ public long getToAccountId() {
8181
return toAccountId;
8282
}
8383

84-
public int getFromAmount() {
84+
public long getFromAmount() {
8585
return fromAmount;
8686
}
8787

88-
public int getToAmount() {
88+
public long getToAmount() {
8989
return toAmount;
9090
}
9191

92-
public int getFromDecimals() {
92+
public long getFromDecimals() {
9393
return fromDecimals;
9494
}
9595

96-
public int getToDecimals() {
96+
public long getToDecimals() {
9797
return toDecimals;
9898
}
9999

@@ -148,9 +148,9 @@ public void writeToParcel(Parcel dest, int flags) {
148148
dest.writeLong(time);
149149
dest.writeLong(fromAccountId);
150150
dest.writeLong(toAccountId);
151-
dest.writeInt(fromAmount);
152-
dest.writeInt(toAmount);
153-
dest.writeInt(fromDecimals);
154-
dest.writeInt(toDecimals);
151+
dest.writeLong(fromAmount);
152+
dest.writeLong(toAmount);
153+
dest.writeLong(fromDecimals);
154+
dest.writeLong(toDecimals);
155155
}
156-
}
156+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/repo/data/AccountRepo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ protected List<Account> getListFromCursor(@Nullable Cursor cursor) {
6565
// Read a account from DB
6666
Account account = new Account(cursor.getLong(idColIndex),
6767
cursor.getString(titleColIndex),
68-
cursor.getInt(curSumColIndex),
68+
cursor.getLong(curSumColIndex),
6969
cursor.getString(currencyColIndex),
70-
cursor.getInt(decimalsColIndex));
70+
cursor.getLong(decimalsColIndex));
7171

7272
accountList.add(account);
7373
} while (cursor.moveToNext());

app/src/main/java/com/blogspot/e_kanivets/moneytracker/repo/data/RecordRepo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ protected List<Record> getListFromCursor(Cursor cursor) {
7575
cursor.getInt(typeColIndex),
7676
cursor.getString(titleColIndex),
7777
cursor.getLong(categoryColIndex),
78-
cursor.getInt(priceColIndex),
78+
cursor.getLong(priceColIndex),
7979
cursor.getLong(accountIdColIndex),
8080
cursor.getString(currencyColIndex),
81-
cursor.getInt(decimalsColIndex));
81+
cursor.getLong(decimalsColIndex));
8282

8383
recordList.add(record);
8484
} while (cursor.moveToNext());
8585
}
8686

8787
return recordList;
8888
}
89-
}
89+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/repo/data/TransferRepo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ protected List<Transfer> getListFromCursor(@Nullable Cursor cursor) {
7373
cursor.getLong(idColTime),
7474
cursor.getLong(idColFromAccountId),
7575
cursor.getLong(idColToAccountId),
76-
cursor.getInt(idColFromAmount),
77-
cursor.getInt(idColToAmount),
78-
cursor.getInt(idColDecimalsFrom),
79-
cursor.getInt(idColDecimalsTo));
76+
cursor.getLong(idColFromAmount),
77+
cursor.getLong(idColToAmount),
78+
cursor.getLong(idColDecimalsFrom),
79+
cursor.getLong(idColDecimalsTo));
8080

8181
accountList.add(account);
8282
} while (cursor.moveToNext());

app/src/main/java/com/blogspot/e_kanivets/moneytracker/util/validator/AccountValidator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ public Account validate() {
6565
valid = false;
6666
}
6767

68-
if (Math.abs(initSum) > Integer.MAX_VALUE) {
68+
if (initSum == Double.MAX_VALUE) {
69+
tilInitSum.setError(context.getString(R.string.field_cant_be_empty));
70+
initSum = 0;
71+
valid = false;
72+
}
73+
74+
if (Math.abs(initSum) > MAX_ABS_VALUE) {
6975
tilInitSum.setError(context.getString(R.string.too_rich));
7076
valid = false;
7177
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/util/validator/IValidator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111

1212
public interface IValidator<T> {
13+
long MAX_ABS_VALUE = Integer.MAX_VALUE * 1024L;
14+
1315
/**
1416
* @return instance of class T if validation passed or null otherwise
1517
*/

0 commit comments

Comments
 (0)