Example usage for java.lang Long intValue

List of usage examples for java.lang Long intValue

Introduction

In this page you can find the example usage for java.lang Long intValue.

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Long as an int after a narrowing primitive conversion.

Usage

From source file:com.shuffle.mock.MockCoin.java

public static MockCoin fromJSON(Reader jsonObject) throws IllegalArgumentException {

    JSONObject json = null;//from ww  w  .j a va 2  s  .c om
    JSONArray outputs = null;
    JSONArray transactions = null;
    try {
        json = (JSONObject) JSONValue.parse(jsonObject);
        if (json == null) {
            throw new IllegalArgumentException("could not parse json object.");
        }

        outputs = (JSONArray) json.get("outputs");
        if (outputs == null) {
            throw new IllegalArgumentException("Missing field \"outputs\".");
        }

        transactions = (JSONArray) json.get("transactions");
        if (transactions == null) {
            throw new IllegalArgumentException("Missing field \"transactions\".");
        }
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("could not parse json object.");
    }

    MockCoin mock = new MockCoin();

    Map<Long, Output> outList = new HashMap<>();
    for (int i = 1; i <= outputs.size(); i++) {
        JSONObject o = null;
        try {
            o = (JSONObject) outputs.get(i - 1);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Could not read " + outputs.get(i - 1) + " as json object.");
        }

        Object address = o.get("address");
        Long amount = (Long) o.get("amount");
        if (address == null) {
            throw new IllegalArgumentException("Output missing field \"address\".");
        }
        if (amount == null) {
            throw new IllegalArgumentException("Output missing field \"amount\".");
        }

        Output bo = null;
        if (address instanceof String) {
            bo = new Output(new MockAddress((String) address), amount);
        } else if (address instanceof Long) {
            bo = new Output(new MockAddress((Long) address), amount);
        } else {
            throw new IllegalArgumentException("Could not read " + address + " as address");
        }

        outList.put((long) i, bo);
        mock.blockchain.put(bo.address, bo);
    }

    for (Object t : transactions) {

        JSONObject trans = (JSONObject) t;
        JSONArray in = (JSONArray) trans.get("inputs");
        JSONArray out = (JSONArray) trans.get("outputs");
        List<Output> tout = new LinkedList<>();
        List<Output> tin = new LinkedList<>();

        for (Object i : in) {
            Output o = outList.get(i);
            if (o == null) {
                throw new IllegalArgumentException("Missing output " + o);
            }
            tin.add(outList.get(i));
        }

        for (Object i : out) {
            Output o = outList.get(i);
            if (o == null) {
                throw new IllegalArgumentException("Missing output " + o);
            }
            tout.add(outList.get(i));
        }

        MockTransaction tr;
        Long z = null;
        Object zz = trans.get("z");
        try {

            if (zz == null) {
                tr = new MockTransaction(tin, tout, mock);
            } else {
                z = (Long) zz;
                tr = new MockTransaction(tin, tout, z.intValue(), mock, new HashMap<Output, VerificationKey>());
            }
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Could not read z value " + zz + " as long.");
        }
    }

    return mock;
}

From source file:de.cosmocode.collections.utility.Convert.java

private static <E extends Enum<E>> E doIntoEnum(Object value, Class<E> enumType) {
    Preconditions.checkNotNull(enumType, "EnumType");
    if (enumType.isInstance(value))
        return enumType.cast(value);
    final Long ordinal = doIntoLong(value);
    if (ordinal == null) {
        final String name = doIntoString(value);
        if (name == null)
            return null;
        try {//from  ww w  .  j a v  a 2 s . c om
            return Enum.valueOf(enumType, name.toUpperCase());
        } catch (IllegalArgumentException e) {
            return null;
        }
    } else {
        try {
            return Enums.valueOf(enumType, ordinal.intValue());
        } catch (IndexOutOfBoundsException e) {
            return null;
        }
    }
}

From source file:org.spring.data.gemfire.app.main.SpringGemFireClient.java

int intValue(Long value) {
    return value.intValue();
}

From source file:cn.itcast.bbs.dao.ReplyDao.java

public int countReplyByTopic(int id) throws SQLException {
    QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource());
    String sql = "select count(*) from reply where topic_id = ?;";
    Long cnt = runner.query(sql, new ScalarHandler(), id);
    return cnt.intValue();
}

From source file:io.druid.benchmark.datagen.RealRoundingDistribution.java

@Override
public int sample() {
    double randomVal = realDist.sample();
    Long longVal = Math.round(randomVal);
    return longVal.intValue();
}

From source file:reviewbot.service.ReviewService.java

@Override
public ReviewDTO readOne(Long id) {
    return unwrap(_reviewRepository.readOne(id.intValue()));
}

From source file:reviewbot.service.UserService.java

@Override
public UserDTO readOne(Long id) {
    return unwrap(_userRepository.readOne(id.intValue()));
}

From source file:com.epam.ta.reportportal.database.dao.FixtureTest.java

@Test
public void checkUsers() {
    Long countOfImportedUsers = userRepository.count();
    Assert.assertThat(countOfImportedUsers.intValue(), greaterThan(0));
}

From source file:com.olabini.jescov.generators.JsonIngester.java

public CoverageData ingest(Reader reader) throws IOException {
    Map<String, Object> input = (Map<String, Object>) JSONValue.parse(reader);
    List<FileCoverage> fcs = new ArrayList<FileCoverage>();
    for (Map.Entry<String, Object> me : input.entrySet()) {
        Collection<LineCoverage> lcs = new ArrayList<LineCoverage>();
        Collection<BranchCoverage> bcs = new ArrayList<BranchCoverage>();

        List<List<Object>> lines = (List<List<Object>>) me.getValue();
        for (List<Object> lineInfo : lines) {
            int lineNumber = ((Long) lineInfo.get(0)).intValue();
            int hits = ((Long) lineInfo.get(1)).intValue();
            List<List<Object>> branches = (List<List<Object>>) lineInfo.get(2);
            lcs.add(new LineCoverage(lineNumber, hits));
            for (List<Object> bc : branches) {
                int branchId = ((Long) bc.get(0)).intValue();
                List<Long> actualCoverage = (List<Long>) bc.get(1);
                int[] branchHits = new int[actualCoverage.size()];
                int index = 0;
                for (Long hit : actualCoverage) {
                    branchHits[index++] = hit.intValue();
                }/*from   w  w w.ja  v a2  s. c  om*/
                bcs.add(new BranchCoverage(lineNumber, branchId, branchHits));
            }
        }

        fcs.add(new FileCoverage(me.getKey(), lcs, bcs));
    }
    return new CoverageData(fcs);
}

From source file:com.epam.ta.reportportal.database.dao.FixtureTest.java

@Test
public void checkProjects() {
    Long countOfImportedProjects = projectRepository.count();
    Assert.assertThat(countOfImportedProjects.intValue(), greaterThan(0));
}