Skip to content

Commit

Permalink
Added JavaDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
BramBear committed Sep 13, 2017
1 parent 4b0e5e7 commit 38443df
Show file tree
Hide file tree
Showing 16 changed files with 594 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/io/nem/apps/adapters/CoinsDeserializer.java
Expand Up @@ -10,10 +10,18 @@
import io.nem.apps.model.Coin;
import io.nem.apps.model.Coins;


/**
* The Class CoinsDeserializer.
*/
public class CoinsDeserializer implements JsonDeserializer<Coins> {

/** The gson. */
private static Gson gson = new Gson();

/* (non-Javadoc)
* @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
@Override
public Coins deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
Coins coins = new Coins();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/nem/apps/adapters/FiatsXemDeserializer.java
Expand Up @@ -15,8 +15,15 @@
import io.nem.apps.model.Price;
import io.nem.apps.model.XemFiat;


/**
* The Class FiatsXemDeserializer.
*/
public class FiatsXemDeserializer implements JsonDeserializer<FiatsXem> {

/* (non-Javadoc)
* @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
@Override
public FiatsXem deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/nem/apps/adapters/PriceDeserializer.java
Expand Up @@ -9,8 +9,15 @@

import io.nem.apps.model.Price;


/**
* The Class PriceDeserializer.
*/
public class PriceDeserializer implements JsonDeserializer<Price> {

/* (non-Javadoc)
* @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
@Override
public Price deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
Price price = new Price();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/nem/apps/adapters/XemFiatDeserializer.java
Expand Up @@ -13,8 +13,15 @@
import io.nem.apps.model.Price;
import io.nem.apps.model.XemFiat;


/**
* The Class XemFiatDeserializer.
*/
public class XemFiatDeserializer implements JsonDeserializer<XemFiat> {

/* (non-Javadoc)
* @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
@Override
public XemFiat deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {

Expand Down
131 changes: 130 additions & 1 deletion src/main/java/io/nem/apps/converter/PriceConverter.java
Expand Up @@ -9,95 +9,221 @@
import io.nem.apps.model.XemFiat;
import io.nem.apps.service.PriceCompute;


/**
* The Class PriceConverter.
*/
public class PriceConverter {

/**
* Instantiates a new price converter.
*/
private PriceConverter() {
}

/**
* From fiat.
*
* @param symbol the symbol
* @param fiatAmount the fiat amount
* @return the i to xem
*/
public static IToXem fromFiat(String symbol, Double fiatAmount) {
return new PriceConverter.Builder(symbol, fiatAmount);
}

/**
* From xem.
*
* @param xemAmount the xem amount
* @return the i to fiat
*/
public static IToFiat fromXem(String xemAmount) {
return new PriceConverter.Builder(xemAmount);
}

/**
* From fiat.
*
* @param symbol the symbol
* @param fiatAmount the fiat amount
* @return the i to xem
*/
public static IToXem fromFiat(String symbol, String fiatAmount) {
return new PriceConverter.Builder(symbol, fiatAmount);
}

/**
* From xem.
*
* @param xemAmount the xem amount
* @return the i to fiat
*/
public static IToFiat fromXem(Double xemAmount) {
return new PriceConverter.Builder(xemAmount);
}

/**
* The Interface IToXem.
*/
public interface IToXem {

/**
* From fiat.
*
* @param symbol the symbol
* @param fiatAmount the fiat amount
* @return the i to xem
*/
IToXem fromFiat(String symbol, String fiatAmount);

/**
* From fiat.
*
* @param symbol the symbol
* @param fiatAmount the fiat amount
* @return the i to xem
*/
IToXem fromFiat(String symbol, Double fiatAmount);

/**
* From fiat.
*
* @param symbol the symbol
* @return the i to xem
*/
IToXem fromFiat(String symbol);

/**
* To xem.
*
* @return the fiats xem
*/
FiatsXem toXem();

}

/**
* The Interface IToFiat.
*/
public interface IToFiat {

/**
* To fiat.
*
* @param symbol the symbol
* @return the i to fiat
*/
IToFiat toFiat(String symbol);

XemFiat convert();
/**
* Convert.
*
* @return the xem fiat
*/
XemFiat convert();
}

/**
* The Class Builder.
*/
private static class Builder implements IToXem, IToFiat {

/** The fiat symbol. */
private String fiatSymbol = "";

/** The fiat amount. */
private Double fiatAmount = 0d;

/** The fees. */
private Double fees;

/** The xem. */
private Double xem = 0d;

/** The computed price. */
private Double computedPrice = 0d;

/** The conversion kv. */
private ConcurrentHashMap<String, String> conversionKv = new ConcurrentHashMap<String, String>();

/**
* Instantiates a new builder.
*
* @param symbol the symbol
* @param fiatAmount the fiat amount
*/
public Builder(String symbol, Double fiatAmount) {
this.conversionKv.put(symbol, String.valueOf(fiatAmount));;
}

/**
* Instantiates a new builder.
*
* @param symbol the symbol
* @param fiatAmount the fiat amount
*/
public Builder(String symbol, String fiatAmount) {
this.conversionKv.put(symbol, fiatAmount);
}

/**
* Instantiates a new builder.
*
* @param xemAmount the xem amount
*/
public Builder(Double xemAmount) {
this.xem = xemAmount;
}

/**
* Instantiates a new builder.
*
* @param xemAmount the xem amount
*/
public Builder(String xemAmount) {
this.xem = Double.valueOf(xemAmount);
}

/* (non-Javadoc)
* @see io.nem.apps.converter.PriceConverter.IToFiat#toFiat(java.lang.String)
*/
@Override
public IToFiat toFiat(String symbol) {
this.conversionKv.put(symbol, "1.0");
return this;
}

/* (non-Javadoc)
* @see io.nem.apps.converter.PriceConverter.IToXem#fromFiat(java.lang.String)
*/
@Override
public IToXem fromFiat(String symbol) {
this.conversionKv.put(symbol, "1.0");
return this;
}

/* (non-Javadoc)
* @see io.nem.apps.converter.PriceConverter.IToXem#fromFiat(java.lang.String, java.lang.String)
*/
@Override
public IToXem fromFiat(String symbol, String fiatAmount) {
this.conversionKv.put(symbol, fiatAmount);
return this;
}

/* (non-Javadoc)
* @see io.nem.apps.converter.PriceConverter.IToXem#fromFiat(java.lang.String, java.lang.Double)
*/
@Override
public IToXem fromFiat(String symbol, Double fiatAmount) {
this.conversionKv.put(symbol, String.valueOf(fiatAmount));
return this;
}

/* (non-Javadoc)
* @see io.nem.apps.converter.PriceConverter.IToFiat#convert()
*/
@Override
public XemFiat convert() {
try {
Expand All @@ -108,6 +234,9 @@ public XemFiat convert() {
return null;
}

/* (non-Javadoc)
* @see io.nem.apps.converter.PriceConverter.IToXem#toXem()
*/
@Override
public FiatsXem toXem() {
try {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/nem/apps/endpoint/api/EndPoints.java
@@ -1,9 +1,18 @@
package io.nem.apps.endpoint.api;


/**
* The Enum EndPoints.
*/
public enum EndPoints {

/** The cc coin list. */
CC_COIN_LIST("https://www.cryptocompare.com/api/data/coinlist/"),

/** The cc conv single. */
CC_CONV_SINGLE("https://min-api.cryptocompare.com/data/price"),

/** The cc conv multi. */
CC_CONV_MULTI("https://min-api.cryptocompare.com/data/pricemulti");

/** The value. */
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/nem/apps/endpoint/api/NetworkUtils.java
Expand Up @@ -5,11 +5,22 @@
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.asynchttpclient.Response;


/**
* The Class NetworkUtils.
*/
public class NetworkUtils {

/** The async http client. */
private static AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();

/**
* Gets the async.
*
* @param endpoint the endpoint
* @param query the query
* @return the async
*/
public static CompletableFuture<Response> getAsync(EndPoints endpoint, String query) {
return asyncHttpClient.prepareGet(endpoint + query).execute().toCompletableFuture();
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/nem/apps/global/GlobalConfig.java
Expand Up @@ -12,15 +12,32 @@
import io.nem.apps.model.Price;
import io.nem.apps.model.XemFiat;


/**
* The Class GlobalConfig.
*/
public class GlobalConfig {

/** The gson. */
private static Gson gson = null;

/** The instance. */
private static GlobalConfig instance;

/**
* Gets the single instance of GlobalConfig.
*
* @return single instance of GlobalConfig
*/
public static GlobalConfig getInstance() {
if(instance == null)
instance = new GlobalConfig();
return instance;
}

/**
* Instantiates a new global config.
*/
private GlobalConfig() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Coins.class, new CoinsDeserializer());
Expand All @@ -30,6 +47,11 @@ private GlobalConfig() {
gson = gsonBuilder.create();
}

/**
* Gets the gson.
*
* @return the gson
*/
public Gson getGson() {
return gson;
}
Expand Down

0 comments on commit 38443df

Please sign in to comment.