Skip to content

Commit

Permalink
Use util package for tests as well and catch up with checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
eveliotc committed Jul 14, 2013
1 parent b833f2c commit 8b8c118
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 51 deletions.
2 changes: 1 addition & 1 deletion carbonite/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="LineLength">
<property name="max" value="100"/>
<property name="max" value="120"/>
</module>
<module name="MethodLength"/>
<!--module name="ParameterNumber"/-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import info.evelio.carbonite.cache.CacheFactory;

import static info.evelio.carbonite.Carbonite.CacheType;
import static info.evelio.carbonite.Carbonite.Defaults.*;
import static info.evelio.carbonite.Carbonite.Defaults.CAPACITY;
import static info.evelio.carbonite.Carbonite.Defaults.FACTORY;
import static info.evelio.carbonite.Carbonite.Defaults.LOAD_FACTOR;
import static info.evelio.carbonite.Carbonite.Defaults.TYPE;
import static info.evelio.carbonite.util.Util.illegalArg;
import static info.evelio.carbonite.util.Util.notNullArg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import java.io.File;

import static info.evelio.carbonite.Carbonite.CacheType;
import static info.evelio.carbonite.util.Util.*;
import static info.evelio.carbonite.util.Util.illegalState;
import static info.evelio.carbonite.util.Util.notNull;
import static info.evelio.carbonite.util.Util.notNullArg;
import static info.evelio.carbonite.util.Util.obtainValidKey;

/*package*/ class CacheFactoryImp<T> implements CacheFactory<String, T> {
/*package*/ static final CacheFactoryImp INSTANCE = new CacheFactoryImp();
Expand Down
4 changes: 2 additions & 2 deletions carbonite/src/main/java/info/evelio/carbonite/Carbonite.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public enum CacheType {
}

public static CarboniteBuilder using(Context context) {
return new CarboniteImp.Builder( context.getApplicationContext() );
return new CarboniteImp.Builder(context.getApplicationContext());
}

public static void setLogEnabled(boolean enabled) {
L.sLogEnabled = enabled;
L.setLogEnabled(enabled);
}

}
12 changes: 6 additions & 6 deletions carbonite/src/main/java/info/evelio/carbonite/CarboniteApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.util.concurrent.Future;

public interface CarboniteApi {
public <T> Carbonite set(String key, T value);
public <T> Future<T> get(String key, Class<T> type);
<T> Carbonite set(String key, T value);
<T> Future<T> get(String key, Class<T> type);

public <T> Carbonite memory(String key, T value);
public <T> Carbonite storage(String key, T value);
<T> Carbonite memory(String key, T value);
<T> Carbonite storage(String key, T value);

public <T> T memory(String key, Class<T> type);
public <T> T storage(String key, Class<T> type);
<T> T memory(String key, Class<T> type);
<T> T storage(String key, Class<T> type);
}
36 changes: 18 additions & 18 deletions carbonite/src/main/java/info/evelio/carbonite/CarboniteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
import info.evelio.carbonite.cache.CacheFactory;

public interface CarboniteBuilder {
public Context context();
public Options retaining(Class type);
Context context();
Options retaining(Class type);

// not funny
public CarboniteBuilder iLoveYou();
CarboniteBuilder iLoveYou();
// build methods
public Carbonite iKnow();
public Carbonite build();
Carbonite iKnow();
Carbonite build();

public interface Options extends CarboniteBuilder {
public Options in(Carbonite.CacheType type);
Options in(Carbonite.CacheType type);

public Options capacity(int capacity);
public Options loadFactor(float loadFactor);
Options capacity(int capacity);
Options loadFactor(float loadFactor);

public Options imp(Class<? extends Cache> imp);
public Options factory(CacheFactory factory);
Options imp(Class<? extends Cache> imp);
Options factory(CacheFactory factory);

public Carbonite.CacheType in();
public int capacity();
public float loadFactor();
Carbonite.CacheType in();
int capacity();
float loadFactor();

public Class<? extends Cache> imp();
public CacheFactory factory();
Class<? extends Cache> imp();
CacheFactory factory();

public CarboniteBuilder builder();
public Class<? extends Object> retaining();
CarboniteBuilder builder();
Class<? extends Object> retaining();

/**
* Note: Must spawn a new Options for current retained class instead of return this
*/
public Options and(Carbonite.CacheType type);
Options and(Carbonite.CacheType type);
}
}
10 changes: 5 additions & 5 deletions carbonite/src/main/java/info/evelio/carbonite/CarboniteImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import info.evelio.carbonite.cache.Cache;
import info.evelio.carbonite.cache.ReferenceCache;
import info.evelio.carbonite.cache.UnmodifiableCache;
import info.evelio.carbonite.util.Util;
import org.jetbrains.annotations.NotNull;

import java.util.LinkedHashSet;
Expand All @@ -25,6 +24,7 @@
import static info.evelio.carbonite.util.Util.illegalAccess;
import static info.evelio.carbonite.util.Util.illegalArg;
import static info.evelio.carbonite.util.Util.len;
import static info.evelio.carbonite.util.Util.newFixedCachedThread;
import static info.evelio.carbonite.util.Util.nonEmpty;
import static info.evelio.carbonite.util.Util.nonEmptyArg;
import static info.evelio.carbonite.util.Util.notNull;
Expand Down Expand Up @@ -122,7 +122,7 @@ private <T> Carbonite doSet(String key, T value, CacheType cacheType) {
}

