Java Code Examples for com.alibaba.fastjson.JSONArray#getInteger()

The following examples show how to use com.alibaba.fastjson.JSONArray#getInteger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WXParallax.java    From incubator-weex-playground with Apache License 2.0 6 votes vote down vote up
private void initBackgroundColor(Object obj) {
  if (obj == null)
    return;

  if (obj instanceof JSONObject) {
    mBackgroundColor = new BackgroundColorCreator();
    JSONObject object = (JSONObject) obj;

    JSONArray in = object.getJSONArray("in");
    mBackgroundColor.input = new int[in.size()];
    for (int i = 0; i < in.size(); i++) {
      mBackgroundColor.input[i] = in.getInteger(i);
    }

    JSONArray out = object.getJSONArray("out");
    mBackgroundColor.output = new int[out.size()];
    for (int i = 0; i < out.size(); i++) {
      String colorStr = out.getString(i);
      mBackgroundColor.output[i] = WXResourceUtils.getColor(colorStr);
    }
  }
}
 
Example 2
Source File: Precision.java    From GOAi with GNU Affero General Public License v3.0 5 votes vote down vote up
static Precision of(JSONArray r) {
    return new Precision(
            Util.decode(r.getString(0)),
            r.getString(1),
            r.getInteger(2),
            r.getInteger(3),
            r.getBigDecimal(4),
            r.getBigDecimal(5),
            r.getBigDecimal(6),
            r.getBigDecimal(7),
            r.getBigDecimal(8),
            r.getBigDecimal(9));
}
 
Example 3
Source File: TopicListener.java    From kafka-monitor with Apache License 2.0 5 votes vote down vote up
@Override
public void childEvent(CuratorFramework curator, TreeCacheEvent event) throws Exception {
    ChildData data = event.getData();
    if (data != null) {
        if (event.getType() == NODE_ADDED) {

        }
        String path = data.getPath();
        //判断是否为topics节点
        if (path.contains(String.format("%s/",ZkUtils.BrokerTopicsPath())) && (!path.contains("partitions"))) {
            Topic topic = JSONObject.parseObject(data.getData(), Topic.class);
            String name = path.substring(path.lastIndexOf("/") + 1, path.length());
            topic.setName(name);

            int[] tPartiyions = topic.getPartitions().keySet().stream().mapToInt((t) -> Integer.valueOf(t)).sorted().toArray();
            for (Object key : tPartiyions
                    ) {
                String partitionPath = String.format("%s/partitions/%s/state", path, key);
                String state = new String(curator.getData().forPath(partitionPath));
                Partition partition = JSONObject.parseObject(state, Partition.class);
                JSONArray replicas = topic.getPartitions().getJSONArray(String.valueOf(key));
                int[] replicasArray = new int[replicas.size()];
                for (int i = 0; i <
                        replicas.size(); i++) {
                    replicasArray[i] = replicas.getInteger(i);
                }
                partition.setReplicasArray(replicasArray);

                topic.getPartitionMap().put((Integer) key, partition);
            }
            topicList.add(topic);
        }
    }
}
 
Example 4
Source File: HttpServer.java    From meshchain with Apache License 2.0 5 votes vote down vote up
/**
 * @desc get user info
 * @param uid
 */
public static UserInfo queryUserInfo(WCS wcs, String uid) throws Exception {
    Web3j web3j = wcs.getWeb3j();

    if (web3j == null) {
        logger.error("queryUserInfo web3j is null");
        return null;
    }

    JSONObject jsonObject = JSON.parseObject("{}");
    jsonObject.put("contract", CONTRACT_NAME);
    jsonObject.put("func", CONTRACT_METHOD_USER_INFO);
    jsonObject.put("version", "");

    List<Object> params = new ArrayList<>();
    params.add(uid);

    jsonObject.put("params", params);

    String data = Numeric.toHexString(jsonObject.toJSONString().getBytes());

    EthCall ethCall = web3j.ethCall(Transaction.createEthCallTransaction(null, null, data, BigInteger.ZERO, false), DefaultBlockParameterName.LATEST).sendAsync().get();
    String value = ethCall.getResult();
    JSONArray array = JSON.parseArray(value);
    if (array.size() != 4) {
        logger.error("queryUserInfo array size 0");
        return null;
    }

    int availAssets = array.getInteger(0);
    int unAvailAssets = array.getInteger(1);
    int identity = array.getInteger(2);
    String name = array.getString(3);

    UserInfo userInfo = new UserInfo(uid, availAssets, unAvailAssets, identity, name);
    return userInfo;

}
 
Example 5
Source File: LindenFieldCacheImpl.java    From linden with Apache License 2.0 5 votes vote down vote up
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
    throws IOException {
  int maxDoc = reader.maxDoc();

  final int[][] matrix = new int[maxDoc][];
  BinaryDocValues valuesIn = reader.getBinaryDocValues(key.field);
  if (valuesIn == null) {
    for (int i = 0; i < maxDoc; ++i) {
      matrix[i] = new int[0];
    }
    return new IntList(matrix);
  }
  for (int i = 0; i < maxDoc; ++i) {
    String str = valuesIn.get(i).utf8ToString();
    if (StringUtils.isEmpty(str)) {
      matrix[i] = new int[0];
      continue;
    }
    JSONArray array = JSON.parseArray(str);
    matrix[i] = new int[array.size()];
    for (int j = 0; j < array.size(); ++j) {
      matrix[i][j] = array.getInteger(j);
    }
  }
  return new IntList(matrix);
}
 
Example 6
Source File: LindenFieldCacheImpl.java    From linden with Apache License 2.0 5 votes vote down vote up
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
    throws IOException {
  int maxDoc = reader.maxDoc();

  final long[][] matrix = new long[maxDoc][];
  BinaryDocValues valuesIn = reader.getBinaryDocValues(key.field);
  if (valuesIn == null) {
    for (int i = 0; i < maxDoc; ++i) {
      matrix[i] = new long[0];
    }
    return new LongList(matrix);
  }
  for (int i = 0; i < maxDoc; ++i) {
    String str = valuesIn.get(i).utf8ToString();
    if (StringUtils.isEmpty(str)) {
      matrix[i] = new long[0];
      continue;
    }
    JSONArray array = JSON.parseArray(str);
    matrix[i] = new long[array.size()];
    for (int j = 0; j < array.size(); ++j) {
      matrix[i][j] = array.getInteger(j);
    }
  }
  return new LongList(matrix);
}
 
Example 7
Source File: DeployContract.java    From meshchain with Apache License 2.0 4 votes vote down vote up
/**
 * @desc get user info
 * @param uid
 */
public static UserInfo queryUserInfo(String uid) throws Exception {

    byte[] uidBytes = Arrays.copyOf(uid.getBytes(), 32);
    Bytes32 uidByte32 = new Bytes32(uidBytes);

    RouteManager routeManager = RouteManager.load(Config.getConfig().getRouteAddress(), routeWCS.getWeb3j(), routeWCS.getCredentials(), gasPrice, gasLimit);

    List<Type> typeList = routeManager.getRoute(uidByte32).get();
    if (typeList.size() != 2) {
        return null;
    }

    Boolean existed = (Boolean)typeList.get(0).getValue();
    BigInteger setId = (BigInteger)typeList.get(1).getValue();

    if (!existed) {
        return null;
    }

    Future<Utf8String> addressFuture = routeManager.m_setNames(new Uint256(setId));
    String setName = addressFuture.get().toString();


    JSONObject jsonObject = JSON.parseObject("{}");
    jsonObject.put("contract", "Meshchain");
    jsonObject.put("func", "getUserInfo");
    jsonObject.put("version", "");

    List<Object> params = new ArrayList<>();
    params.add(uid);
    jsonObject.put("params", params);

    Web3j web3j = nameSetServiceMap.get(setName).getWeb3j();

    if (web3j == null) {
        throw new Exception("bad chain name");
    }

    String data = Numeric.toHexString(jsonObject.toJSONString().getBytes());

    EthCall ethCall = web3j.ethCall(Transaction.createEthCallTransaction(null, null, data, BigInteger.ZERO, false), DefaultBlockParameterName.LATEST).sendAsync().get();
    String value = ethCall.getResult();
    JSONArray array = JSON.parseArray(value);
    if (array.size() == 0) {
        throw new Exception("array size = 0");
    }

    int availAssets = array.getInteger(0);
    int unAvailAssets = array.getInteger(1);
    int identity = array.getInteger(2);
    String name = array.getString(3);

    UserInfo userInfo = new UserInfo(uid, availAssets, unAvailAssets, identity, name);
    System.out.printf("uid:%s,set id:%d\n", uid, setId.intValue());
    return userInfo;

}
 
Example 8
Source File: HttpServer.java    From meshchain with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param wcs
 * @param jsonMerkleProof
 * @return
 * @throws ExecutionException
 * @throws InterruptedException
 */
public static boolean verifySign(WCS wcs, JSONObject jsonMerkleProof) throws ExecutionException, InterruptedException {
    String hash = jsonMerkleProof.getString("hash");
    JSONArray pubArr = jsonMerkleProof.getJSONArray("pubs");
    StringBuilder pubSb = new StringBuilder();
    for(Object pub : pubArr) {
        pubSb.append(pub.toString()).append(";");
    }

    String pubStr = "";
    if (pubSb.length() > 0) {
        pubStr = pubSb.substring(0, pubSb.length() - 1);
    }

    JSONArray signArr = jsonMerkleProof.getJSONArray("signs");
    StringBuilder signSb = new StringBuilder();
    StringBuilder idxSb = new StringBuilder();

    for(int i = 0; i < signArr.size(); i++) {
        JSONObject idxAndsign = signArr.getJSONObject(i);
        signSb.append(idxAndsign.getString("sign").toString()).append(";");
        idxSb.append(idxAndsign.getString("idx").toString()).append(";");
    }

    String signStr = "";
    String idxStr = "";
    if (signSb.length() > 0) {
        signStr = signSb.substring(0, signSb.length() - 1);
    }

    if (idxSb.length() > 0) {
        idxStr = idxSb.substring(0, idxSb.length() - 1);
    }

    List<Object> signPubListParams = new ArrayList<>();
    signPubListParams.add(hash);
    signPubListParams.add(pubStr);
    signPubListParams.add(signStr);
    signPubListParams.add(idxStr);

    JSONObject jsonObject = JSON.parseObject("{}");
    jsonObject.put("contract", CONTRACT_NAME);
    jsonObject.put("func", "verifySign");
    jsonObject.put("version", "");
    jsonObject.put("params", signPubListParams);

    String data = Numeric.toHexString(jsonObject.toJSONString().getBytes());

    EthCall ethCall = wcs.getWeb3j().ethCall(Transaction.createEthCallTransaction(null, null, data, BigInteger.ZERO, false), DefaultBlockParameterName.LATEST).sendAsync().get();
    String value = ethCall.getResult();
    JSONArray array = JSON.parseArray(value);
    if (array.size() == 0) {
        logger.warn("verifySign get array size is 0");
        return false;
    }

    int code = array.getInteger(0);
    return code == 0 ? true : false;

}
 
