/** * Get the value as boolean, with given default value if it is missed * * @param key name of the parameter * @param defaultValue value to return if missing * @return value found in mao or the defaultValue */ public Boolean getBoolean(String key, Boolean defaultValue) { Boolean res = (Boolean) get(key); return (res == null) ? defaultValue : res; }
@Override public void deserialize(Binder data, BiDeserializer deserializer) throws IOException { hashId = deserializer.deserialize(data.get("hashId")); isChainSubscription = data.getBooleanOrThrow("isChainSubscription"); expiresAt = data.getZonedDateTimeOrThrow("expiresAt"); }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { try {origin = deserializer.deserialize(data.get("origin"));} catch (Exception e) {origin = null;} shortAddress = data.getString("shortAddress",null); longAddress = data.getString("longAddress",null); } }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { this.unsAddresses = deserializer.deserialize(data.getList("addresses", new ArrayList<>())); Object originObj = data.get("origin"); if (originObj != null) this.unsOrigin = deserializer.deserialize(originObj); }
@Override public synchronized void deserialize(Binder data, BiDeserializer ds) throws IOException { payload = TransactionPack.unpack(data.getBinary("payload")); payment = TransactionPack.unpack(data.getBinary("payment")); hashId = ds.deserialize(data.get("hashId")); prepareForNode(); }
/** * Create new permission for change some set of fields. * * @param role allows to permission * @param params is parameters of permission: fields is map of field names and lists of allowed values */ public ModifyDataPermission(Role role, Binder params) { super(FIELD_NAME, role, params); Object fields = params.get("fields"); if (fields != null && fields instanceof Map) { this.fields.putAll((Map) fields); } }
public Double getDouble(String key) { Object x = get(key); if (x instanceof String) return Double.parseDouble((String) x); return new Double((double) x); }
/** * Use {@link #getLongOrThrow(String)} instead. * * @param key * @return */ @Deprecated public long getLong(String key) { Number i = (Number) get(key); if (i == null) throw new IllegalArgumentException("missing long integer parameter"); return i.longValue(); }
public Collection<AbstractKey> getSigningKeys() { ArrayList<AbstractKey> kk = new ArrayList<>(); for(Binder b: signers.values()) kk.add((AbstractKey) b.get("key")); return kk; }
public long getLongOrThrow(String key) { Object x = get(key); Number n = x instanceof Number ? (Number) x : Long.valueOf((String) x); if (n == null) throw new IllegalArgumentException("missing long integer parameter: " + key); return n.longValue(); }
public Integer getInt(String key, Integer defaultValue) { Object o = get(key); if (o == null) return defaultValue; if (o instanceof String) { return Integer.valueOf((String) o); } else if (o instanceof Number) { return ((Number) o).intValue(); } throw new IllegalArgumentException("can't convert to integer: " + o.getClass().getCanonicalName()); }
public <T> List<T> getList(String key, List<T> defaultValue) { Object x = get(key); if (x == null) return defaultValue; return Do.list(x); }
@Override public <T, U extends T> T get(String keyName, U defaultValue) { if(kvStore.containsKey(keyName)) return (T) kvStore.get(keyName); return defaultValue; }
/** * Get object as list, or create empty list if it is empty * * @param key * @param <T> * @return list instance, not null. */ public <T> List<T> getOrCreateList(String key) { Object x = get(key); if (x == null) return new ArrayList<>(); return Do.list(x); }
public Binder getBinder(String key, Binder defaultValue) { HashMap<String, Object> x = (HashMap<String, Object>) get(key); Binder b = null; if (x instanceof Binder) { b = (Binder) x; } else if (x != null) { b = new Binder(x); if (frozen) b.freeze(); } return b == null ? defaultValue : b; }
private Binder extractParams(BasicHTTPService.Request request) { Binder rp = request.getParams(); BasicHTTPService.FileUpload rd = (BasicHTTPService.FileUpload) rp.get("callbackData"); if (rd != null) { byte[] data = rd.getBytes(); return Boss.unpack(data); } return Binder.EMPTY; }
public Binder getOrCreateBinder(String key) { checkNotFrozen(); HashMap<String, Object> x = (HashMap<String, Object>) get(key); Binder b = null; if (x == null) { b = new Binder(); put(key, b); } else b = (x instanceof Binder) ? (Binder) x : new Binder(x); return b; }
@Test public void importWithNameTest() throws Exception { String name = "ImportedContract.unicon"; callMain( "-i", basePath + "contract_to_import.xml", "--output", basePath + name); System.out.println(output); assertTrue (output.indexOf("import from xml ok") >= 0); assertEquals(2, errors.size()); if(errors.size() > 0) { assertEquals(Errors.NOT_SIGNED.name(), errors.get(0).get("code")); } }
@Test public void importFromXMLTest() throws Exception { callMain( "-i", basePath + "contract_to_import.XML"); System.out.println(output); assertTrue (output.indexOf("import from xml ok") >= 0); assertEquals(2, errors.size()); if(errors.size() > 0) { assertEquals(Errors.NOT_SIGNED.name(), errors.get(0).get("code")); } }
@Test public void importFromYamlTest() throws Exception { callMain( "-i", basePath + "contract_to_import.yaml"); System.out.println(output); assertTrue (output.indexOf("import from yaml ok") >= 0); assertEquals(2, errors.size()); if(errors.size() > 0) { assertEquals(Errors.NOT_SIGNED.name(), errors.get(0).get("code")); } }