Commit af3af3f1 authored by Akhmad Fakhoni Listiyan Dede's avatar Akhmad Fakhoni Listiyan Dede
Browse files

Fixing getTradebox for returning null

parent 86d3b7e8
......@@ -88,9 +88,9 @@ public class Database {
addItemToInventory("553b6adc3c892b2edffa877c", 3);
addItemToInventory("553b6adc3c892b2edffa877c", 2);
addItemToInventory("553b6adc3c892b2edffa877c", 3);
addItemToInventory("553b6adc3c892b2edffa877c", 4);
addItemToInventory("553b6adc3c892b2edffa877c", 4);
addItemToInventory("553b6adc3c892b2edffa877c", 4);
addItemToInventory("553b6adc3c892b2edffa877c", 5);
addItemToInventory("553b6adc3c892b2edffa877c", 5);
addItemToInventory("553b6adc3c892b2edffa877c", 5);
//
// System.out.println(saveOfferToTradeBox("553b6adc3c892b2edffa877c", 4, 1, 5, 3));
......@@ -352,23 +352,26 @@ public class Database {
try{
allOffer = new ArrayList<>();
while(cursor.hasNext())
if(cursor.hasNext())
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getString("usertoken").equals(usertoken))
while(cursor.hasNext())
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getString("usertoken").equals(usertoken))
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
}
}
if(allOffer.isEmpty())
else
return null;
} catch (JSONException | NullPointerException ex) {
return null;
......@@ -389,24 +392,27 @@ public class Database {
try{
allOffer = new ArrayList<>();
while(cursor.hasNext())
if(cursor.hasNext())
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(!jsonObj.getString("usertoken").equals(usertoken)
&& (jsonObj.getInt("offered_item") == itemIdx))
while(cursor.hasNext())
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(!jsonObj.getString("usertoken").equals(usertoken)
&& (jsonObj.getInt("offered_item") == itemIdx))
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
}
}
if(allOffer.isEmpty())
else
return null;
} catch (JSONException | NullPointerException ex) {
return null;
......@@ -427,20 +433,23 @@ public class Database {
try{
allOffer = new ArrayList<>();
while(cursor.hasNext())
if(cursor.hasNext())
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
while(cursor.hasNext())
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
}
if(allOffer.isEmpty())
else
return null;
} catch (JSONException | NullPointerException ex) {
return null;
......@@ -461,23 +470,26 @@ public class Database {
try{
allOffer = new ArrayList<>();
while(cursor.hasNext())
if(cursor.hasNext())
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getInt("offered_item") == itemIdx)
while(cursor.hasNext())
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getInt("offered_item") == itemIdx)
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
}
}
if(allOffer.isEmpty())
else
return null;
} catch (JSONException | NullPointerException ex) {
return null;
......
......@@ -71,7 +71,7 @@ public class Message {
// getTradeBox("553b64d23c892b2d5b772c74");
// sendFind("553b64d23c892b2d5b772c74", 4);
System.out.println("Mix item: " + mixItem("553b6adc3c892b2edffa877c", 2, 3));
System.out.println("Mix item: " + mixItem("553b6adc3c892b2edffa877c", 4, 5));
System.out.println("Get inventory: " + getInventory("553b6adc3c892b2edffa877c"));
System.out.println("Get tradebox: " + getTradeBox("553a1674179bf4356b7198d5"));
}
......@@ -679,7 +679,7 @@ public class Message {
jsonObj.put("status", "ok");
jsonObj.put("offers", Database.getTradebox(itemIdx));
response = jsonObj.toString();
}catch(JSONException ex)
}catch(Exception ex)
{
System.out.println("getFindOffer() Error: " + jsonObj.toString());
response = error();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment