Skip to content

Commit 8540d32

Browse files
committed
Simple Entry
1 parent 8b2967b commit 8540d32

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

src/main/java/picoded/dstack/redis/Redis_DataObjectMap.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import java.util.concurrent.locks.ReentrantReadWriteLock;
1313
import java.util.Collection;
1414
import java.util.Iterator;
15+
import java.util.stream.Collectors;
16+
17+
1518

1619
// JavaCommons imports
1720
import picoded.core.conv.ConvertJSON;
@@ -25,16 +28,22 @@
2528

2629
// Redis imports
2730
import org.redisson.Redisson;
31+
import org.redisson.client.codec.StringCodec;
2832
import org.redisson.api.RedissonClient;
2933
import org.redisson.api.RMap;
3034
import org.redisson.api.RKeys;
3135
import org.redisson.api.RSet;
3236
import org.redisson.api.RSetMultimap;
3337

38+
// Jackson library used
39+
import com.fasterxml.jackson.core.JsonParser;
40+
import com.fasterxml.jackson.databind.ObjectMapper;
41+
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
42+
import com.fasterxml.jackson.core.util.DefaultIndenter;
43+
import com.fasterxml.jackson.databind.MapperFeature;
3444

35-
import org.redisson.client.codec.StringCodec;
45+
import org.hjson.*;
3646

37-
// import org.redisson.api.RSet;
3847

3948
/**
4049
* Redis implementation of DataObjectMap data structure.
@@ -196,24 +205,43 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
196205
* @return null if not exists, else a map with the data
197206
**/
198207
public Map<String, Object> DataObjectRemoteDataMap_get(String _oid) {
199-
208+
200209
Collection<Object> res = redisMap.values(_oid);
201210

202211
Object resObj = res.iterator().next();
203212
if (resObj == null) {
204213
return null;
205214
}
206215

207-
//NEED TO FIND HOW TO CONVERT resObj TO MAP
216+
//Convert resObj to String
217+
String resString = resObj.toString();
218+
//Get rid of {}
219+
resString = resString.substring(1, resString.length() - 1);
220+
221+
//Convert resString to Map
222+
//if duplicate keys show up, the first one encountered takes precedence
223+
//for latest value for a duplicate key then use (a, b)-> b as the merge lambda.)
224+
Map<String, Object> resMap = Arrays.stream(resString.split(","))
225+
.map(str -> str.split("="))
226+
.collect(Collectors.toMap(a -> a[0], a->a[1], (a, b) -> a));
227+
228+
229+
//Convert resObj to String so I can use replace() to make it a valid hjson
230+
//https://github.com/hjson/hjson-java
231+
// String tmpString=resObj.toString();
232+
// tmpString=tmpString.replace('=',':');
233+
// System.out.println(resObj);
234+
// Map<String, String> mapData = GenericConvert.toStringMap(resObj);
235+
// System.out.println(mapData);
208236

209237
Map<String, Object> ret = new HashMap<>();
210238

211239
// Lets iterate through the object
212-
Set<String> fullKeys = resObj.keySet();
240+
Set<String> fullKeys = resMap.keySet();
213241
for (String key : fullKeys) {
214242

215243
// Get the value
216-
Object val = resObj.get(key);
244+
Object val = resMap.get(key);
217245

218246
// Populate the ret map
219247
ret.put(key, val);

0 commit comments

Comments
 (0)