Example 9
Source File: HttpServer.java    From meshchain with Apache License 2.0 4 votes vote down vote up
/**
 * @desc get hot account or sub hot account info
 * @param name account name
 * @param sub true: sub hot account false:
 */
public static UserInfo getAccountInfoByName(WCS wcs, String name, boolean sub) throws Exception {
    Web3j web3j = wcs.getWeb3j();

    if (web3j == null) {
        logger.error("getHotAccountInfo web3j is null");
        return null;
    }

    JSONObject jsonObject = JSON.parseObject("{}");
    jsonObject.put("contract", CONTRACT_NAME);
    if (!sub) {
        jsonObject.put("func", CONTRACT_METHOD_HOT_ACCOUNT_INFO);
    } else {
        jsonObject.put("func", CONTRACT_METHOD_SUB_HOT_ACCOUNT_INFO);
    }

    jsonObject.put("version", "");

    List<Object> params = new ArrayList<>();
    params.add(name);

    jsonObject.put("params", params);

    String data = Numeric.toHexString(jsonObject.toJSONString().getBytes());

    EthCall ethCall = web3j.ethCall(Transaction.createEthCallTransaction(null, null, data, BigInteger.ZERO, false), DefaultBlockParameterName.LATEST).sendAsync().get();
    String value = ethCall.getResult();
    JSONArray array = JSON.parseArray(value);
    if (array.size() == 0) {
        logger.error("getHotAccountInfo array size 0");
        return null;
    }

    String uid = array.getString(0);
    int availAssets = array.getInteger(1);
    int unAvailAssets = array.getInteger(2);
    int identity = array.getInteger(3);

    UserInfo userInfo = new UserInfo(uid, availAssets, unAvailAssets, identity, name);
    return userInfo;

}
 
Example 10
Source File: Actions.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public static Action get(String actionName,JSONArray args){
  switch (actionName) {
    case CREATE_BODY:
      if (args == null) {
        return null;
      }
      return new CreateBodyAction(args.getJSONObject(0));
    case UPDATE_ATTRS:
      if (args == null) {
        return null;
      }
      return new UpdateAttributeAction(args.getString(0),args.getJSONObject(1));
    case UPDATE_STYLE:
      if (args == null) {
        return null;
      }
      return new UpdateStyleAction(args.getString(0),args.getJSONObject(1));
    case REMOVE_ELEMENT:
      if (args == null) {
        return null;
      }
      return new RemoveElementAction(args.getString(0));
    case ADD_ELEMENT:
      if (args == null) {
        return null;
      }
      return new AddElementAction(args.getJSONObject(1),args.getString(0),args.getInteger(2));
    case MOVE_ELEMENT:
      if (args == null) {
        return null;
      }
      return new MoveElementAction(args.getString(0),args.getString(1),args.getInteger(2));
    case ADD_EVENT:
      if (args == null) {
        return null;
      }
      return new AddEventAction(args.getString(0),args.getString(1));
    case REMOVE_EVENT:
      if (args == null) {
        return null;
      }
      return new RemoveEventAction(args.getString(0),args.getString(1));
    case CREATE_FINISH:
      return new CreateFinishAction();
    case REFRESH_FINISH:
      return new RefreshFinishAction();
    case UPDATE_FINISH:
      return new UpdateFinishAction();
    case SCROLL_TO_ELEMENT:
      if (args == null) {
        return null;
      }
      String ref = args.size() >= 1 ? args.getString(0) : null;
      JSONObject options = args.size() >= 2 ? args.getJSONObject(1) : null;
      return new ScrollToElementAction(ref, options);
    case ADD_RULE:
      if (args == null) {
        return null;
      }
      return new AddRuleAction(args.getString(0),args.getJSONObject(1));
    case GET_COMPONENT_RECT:
      if(args == null){
        return null;
      }
      return new GetComponentRectAction(args.getString(0),args.getString(1));
    case INVOKE_METHOD:
      if(args == null){
        return null;
      }
      return new InvokeMethodAction(args.getString(0),args.getString(1),args.getJSONArray(2));
  }

  return null;
}