Thought i'd release this server with a trade post system. Writing backend atm, interface will be done eventually.
Code:
package org.sabsabionline.rs2.model.trade_post;
import org.sabsabionline.rs2.model.Item;
/**
*
* @author kronn
*
* A class used to construct new products for the trading post
*
*/
public class Product {
/**
*
* Constructs a new product
*
* @param productVendor
* The vendor of the product
* @param date
* The date
* @param productItem
* The product item
* @param productValue
* The product value
*/
public Product(String productVendor, final String date, Item productItem, int productValue) {
this.productVendor = productVendor;
this.date = date;
this.productItem = productItem;
this.productValue = productValue;
}
/**
* @return the productVendor
*/
public String getProductVendor() {
return productVendor;
}
/**
* @return The date
*/
public String getReleaseDate() {
return this.date;
}
/**
* @return the productItem
*/
public Item getProductItem() {
return productItem;
}
/**
* @return the productValue
*/
public int getProductValue() {
return productValue;
}
/**
* The vendor of the product
*/
private final String productVendor;
/**
* The date of the product release
*/
private final String date;
/**
* The product item
*/
private final Item productItem;
/**
* The value of the product
*/
private final int productValue;
}
Code:
package org.sabsabionline.rs2.model.trade_post;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
/**
*
* @author kronn
*
* A class used to parse current listed {@link Product}s
*
*/
public class TradePostParser {
/**
* Java utility logger
*/
private static final Logger LOGGER = Logger.getLogger(TradePostParser.class.getName());
/**
* Path to the product file
*/
private static final Path PATH = Paths.get("data", "trade_post");
/**
* A list of concurrent products
*/
private static final List<Product> PRODUCTS = new ArrayList<Product>();
/**
* Parses saved trade post products, using the gson library
*/
public static final void parse() {
LOGGER.info("Loading trade post products...");
try {
final Gson gson = new Gson();
final Type token = new TypeToken<ArrayList<Product>>() {
}.getType();
final FileReader reader = new FileReader(PATH + "/products.json");
final List<Product> in = gson.fromJson(reader, token);
reader.close();
PRODUCTS.addAll(in);
} catch (IOException e) {
e.printStackTrace();
}
LOGGER.info(PRODUCTS.size() + " trade post products loaded...");
}
}
Code:
[
{
"productVendor": "Mopar",
"date": "20-05-2017 09:10:14",
"productItem": {
"id": 4151,
"count": 1
},
"productValue": 100000
},
{
"productVendor": "Lev518",
"date": "20-05-2017 09:10:14",
"productItem": {
"id": 11802,
"count": 1
},
"productValue": 100000000
}
]