Merge pull request #532 from leogtzr/master
Adding initialization-on-demand idiom and noninstantiable class instead of interface constant idiom
This commit is contained in:
commit
9ec0935a1c
@ -167,7 +167,7 @@ public class LruCache {
|
||||
* Returns cache data in list form.
|
||||
*/
|
||||
public List<UserAccount> getCacheDataInListForm() {
|
||||
ArrayList<UserAccount> listOfCacheData = new ArrayList<>();
|
||||
List<UserAccount> listOfCacheData = new ArrayList<>();
|
||||
Node temp = head;
|
||||
while (temp != null) {
|
||||
listOfCacheData.add(temp.userAccount);
|
||||
|
@ -22,10 +22,13 @@
|
||||
*/
|
||||
package com.iluwatar.dao;
|
||||
|
||||
public interface CustomerSchemaSql {
|
||||
public final class CustomerSchemaSql {
|
||||
|
||||
String CREATE_SCHEMA_SQL = "CREATE TABLE CUSTOMERS (ID NUMBER, FNAME VARCHAR(100), "
|
||||
private CustomerSchemaSql() {}
|
||||
|
||||
public static final String CREATE_SCHEMA_SQL = "CREATE TABLE CUSTOMERS (ID NUMBER, FNAME VARCHAR(100), "
|
||||
+ "LNAME VARCHAR(100))";
|
||||
|
||||
String DELETE_SCHEMA_SQL = "DROP TABLE CUSTOMERS";
|
||||
public static final String DELETE_SCHEMA_SQL = "DROP TABLE CUSTOMERS";
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package com.iluwatar.factorykit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -48,7 +49,7 @@ public interface WeaponFactory {
|
||||
* @return factory with specified {@link Builder}s
|
||||
*/
|
||||
static WeaponFactory factory(Consumer<Builder> consumer) {
|
||||
HashMap<WeaponType, Supplier<Weapon>> map = new HashMap<>();
|
||||
Map<WeaponType, Supplier<Weapon>> map = new HashMap<>();
|
||||
consumer.accept(map::put);
|
||||
return name -> map.get(name).get();
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.mongodb.client.model.UpdateOptions;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mongo based banking adapter
|
||||
@ -110,7 +111,7 @@ public class MongoBank implements WireTransfers {
|
||||
@Override
|
||||
public int getFunds(String bankAccount) {
|
||||
Document search = new Document("_id", bankAccount);
|
||||
ArrayList<Document> results = accountsCollection.find(search).limit(1).into(new ArrayList<Document>());
|
||||
List<Document> results = accountsCollection.find(search).limit(1).into(new ArrayList<Document>());
|
||||
if (results.size() > 0) {
|
||||
return results.get(0).getInteger("funds");
|
||||
} else {
|
||||
|
@ -35,8 +35,10 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Mongo lottery ticket database
|
||||
@ -142,7 +144,7 @@ public class MongoTicketRepository implements LotteryTicketRepository {
|
||||
@Override
|
||||
public Optional<LotteryTicket> findById(LotteryTicketId id) {
|
||||
Document find = new Document("ticketId", id.getId());
|
||||
ArrayList<Document> results = ticketsCollection.find(find).limit(1).into(new ArrayList<Document>());
|
||||
List<Document> results = ticketsCollection.find(find).limit(1).into(new ArrayList<Document>());
|
||||
if (results.size() > 0) {
|
||||
LotteryTicket lotteryTicket = docToTicket(results.get(0));
|
||||
return Optional.of(lotteryTicket);
|
||||
@ -166,7 +168,7 @@ public class MongoTicketRepository implements LotteryTicketRepository {
|
||||
@Override
|
||||
public Map<LotteryTicketId, LotteryTicket> findAll() {
|
||||
Map<LotteryTicketId, LotteryTicket> map = new HashMap<>();
|
||||
ArrayList<Document> docs = ticketsCollection.find(new Document()).into(new ArrayList<Document>());
|
||||
List<Document> docs = ticketsCollection.find(new Document()).into(new ArrayList<Document>());
|
||||
for (Document doc: docs) {
|
||||
LotteryTicket lotteryTicket = docToTicket(doc);
|
||||
map.put(lotteryTicket.getId(), lotteryTicket);
|
||||
@ -183,7 +185,7 @@ public class MongoTicketRepository implements LotteryTicketRepository {
|
||||
PlayerDetails playerDetails = new PlayerDetails(doc.getString("email"), doc.getString("bank"),
|
||||
doc.getString("phone"));
|
||||
int[] numArray = Arrays.asList(doc.getString("numbers").split(",")).stream().mapToInt(Integer::parseInt).toArray();
|
||||
HashSet<Integer> numbers = new HashSet<>();
|
||||
Set<Integer> numbers = new HashSet<>();
|
||||
for (int num: numArray) {
|
||||
numbers.add(num);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public class CakeBakingServiceImpl implements CakeBakingService {
|
||||
CakeToppingInfo cakeToppingInfo =
|
||||
new CakeToppingInfo(cake.getTopping().getId(), cake.getTopping().getName(), cake
|
||||
.getTopping().getCalories());
|
||||
ArrayList<CakeLayerInfo> cakeLayerInfos = new ArrayList<>();
|
||||
List<CakeLayerInfo> cakeLayerInfos = new ArrayList<>();
|
||||
for (CakeLayer layer : cake.getLayers()) {
|
||||
cakeLayerInfos.add(new CakeLayerInfo(layer.getId(), layer.getName(), layer.getCalories()));
|
||||
}
|
||||
|
0
module/error.txt
Normal file
0
module/error.txt
Normal file
0
module/output.txt
Normal file
0
module/output.txt
Normal file
@ -23,6 +23,7 @@
|
||||
package com.iluwatar.object.pool;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -30,8 +31,8 @@ import java.util.HashSet;
|
||||
*/
|
||||
public abstract class ObjectPool<T> {
|
||||
|
||||
private HashSet<T> available = new HashSet<>();
|
||||
private HashSet<T> inUse = new HashSet<>();
|
||||
private Set<T> available = new HashSet<>();
|
||||
private Set<T> inUse = new HashSet<>();
|
||||
|
||||
protected abstract T create();
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
package com.iluwatar.semaphore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -29,7 +30,7 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class FruitBowl {
|
||||
|
||||
private ArrayList<Fruit> fruit = new ArrayList<>();
|
||||
private List<Fruit> fruit = new ArrayList<>();
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -26,6 +26,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -58,7 +59,7 @@ public class App {
|
||||
King k = new King();
|
||||
Queen q = new Queen();
|
||||
|
||||
ArrayList<Royalty> guests = new ArrayList<>();
|
||||
List<Royalty> guests = new ArrayList<>();
|
||||
guests.add(k);
|
||||
guests.add(q);
|
||||
|
||||
|
@ -25,6 +25,7 @@ package com.iluwatar.servant;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -74,12 +75,12 @@ public class ServantTest {
|
||||
final Royalty badMoodRoyalty = mock(Royalty.class);
|
||||
when(badMoodRoyalty.getMood()).thenReturn(true);
|
||||
|
||||
final ArrayList<Royalty> goodCompany = new ArrayList<>();
|
||||
final List<Royalty> goodCompany = new ArrayList<>();
|
||||
goodCompany.add(goodMoodRoyalty);
|
||||
goodCompany.add(goodMoodRoyalty);
|
||||
goodCompany.add(goodMoodRoyalty);
|
||||
|
||||
final ArrayList<Royalty> badCompany = new ArrayList<>();
|
||||
final List<Royalty> badCompany = new ArrayList<>();
|
||||
goodCompany.add(goodMoodRoyalty);
|
||||
goodCompany.add(goodMoodRoyalty);
|
||||
goodCompany.add(badMoodRoyalty);
|
||||
|
@ -27,16 +27,16 @@ package com.iluwatar.singleton;
|
||||
*/
|
||||
public final class IvoryTower {
|
||||
|
||||
/**
|
||||
* Static to class instance of the class.
|
||||
*/
|
||||
private static final IvoryTower INSTANCE = new IvoryTower();
|
||||
|
||||
/**
|
||||
* Private constructor so nobody can instantiate the class.
|
||||
*/
|
||||
private IvoryTower() {}
|
||||
|
||||
/**
|
||||
* Static to class instance of the class.
|
||||
*/
|
||||
private static final IvoryTower INSTANCE = new IvoryTower();
|
||||
|
||||
/**
|
||||
* To be called by user to obtain instance of the class.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user