Skip to content
Open
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
#Thu Sep 15 14:56:19 IDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4 changes: 2 additions & 2 deletions rxsnappy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ apply plugin: 'com.android.library'


android {
compileSdkVersion 23
compileSdkVersion 22
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package io.supercharge.rxsnappy;

import android.os.CountDownTimer;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;

import com.snappydb.SnappydbException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.supercharge.mock.DataGenerator;
import io.supercharge.mock.DummyData;
import io.supercharge.mock.MockedResponse;
import io.supercharge.rxsnappy.exception.RxSnappyException;
import rx.functions.Action1;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
Expand Down Expand Up @@ -53,6 +58,45 @@ public void testResetDatabase() throws SnappydbException {
}


@SmallTest
public void testHashMap(){
final String key_test_hash = "hash me up23";
HashMap<Object , Object> hash = new HashMap<>();
hash.put("key", "value");
rxSnappyClient.setHashMapList(key_test_hash ,hash).subscribe(new Action1<HashMap<Object, Object>>() {
@Override
public void call(HashMap<Object, Object> objectObjectHashMap) {
Log.d("check the hash" , "key is cache up!");
}
});

new CountDownTimer(1000 , 1000){

@Override
public void onTick(long millisUntilFinished) {

}

@Override
public void onFinish() {
rxSnappyClient.getHashMapList(key_test_hash, (long) 100000).subscribe(new Action1<HashMap<Object, Object>>() {
@Override
public void call(HashMap<Object, Object> objectObjectHashMap) {
for (Map.Entry<Object, Object> entry : objectObjectHashMap.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
Log.d("check the hash" , "key = "+ key.toString() + " value =" + value.toString());

}
}
});
}
}.start();



}

@SmallTest
public void testBooleanValue() throws Exception {
Boolean expected = Boolean.TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import io.supercharge.rxsnappy.exception.CacheExpiredException;
import io.supercharge.rxsnappy.exception.KeyIsNullException;
import io.supercharge.rxsnappy.exception.MissingDataException;
import io.supercharge.rxsnappy.exception.RxSnappyException;
import io.supercharge.rxsnappy.exception.ValueIsNullException;
import io.supercharge.rxsnappy.objects.keyValue;

/**
* Created by richardradics on 25/11/15.
Expand Down Expand Up @@ -104,7 +106,7 @@ public boolean isInCache(String key) throws SnappydbException {
}
}

public boolean exsts(String key) throws SnappydbException {
public Boolean isExists(String key) throws SnappydbException {
synchronized (db) {
return db.exists(key);
}
Expand Down Expand Up @@ -261,6 +263,47 @@ protected void setStringListValue(String key, List<String> value, boolean ignore
}



protected void setHashMap(String key, HashMap<Object , Object> value, boolean ignoreCache) throws SnappydbException, RxSnappyException {
synchronized (db) {
if (key == null) {
throw new KeyIsNullException();
}
if (value == null) {
throw new ValueIsNullException();
}


if (!ignoreCache) {
db.put(generateKey(key), value.entrySet().toArray());
removePreviousCachedElement(key);
} else {
db.put(key, value.entrySet().toArray());
}
}
}


protected HashMap<Object , Object> getHashMap(String key, Long cacheTime) throws SnappydbException {
synchronized (db) {
if (key == null) {
throw new KeyIsNullException();
}
HashMap<Object , Object> hash= new HashMap<>();
if (isInCache(key, cacheTime)) {
keyValue[] array = db.getObjectArray(findTimeBasedKey(key), keyValue.class);
for(keyValue s : array)
hash.put(s.getKey() , s.getKey());
} else {
throw new MissingDataException();
}
return hash;
}
}




protected List<String> getStringListValue(String key, Long cacheTime) throws SnappydbException {
synchronized (db) {
if (key == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.snappydb.DB;

import java.util.HashMap;
import java.util.List;

import rx.Observable;
Expand Down Expand Up @@ -39,7 +40,7 @@ public Observable<Boolean> exists(final String key) {
@Override
public Observable<Boolean> call() {
try {
return Observable.just(exsts(key));
return Observable.just(isExists(key));
} catch (Exception e) {
return Observable.error(e);
}
Expand Down Expand Up @@ -224,6 +225,39 @@ public Observable<List<String>> call() {
});
}


public Observable<HashMap<Object , Object>> setHashMapList(final String key, final HashMap<Object , Object> value) {
return Observable.defer(new Func0<Observable<HashMap<Object , Object>>>() {
@Override
public Observable<HashMap<Object , Object>> call() {
try {
setHashMap(key, value , false);
return Observable.just(value);
} catch (Exception e) {
return Observable.error(e);
}
}
});
}

public Observable<HashMap<Object , Object>> getHashMapList(final String key, final Long cacheTime) {
return Observable.defer(new Func0<Observable<HashMap<Object , Object>>>() {
@Override
public Observable<HashMap<Object , Object>> call() {
try {
return Observable.just(getHashMap(key, cacheTime));
} catch (Exception e) {
return Observable.error(e);
}
}
});
}






public Observable<List> setList(final String key, final List value) {
return setList(key, value, false);
}
Expand Down Expand Up @@ -277,6 +311,8 @@ public Observable<T> call() {
});
}



public <T> Observable<T> getObject(String key, Class<T> selectedClass) {
return getObject(key, null, selectedClass);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.supercharge.rxsnappy.objects;

import java.io.Serializable;

/**
* Created by omri on 15/09/2016.
*/
public class keyValue implements Serializable {

public keyValue(){}
private Object key;
private Object value;

public Object getKey() {
return key;
}

public void setKey(Object key) {
this.key = key;
}

public Object getValue() {
return value;
}

public void setValue(Object value) {
this.value = value;
}

public keyValue(Object key, Object value) {
this.key = key;
this.value = value;
}
}