/** * Decodes a comma encoded String returning element in position i * @param s comma encoded string * @param i position (starts at 0) * @return element in position i of comma encoded string, or null */ public static String commaDecode (String s, int i) { String[] ss = commaDecode(s); int l = ss.length; return i >= 0 && i < l ? ss[i] : null; }
public void setTags(String tags) { ts.clear(); if (tags != null) { for (String t : ISOUtil.commaDecode(tags)) { t = t.trim(); if (t.length() > 0) ts.add(t); } } } public boolean add (String t) {
private static SimpleRC buildRC (String s) { String[] ss = ISOUtil.commaDecode(s); String rc = null; String display = null; if (ss.length > 0) rc = ss[0]; if (ss.length > 1) display = ss[1]; Objects.requireNonNull(rc, "Invalid result code"); return new SimpleRC (rc, display); }
/** * @see org.jpos.iso.ISOUtil#commaEncode(String[]) * @see org.jpos.iso.ISOUtil#commaDecode(String) */ @Test public void testCommaEncodeAndDecode() { assertEquals("error encoding \"\"", "", ISOUtil.commaEncode(new String[] {})); assertEquals("error encoding \"a,b,c\"", "a,b,c", ISOUtil.commaEncode(new String[] { "a", "b", "c" })); assertEquals("error encoding \"\\,,\\\\,c\"", "\\,,\\\\,c", ISOUtil.commaEncode(new String[] { ",", "\\", "c" })); assertArrayEquals("error decoding \"\"", new String[] {}, ISOUtil.commaDecode("")); assertArrayEquals("error decoding \"a,b,c\"", new String[] { "a", "b", "c" }, ISOUtil.commaDecode("a,b,c")); assertArrayEquals("error decoding \"\\,,\\\\,c\"", new String[] { ",", "\\", "c" }, ISOUtil.commaDecode("\\,,\\\\,c")); }
public JESpace(String name, String params) throws SpaceError { super(); try { EnvironmentConfig envConfig = new EnvironmentConfig(); StoreConfig storeConfig = new StoreConfig(); String[] p = ISOUtil.commaDecode(params); String path = p[0]; envConfig.setAllowCreate (true); envConfig.setTransactional(true); envConfig.setLockTimeout(getParam("lock.timeout", p, DEFAULT_LOCK_TIMEOUT), TimeUnit.MILLISECONDS); envConfig.setTxnTimeout(getParam("txn.timeout", p, DEFAULT_TXN_TIMEOUT), TimeUnit.MILLISECONDS); storeConfig.setAllowCreate (true); storeConfig.setTransactional (true); File dir = new File(path); dir.mkdirs(); dbe = new Environment (dir, envConfig); store = new EntityStore (dbe, name, storeConfig); pIndex = store.getPrimaryIndex (Long.class, Ref.class); gcpIndex = store.getPrimaryIndex (Long.class, GCRef.class); sIndex = store.getSecondaryIndex (pIndex, String.class, "key"); gcsIndex = store.getSecondaryIndex (gcpIndex, Long.class, "expires"); gcTask = SpaceFactory.getGCExecutor().scheduleAtFixedRate(this, GC_DELAY, GC_DELAY, TimeUnit.MILLISECONDS); } catch (Exception e) { throw new SpaceError (e); } }