package redis.clients.jedis;

import java.util.List;

import redis.clients.util.SafeEncoder;

public class ScanResult<T> {
    private String cursor;
    private List<T> results;

    @Deprecated
    /**
     * This method is deprecated due to bug (scan cursor should be unsigned long)
     * And will be removed on next major release
     * @see https://github.com/xetorthio/jedis/issues/531 
     */
    public ScanResult(int cursor, List<T> results) {
	this.cursor = String.valueOf(cursor);
	this.results = results;
    }

    public ScanResult(byte[] cursor, List<T> results) {
	this.cursor = SafeEncoder.encode(cursor);
	this.results = results;
    }
    
    public ScanResult(String cursor, List<T> results) {
	this.cursor = cursor;
	this.results = results;
    }

    @Deprecated
    /**
     * This method is deprecated due to bug (scan cursor should be unsigned long)
     * And will be removed on next major release
     * @see https://github.com/xetorthio/jedis/issues/531
     * @return int(currently), but will be changed to String, so be careful to prepare! 
     */
    public int getCursor() {
	return Integer.parseInt(cursor);
    }

    /**
     * FIXME: This method should be changed to getCursor() on next major release
     */
    public String getStringCursor() {
	return cursor;
    }
    
    public byte[] getBinaryCursor() {
	return SafeEncoder.encode(cursor);
    }
    
    public List<T> getResult() {
	return results;
    }
}

@@ -128,22 +128,22 @@
 private 
-String
+byte%5B%5D
  cursor;
@@ -457,65 +457,46 @@
 this
-.cursor = String.valueOf(cursor);%0A%09this.results =
+(Protocol.toByteArray(cursor),
  results
 ;%0A  
@@ -483,32 +483,33 @@
 cursor), results
+)
 ;%0A    %7D%0A%0A    pub
@@ -523,22 +523,22 @@
 nResult(
-byte%5B%5D
+String
  cursor,
@@ -562,26 +562,17 @@
  %7B%0A%09this
-.cursor = 
+(
 SafeEnco
@@ -593,33 +593,17 @@
 sor)
-;%0A%09this.results =
+,
  results
 ;%0A  
@@ -598,24 +598,25 @@
  results
+)
 ;%0A    %7D%0A
     %0A   
@@ -599,36 +599,32 @@
 results);%0A    %7D%0A
-    
 %0A    public Scan
@@ -622,38 +622,38 @@
 blic ScanResult(
-String
+byte%5B%5D
  cursor, List%3CT%3E
@@ -714,24 +714,28 @@
 ults;%0A    %7D%0A
+    
 %0A    @Deprec
@@ -1087,22 +1087,33 @@
 arseInt(
-c
+getStringC
 ursor
+()
 );%0A    %7D
@@ -1257,22 +1257,42 @@
 %09return 
+SafeEncoder.encode(
 cursor
+)
 ;%0A    %7D%0A
@@ -1346,34 +1346,14 @@
 urn 
-SafeEncoder.encode(
 cursor
-)
 ;%0A  

Change ScanResult's cursor type to byte[]