Skip to content

Adding initialization-on-demand idiom and noninstantiable class instead of interface constant idiom #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion caching/src/main/java/com/iluwatar/caching/LruCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void clear() {
* 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);
Expand Down
9 changes: 6 additions & 3 deletions dao/src/main/java/com/iluwatar/dao/CustomerSchemaSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bson.Document;

import java.util.ArrayList;
import java.util.List;

/**
* Mongo based banking adapter
Expand Down Expand Up @@ -110,7 +111,7 @@ public void setFunds(String bankAccount, int amount) {
@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
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
Expand Down Expand Up @@ -142,7 +144,7 @@ public MongoCollection<Document> getCountersCollection() {
@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);
Expand All @@ -166,7 +168,7 @@ public Optional<LotteryTicketId> save(LotteryTicket ticket) {
@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);
Expand All @@ -183,7 +185,7 @@ private LotteryTicket docToTicket(Document doc) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public List<CakeInfo> getAllCakes() {
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()));
}
Expand Down
Empty file added module/error.txt
Empty file.
Empty file added module/output.txt
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
package com.iluwatar.object.pool;

import java.util.HashSet;
import java.util.Set;

/**
*
* Generic object pool
*/
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
*/
package com.iluwatar.semaphore;

import java.util.List;
import java.util.ArrayList;

/**
* A FruitBowl contains Fruit.
*/
public class FruitBowl {

private ArrayList<Fruit> fruit = new ArrayList<>();
private List<Fruit> fruit = new ArrayList<>();

/**
*
Expand Down
3 changes: 2 additions & 1 deletion servant/src/main/java/com/iluwatar/servant/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;


/**
Expand Down Expand Up @@ -58,7 +59,7 @@ public static void scenario(Servant servant, int compliment) {
King k = new King();
Queen q = new Queen();

ArrayList<Royalty> guests = new ArrayList<>();
List<Royalty> guests = new ArrayList<>();
guests.add(k);
guests.add(q);

Expand Down
5 changes: 3 additions & 2 deletions servant/src/test/java/com/iluwatar/servant/ServantTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -74,12 +75,12 @@ public void testCheckIfYouWillBeHanged() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
public final class IvoryTower {

/**
* Static to class instance of the class.
* Private constructor so nobody can instantiate the class.
*/
private static final IvoryTower INSTANCE = new IvoryTower();
private IvoryTower() {}

/**
* Private constructor so nobody can instantiate the class.
* Static to class instance of the class.
*/
private IvoryTower() {}
private static final IvoryTower INSTANCE = new IvoryTower();

/**
* To be called by user to obtain instance of the class.
Expand Down