package org.ndexbio.common.helpers;

import com.orientechnologies.orient.core.id.OClusterPositionFactory;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/******************************************************************************
* Converts between RIDs and JIDs. JIDs are used on the web site as a
* workaround for the limitations of limited characters that can be displayed
* in URLs. RIDs are the true IDs used by OrientDB.
******************************************************************************/
public class IdConverter
{
    /**************************************************************************
    * Converts a JID to a RID.
    * 
    * @param Jid
    *            The JID.
    * @throws IllegalArgumentException
    *            The JID isn't a valid JID.
    * @return The JID converted to a RID.
    **************************************************************************/
    public static ORID toRid(String Jid) throws IllegalArgumentException
    {
        final Matcher m = Pattern.compile("^C(\\d*)R(\\d*)$").matcher(Jid.trim());

        if (m.matches())
            return new ORecordId(Integer.valueOf(m.group(1)), OClusterPositionFactory.INSTANCE.valueOf(m.group(2)));
        else
            throw new IllegalArgumentException(Jid + " is not a valid JID.");
    }

    /**************************************************************************
    * Converts a RID to a JID.
    * 
    * @param Rid
    *            The RID.
    * @return The RID converted to a JID.
    **************************************************************************/
    public static String toJid(ORID Rid)
    {
        return Rid.toString().replace("#", "C").replace(":", "R");
    }
}

@@ -204,16 +204,17 @@
 cordId;%0A
+%0A
 import j
@@ -350,16 +350,17 @@
 *******%0A
+ 
 * Conver
@@ -419,18 +419,16 @@
 ite as a
-%0A*
  workaro
@@ -430,16 +430,19 @@
 rkaround
+%0A *
  for the
@@ -497,18 +497,16 @@
 isplayed
-%0A*
  in URLs
@@ -511,16 +511,19 @@
 Ls. RIDs
+%0A *
  are the
@@ -550,16 +550,17 @@
 ientDB.%0A
+ 
 ********
@@ -659,15 +659,12 @@
 rter
-%0A%7B%0A    
+ %7B%0A%09
 /***
@@ -727,35 +727,33 @@
 ***************%0A
-   
+%09
  * Converts a JI
@@ -760,34 +760,30 @@
 D to a RID.%0A
-   
+%09
  * %0A
-   
+%09
  * @param Ji
@@ -784,19 +784,17 @@
 ram Jid%0A
-   
+%09
  *      
@@ -804,27 +804,25 @@
    The JID.%0A
-   
+%09
  * @throws I
@@ -845,21 +845,20 @@
 ception%0A
-    *
+%09 * 
         
@@ -884,27 +884,25 @@
  valid JID.%0A
-   
+%09
  * @return T
@@ -924,27 +924,25 @@
 d to a RID.%0A
-   
+%09
  ***********
@@ -998,36 +998,33 @@
 **************/%0A
-    
+%09
 public static OR
@@ -1075,31 +1075,21 @@
 xception
-%0A    %7B%0A        
+ %7B%0A%09%09
 final Ma
@@ -1142,16 +1142,21 @@
 matcher(
+%0A%09%09%09%09
 Jid.trim
@@ -1161,24 +1161,18 @@
 im());%0A%0A
-        
+%09%09
 if (m.ma
@@ -1180,28 +1180,19 @@
 ches())%0A
-            
+%09%09%09
 return n
@@ -1232,17 +1232,22 @@
 oup(1)),
- 
+%0A%09%09%09%09%09
 OCluster
@@ -1297,33 +1297,18 @@
 ));%0A
-        else%0A            
+%09%09else%0A%09%09%09
 thro
@@ -1373,19 +1373,13 @@
 %22);%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 /***
@@ -1450,19 +1450,17 @@
 *******%0A
-   
+%09
  * Conve
@@ -1483,18 +1483,14 @@
 ID.%0A
-   
+%09
  * %0A
-   
+%09
  * @
@@ -1499,19 +1499,17 @@
 ram Rid%0A
-   
+%09
  *      
@@ -1523,19 +1523,17 @@
 he RID.%0A
-   
+%09
  * @retu
@@ -1563,19 +1563,17 @@
  a JID.%0A
-   
+%09
  *******
@@ -1641,20 +1641,17 @@
 ******/%0A
-    
+%09
 public s
@@ -1682,23 +1682,13 @@
 Rid)
-%0A    %7B%0A        
+ %7B%0A%09%09
 retu
@@ -1742,16 +1742,294 @@
 , %22R%22);%0A
-    
+%09%7D%0A%0A%09public static String toRidCsv(String%5B%5D strings) %7B%0A%09%09String resultString = %22%22;%0A%09%09for (final String string : strings) %7B%0A%09%09%09ORID rid = toRid(string);%0A%09%09%09resultString += rid + %22,%22;%0A%09%09%7D%0A%09%09resultString = resultString.substring(0, resultString.length() - 1);%0A%09%09return resultString;%0A%0A%09
 %7D%0A%7D%0A

Add a method for converting lists of JIDs to csv strings or RIDs (common case for constructing queries)