Skip to content

Commit

Permalink
add eclipse gradle plugin, remove whitespace from line endings, code …
Browse files Browse the repository at this point in the history
…formatting
  • Loading branch information
Teubel György committed Nov 11, 2013
1 parent 7cd2769 commit a3267fa
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,7 +8,9 @@
reports
target
build
bin
.gradle
.classpath
.project
.settings
.idea
1 change: 1 addition & 0 deletions build.gradle
@@ -1,6 +1,7 @@
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'eclipse'

group = 'com.fiftyonred'
version = '0.1.2'
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/fiftyonred/mock_jedis/MockJedis.java
Expand Up @@ -9,7 +9,7 @@
import java.util.Set;

public class MockJedis extends Jedis {

private MockPipeline pipeline = null;

public MockJedis(String host) {
Expand All @@ -26,21 +26,21 @@ public String set(final String key, String value) {
public String get(final String key) {
return pipeline.get(key).get();
}

@Override
public List<String> mget(final String... keys) {
if (keys.length <= 0) {
throw new JedisDataException("ERR wrong number of arguments for 'mget' command");
}
return pipeline.mget(keys).get();
}

@Override
public String flushAll() {
pipeline.clear();
return "OK";
}

@Override
public Long decrBy(String key, long integer) {
return pipeline.decrBy(key, integer).get();
Expand Down Expand Up @@ -70,17 +70,17 @@ public Long incrBy(String key, long integer) {
public String setex(String key, int seconds, String value) {
return set(key, value);
}

@Override
public Long del(String... keys) {
return pipeline.del(keys).get();
}

@Override
public Long hset(final String key, final String field, final String value) {
return pipeline.hset(key, field, value).get();
}

@Override
public String hget(final String key, final String field) {
return pipeline.hget(key, field).get();
Expand All @@ -90,12 +90,12 @@ public String hget(final String key, final String field) {
public Map<String, String> hgetAll(final String key) {
return pipeline.hgetAll(key).get();
}

@Override
public String hmset(final String key, final Map<String, String> hash) {
return pipeline.hmset(key, hash).get();
}

@Override
public List<String> hmget(final String key, final String... fields) {
return pipeline.hmget(key, fields).get();
Expand All @@ -115,7 +115,7 @@ public String lpop(final String key) {
public Long llen(final String key) {
return pipeline.llen(key).get();
}

@Override
public Pipeline pipelined() {
return pipeline;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/fiftyonred/mock_jedis/MockJedisPool.java
Expand Up @@ -11,12 +11,12 @@ public class MockJedisPool extends JedisPool {
public MockJedisPool(Config poolConfig, String host) {
super(poolConfig, host);
}

public Jedis getResource() {
if (client == null) {
client = new MockJedis("localhost");
}
return client;
}
if (client == null) {
client = new MockJedis("localhost");
}
return client;
}

}
52 changes: 26 additions & 26 deletions src/main/java/com/fiftyonred/mock_jedis/MockPipeline.java
Expand Up @@ -14,51 +14,51 @@ public class MockPipeline extends Pipeline {
private final Map<String, String> storage;
private final Map<String, Map<String, String>> hashStorage;
private final Map<String, List<String>> listStorage;

public MockPipeline() {
storage = new HashMap<String, String>();
hashStorage = new HashMap<String, Map<String, String>>();
listStorage = new HashMap<String, List<String>>();
}

public void clear() {
storage.clear();
}

@Override
public synchronized Response<String> set(String key, String value) {
Response<String> response = new Response<String>(BuilderFactory.STRING);
storage.put(key, value);
response.set("OK".getBytes());
return response;
}

@Override
public Response<String> setex(String key, int seconds, String value) {
return set(key, value);
}

@Override
public synchronized Response<String> get(String key) {
Response<String> response = new Response<String>(BuilderFactory.STRING);
String val = storage.get(key);
response.set(val != null ? val.getBytes() : null);
return response;
}

@Override
public Response<Long> expire(String key, int seconds) {
Response<Long> response = new Response<Long>(BuilderFactory.LONG);
response.set(seconds);
return response;
}

@Override
public synchronized Response<List<String>> mget(String... keys) {
Response<List<String>> response = new Response<List<String>>(BuilderFactory.STRING_LIST);

List<byte[]> result = new ArrayList<byte[]>();
for (String key: keys) {
for (String key : keys) {
if (storage.containsKey(key)) {
result.add(storage.get(key).getBytes());
} else {
Expand All @@ -68,12 +68,12 @@ public synchronized Response<List<String>> mget(String... keys) {
response.set(result);
return response;
}

@Override
public Response<Long> decr(String key) {
return decrBy(key, 1);
}

@Override
public synchronized Response<Long> decrBy(String key, long integer) {
Response<Long> response = new Response<Long>(BuilderFactory.LONG);
Expand All @@ -83,12 +83,12 @@ public synchronized Response<Long> decrBy(String key, long integer) {
response.set(result);
return response;
}

@Override
public Response<Long> incr(String key) {
return incrBy(key, 1);
}

@Override
public synchronized Response<Long> incrBy(String key, long integer) {
Response<Long> response = new Response<Long>(BuilderFactory.LONG);
Expand All @@ -98,12 +98,12 @@ public synchronized Response<Long> incrBy(String key, long integer) {
response.set(result);
return response;
}

@Override
public synchronized Response<Long> del(String... keys) {
Response<Long> response = new Response<Long>(BuilderFactory.LONG);
Long result = 0L;
for (String key: keys) {
for (String key : keys) {
String i = storage.remove(key);
if (i != null) {
++result;
Expand All @@ -112,7 +112,7 @@ public synchronized Response<Long> del(String... keys) {
response.set(result);
return response;
}

@Override
public synchronized Response<String> hget(String key, String field) {
Response<String> response = new Response<String>(BuilderFactory.STRING);
Expand Down Expand Up @@ -154,29 +154,29 @@ public synchronized Response<Long> hset(String key, String field, String value)
if (!hashStorage.containsKey(key)) {
hashStorage.put(key, m);
}

return response;
}

@Override
public synchronized Response<List<String>> hmget(String key, String... fields) {
Response<List<String>> response = new Response<List<String>>(BuilderFactory.STRING_LIST);
List<byte[]> result = new ArrayList<byte[]>();
if (!hashStorage.containsKey(key)) {
for (String field: fields) {
for (String field : fields) {
result.add(null);
}
response.set(result);
return response;
}
for (String field: fields) {
for (String field : fields) {
String v = hashStorage.get(key).get(field);
result.add(v != null ? v.getBytes() : null);
}
response.set(result);
return response;
}

@Override
public synchronized Response<String> hmset(String key, Map<String, String> hash) {
Response<String> response = new Response<String>(BuilderFactory.STRING);
Expand All @@ -186,7 +186,7 @@ public synchronized Response<String> hmset(String key, Map<String, String> hash)
} else {
m = hashStorage.get(key);
}
for (Map.Entry<String, String> e: hash.entrySet()) {
for (Map.Entry<String, String> e : hash.entrySet()) {
m.put(e.getKey(), e.getValue());
}
if (!hashStorage.containsKey(key)) {
Expand Down Expand Up @@ -232,11 +232,11 @@ public synchronized Response<Long> llen(String key) {
}
return response;
}

@Override
public void sync() {
// do nothing
}
}

@Override
public synchronized Response<Set<String>> keys(final String pattern) {
Expand All @@ -251,8 +251,8 @@ public synchronized Response<Set<String>> keys(final String pattern) {
}

public void filterKeys(final String pattern, final Collection<String> collection, final List<byte[]> result) {
for(String key: collection) {
if(wildcardMatcher.match(key, pattern))
for (String key : collection) {
if (wildcardMatcher.match(key, pattern))
result.add(key.getBytes());
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/fiftyonred/mock_jedis/MockJedisTest.java
Expand Up @@ -8,17 +8,17 @@

public class MockJedisTest {
private Jedis j = null;

@Before
public void setUp() {
j = new MockJedis("test");
}

@Test
public void testSet() {
assertEquals("OK", j.set("test", "123"));
}

@Test
public void testGet() {
j.set("test", "123");
Expand Down
Expand Up @@ -8,12 +8,12 @@

public class MockJedisThreadSafeTest {
private Jedis j = null;

@Before
public void setUp() {
j = new MockJedis("test");
}

@Test
public void testThreadSafety() throws InterruptedException {
final Thread t1 = new Thread(new Runnable() {
Expand Down

0 comments on commit a3267fa

Please sign in to comment.