JAVA-29231 Move modules inside existing container modules (#15492)
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.rate;
|
||||
|
||||
import com.baeldung.rate.exception.ProviderNotFoundException;
|
||||
import com.baeldung.rate.spi.ExchangeRateProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public final class ExchangeRate {
|
||||
|
||||
private static final String DEFAULT_PROVIDER = "com.baeldung.rate.spi.YahooFinanceExchangeRateProvider";
|
||||
|
||||
//All providers
|
||||
public static List<ExchangeRateProvider> providers() {
|
||||
List<ExchangeRateProvider> services = new ArrayList<>();
|
||||
ServiceLoader<ExchangeRateProvider> loader = ServiceLoader.load(ExchangeRateProvider.class);
|
||||
loader.forEach(services::add);
|
||||
return services;
|
||||
}
|
||||
|
||||
//Default provider
|
||||
public static ExchangeRateProvider provider() {
|
||||
return provider(DEFAULT_PROVIDER);
|
||||
}
|
||||
|
||||
//provider by name
|
||||
public static ExchangeRateProvider provider(String providerName) {
|
||||
ServiceLoader<ExchangeRateProvider> loader = ServiceLoader.load(ExchangeRateProvider.class);
|
||||
Iterator<ExchangeRateProvider> it = loader.iterator();
|
||||
while (it.hasNext()) {
|
||||
ExchangeRateProvider provider = it.next();
|
||||
if (providerName.equals(provider.getClass().getName())) {
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
throw new ProviderNotFoundException("Exchange Rate provider " + providerName + " not found");
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.baeldung.rate.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Quote {
|
||||
private String currency;
|
||||
private BigDecimal ask;
|
||||
private BigDecimal bid;
|
||||
private LocalDate date;
|
||||
|
||||
public Quote(String currency, BigDecimal ask, BigDecimal bid) {
|
||||
this.currency = currency;
|
||||
this.ask = ask;
|
||||
this.bid = bid;
|
||||
}
|
||||
|
||||
public String getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public void setCurrency(String currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public BigDecimal getAsk() {
|
||||
return ask;
|
||||
}
|
||||
|
||||
public void setAsk(BigDecimal ask) {
|
||||
this.ask = ask;
|
||||
}
|
||||
|
||||
public BigDecimal getBid() {
|
||||
return bid;
|
||||
}
|
||||
|
||||
public void setBid(BigDecimal bid) {
|
||||
this.bid = bid;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.rate.api;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
public interface QuoteManager {
|
||||
List<Quote> getQuotes(String baseCurrency, LocalDate date);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.rate.exception;
|
||||
|
||||
public class ProviderNotFoundException extends RuntimeException {
|
||||
|
||||
public ProviderNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProviderNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.rate.spi;
|
||||
|
||||
import com.baeldung.rate.api.QuoteManager;
|
||||
|
||||
public interface ExchangeRateProvider {
|
||||
QuoteManager create();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user