Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple code improvements - squid:S1118, squid:S1854, squid:S1488, squid:S2259, squid:S00122 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public boolean addProduct(String name, String barcode, double salePrice) {
* @return true if product edits success ; otherwise false.
*/
public boolean editProduct(Product product) {
boolean respond = inventoryDao.editProduct(product);
return respond;
return inventoryDao.editProduct(product);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/refresh/pos/domain/sale/Register.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static boolean isDaoSet() {
}

public static Register getInstance() throws NoDaoSetException {
if (instance == null) instance = new Register();
if (instance == null)
instance = new Register();
return instance;
}

Expand Down Expand Up @@ -90,7 +91,8 @@ public LineItem addItem(Product product, int quantity) {
* @return total price of Sale.
*/
public double getTotal() {
if (currentSale == null) return 0;
if (currentSale == null)
return 0;
return currentSale.getTotal();
}

Expand Down Expand Up @@ -133,7 +135,8 @@ public boolean setCurrentSale(int id) {
* @return true if there is a current Sale; otherwise false.
*/
public boolean hasSale(){
if(currentSale == null)return false;
if(currentSale == null)
return false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static boolean isDaoSet() {
}

public static SaleLedger getInstance() throws NoDaoSetException {
if (instance == null) instance = new SaleLedger();
if (instance == null)
instance = new SaleLedger();
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

@Override
public List<Object> select(String queryString) {
Cursor cursor = null;
try {
SQLiteDatabase database = this.getWritableDatabase();
List<Object> list = new ArrayList<Object>();
Cursor cursor = database.rawQuery(queryString, null);
cursor = database.rawQuery(queryString, null);

if (cursor != null) {
if (cursor.moveToFirst()) {
Expand All @@ -125,13 +126,16 @@ public List<Object> select(String queryString) {
} while (cursor.moveToNext());
}
}
cursor.close();
database.close();
return list;

} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if(cursor != null) {
cursor.close();
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/refresh/pos/techicalservices/Demo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
public class Demo {

private Demo() {}

/**
* Adds the demo product to inventory.
* @param context The current stage of the application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public List<Product> getAllProduct() {
*/
private List<Product> getAllProduct(String condition) {
String queryString = "SELECT * FROM " + DatabaseContents.TABLE_PRODUCT_CATALOG.toString() + condition + " ORDER BY name";
List<Product> list = toProductList(database.select(queryString));
return list;
return toProductList(database.select(queryString));
}

/**
Expand Down Expand Up @@ -108,7 +107,8 @@ private List<Product> getSimilarProductBy(String reference, String value) {
@Override
public Product getProductByBarcode(String barcode) {
List<Product> list = getProductBy("barcode", barcode);
if (list.isEmpty()) return null;
if (list.isEmpty())
return null;
return list.get(0);
}

Expand Down Expand Up @@ -167,8 +167,7 @@ public List<Product> searchProduct(String search) {
*/
private List<ProductLot> getAllProductLot(String condition) {
String queryString = "SELECT * FROM " + DatabaseContents.TABLE_STOCK.toString() + condition;
List<ProductLot> list = toProductLotList(database.select(queryString));
return list;
return toProductLotList(database.select(queryString));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public int addLineItem(int saleId, LineItem lineItem) {
content.put("product_id", lineItem.getProduct().getId());
content.put("quantity", lineItem.getQuantity());
content.put("unit_price", lineItem.getPriceAtSale());
int id = database.insert(DatabaseContents.TABLE_SALE_LINEITEM.toString(), content);
return id;
return database.insert(DatabaseContents.TABLE_SALE_LINEITEM.toString(), content);
}

@Override
Expand All @@ -86,8 +85,7 @@ public List<Sale> getAllSale() {
public List<Sale> getAllSaleDuring(Calendar start, Calendar end) {
String startBound = DateTimeStrategy.getSQLDateFormat(start);
String endBound = DateTimeStrategy.getSQLDateFormat(end);
List<Sale> list = getAllSale(" WHERE end_time BETWEEN '" + startBound + " 00:00:00' AND '" + endBound + " 23:59:59' AND status = 'ENDED'");
return list;
return getAllSale(" WHERE end_time BETWEEN '" + startBound + " 00:00:00' AND '" + endBound + " 23:59:59' AND status = 'ENDED'");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public void onClick(View v) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!gone) go();
if (!gone)
go();
}
}, SPLASH_TIMEOUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void showList(List<Sale> list) {
@Override
public void update() {
int period = spinner.getSelectedItemPosition();
List<Sale> list = null;
List<Sale> list;
Calendar cTime = (Calendar) currentTime.clone();
Calendar eTime = (Calendar) currentTime.clone();

Expand Down