private <T> Cache<String, T> cacheFor(CacheType cacheType, Class<T> type) {
final Cache<String, T> cache = mCaches.get( buildKey(cacheType, type) );
final Cache<String, T> cache = mCaches.get(buildKey(cacheType, type));
return cache;
}

Expand All @@ -142,9 +142,9 @@ private <T> Future<T> later(ACTION action, String key, T value, Cache<String, T>
// TODO allow only unique ACTIONS, if we are setting/getting certain key multiple times submit just once
switch (action) {
case SET:
return (Future<T>) mExecutor.submit( new SetTask(key, value, cache) );
return (Future<T>) mExecutor.submit(new SetTask(key, value, cache));
case GET:
return mExecutor.submit( new GetTask(key, cache) );
return mExecutor.submit(new GetTask(key, cache));
default:
illegalArg(true, "Unknown action " + action);
return null;
Expand Down Expand Up @@ -287,7 +287,7 @@ public Carbonite build() {
caches.set(buildKey(cacheType, type), built); // alrite let's cache it!
}

return new CarboniteImp( caches, Util.newFixedCachedThread(THREADS, new CarboniteThreadFactory()) );
return new CarboniteImp(caches, newFixedCachedThread(THREADS, new CarboniteThreadFactory()));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import static info.evelio.carbonite.CarboniteBuilder.Options;

public interface CacheFactory<K, T> {
public Cache<K, T> build(Options options);
Cache<K, T> build(Options options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public MapCache(int capacity, float loadFactor) {
mCache = onCreateMap(capacity, loadFactor);
}

protected abstract Map<K,V> onCreateMap(int capacity, float loadFactor);
protected abstract Map<K, V> onCreateMap(int capacity, float loadFactor);

@Override
public V get(K key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public StorageLruCache<T> set(String key, T value) {
try {
editor = mCache.edit(key);
} catch (IOException e) {
L.e(TAG, String.format("Unable to edit %s for %s of type %s ", key, value,mType), e);
L.e(TAG, String.format("Unable to edit %s for %s of type %s ", key, value, mType), e);
}

if (editor == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
/**
* A {@link Cache} wrapper to make it unmodifiable
*/
public final class UnmodifiableCache<K,V> implements Cache<K,V> {
private final Cache<K,V> mWrapped;
public final class UnmodifiableCache<K, V> implements Cache<K, V> {
private final Cache<K, V> mWrapped;

public UnmodifiableCache(Cache<K,V> cache) {
public UnmodifiableCache(Cache<K, V> cache) {
notNullArg(cache, "Given cache must not be null");

mWrapped = cache;
Expand All @@ -21,7 +21,7 @@ public V get(K key) {
}

@Override
public UnmodifiableCache<K,V> set(K key, V value) {
public UnmodifiableCache<K, V> set(K key, V value) {
illegalAccess(true, "You must not try to modify an UnmodifiableCache.");
return null; // never gonna give you up
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class UncheckedFuture<V> implements Future<V>{
public class UncheckedFuture<V> implements Future<V> {
private final Future<V> mWrapped;

public UncheckedFuture(Future<V> future) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import java.io.OutputStream;

public interface Serializer<T> {
public T read(InputStream in);
public boolean write(OutputStream out, T value);
T read(InputStream in);
boolean write(OutputStream out, T value);
}
6 changes: 5 additions & 1 deletion carbonite/src/main/java/info/evelio/carbonite/util/L.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import android.util.Log;

public class L {
/*package*/ static boolean sLogEnabled = true;
private static boolean sLogEnabled = true;

public static void e(String tag, String msg, Throwable tr) {
if (sLogEnabled) {
Log.e(tag, msg, tr);
}
}

public static void setLogEnabled(boolean logEnabled) {
sLogEnabled = logEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import info.evelio.carbonite.future.Present;
import info.evelio.carbonite.future.UncheckedFuture;
import info.evelio.carbonite.util.L;

import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.evelio.carbonite.cache;

import static info.evelio.carbonite.TestHelper.gimmeReferenceCacheOfOne;
import static info.evelio.carbonite.util.TestHelper.gimmeReferenceCacheOfOne;

public class ReferenceCacheTest extends MapCacheTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.junit.Test;

import static info.evelio.carbonite.TestHelper.gimmeReferenceCacheOfOne;
import static info.evelio.carbonite.TestHelper.unmodifiable;
import static info.evelio.carbonite.util.TestHelper.gimmeReferenceCacheOfOne;
import static info.evelio.carbonite.util.TestHelper.unmodifiable;
import static org.junit.Assert.assertEquals;

public class UnmodifiableCacheTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.evelio.carbonite;
package info.evelio.carbonite.util;

import info.evelio.carbonite.cache.Cache;
import info.evelio.carbonite.cache.ReferenceCache;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.evelio.carbonite;
package info.evelio.carbonite.util;

import info.evelio.carbonite.util.Util;
import org.junit.Test;
Expand Down

0 comments on commit 8b8c118

Please sign in to comment.