List of usage examples for java.math BigInteger intValue
public int intValue()
From source file:com.acmemotors.obd2.OBD2Controller.java
protected int decodeEngineLoad(String response) { String[] respsonseLines = response.split("\n"); StringBuilder pidString = new StringBuilder(); String[] elements = respsonseLines[1].split(" "); BigInteger a = new BigInteger(elements[7], 16); return a.intValue() * 100 / 255; }
From source file:de.fischer.thotti.core.runner.NDRunner.java
protected FindResult findInstanceByID(TestSuite testSuite, int executionID) { if (testSuite == null) throw new NullPointerException(); // Remember, the execution id is unique within a given test suite // but only for he given suite. Generating the same tests suite // from the same annotations might result in different IDs TestInstanceType instance = null;/*from w w w. j a v a 2 s . c om*/ NonDistributedTestType testOfInstance = null; NonDistributedTestsType tests = testSuite.getNonDistributedTests(); for (NonDistributedTestType test : tests.getNonDistributedTests()) { for (TestInstanceType current : test.getTestInstances()) { BigInteger id = current.getExecutionID(); if (id.intValue() == executionID) { instance = current; testOfInstance = test; break; } } } if (instance == null) { throw new ThottiRuntimeException( "Internal error while running in " + "slave mode: No test instace " + executionID + " found."); } return new FindResult(testOfInstance, instance); }
From source file:gov.nih.nci.cabig.caaers.grid.service.StudyServiceImpl.java
public gov.nih.nci.cabig.caaers.grid.beans.StudyParticipantAssignment assignParticipant( gov.nih.nci.cabig.caaers.grid.beans.Study studyBean, gov.nih.nci.cabig.caaers.grid.beans.Participant participantBean, gov.nih.nci.cabig.caaers.grid.beans.Site siteBean) throws RemoteException { gov.nih.nci.cabig.caaers.grid.beans.StudyParticipantAssignment assignmentBean = new gov.nih.nci.cabig.caaers.grid.beans.StudyParticipantAssignment(); try {//from ww w. j a v a 2s. co m BigInteger studyId = studyBean.getId(); if (studyId == null) { throw new IllegalArgumentException("Study ID is null"); } BigInteger siteId = siteBean.getId(); if (siteId == null) { throw new IllegalArgumentException("Site ID is null"); } Study study = new Study(); study.setId(studyId.intValue()); Organization site = new Organization(); site.setId(siteId.intValue()); BigInteger participantId = participantBean.getId(); Participant participant = new Participant(); if (participantId != null) { participant.setId(participantId.intValue()); } else { participant.setFirstName(participantBean.getFirstName()); participant.setMiddleName(participantBean.getMiddleName()); participant.setLastName(participantBean.getLastName()); participant.setMaidenName(participantBean.getMaidenName()); participant.setInstitution(participantBean.getInstitution()); participant.setInstitutionalPatientNumber(participantBean.getInstitutionalPatientNumber()); participant.setDateOfBirth(participantBean.getDateOfBirth()); participant.setRace(participantBean.getRace()); participant.setGender(participantBean.getGender()); } StudyService svc = (StudyService) this.ctx.getBean(STUDY_SERVICE_BEAN_NAME); StudyParticipantAssignment assignment = svc.assignParticipant(study, participant, site, ""); //TODO: Switch to using grid id when that is reader assignmentBean.setId(BigInteger.valueOf(assignment.getId().longValue())); } catch (Exception ex) { String msg = "Error assigning participant: " + ex.getMessage(); logger.debug(msg, ex); throw new RuntimeException(msg, ex); } return assignmentBean; }
From source file:com.acmemotors.obd2.OBD2Controller.java
protected int decodeRunningTime(String response) { String[] respsonseLines = response.split("\n"); StringBuilder pidString = new StringBuilder(); String[] elements = respsonseLines[1].split(" "); BigInteger a = new BigInteger(elements[7], 16); BigInteger b = new BigInteger(elements[8], 16); return (a.intValue() * 256) + b.intValue(); }
From source file:com.acmemotors.obd2.OBD2Controller.java
private double decodeMafRate(String response) { String[] respsonseLines = response.split("\n"); StringBuilder pidString = new StringBuilder(); String[] elements = respsonseLines[1].split(" "); BigInteger a = new BigInteger(elements[7], 16); BigInteger b = new BigInteger(elements[8], 16); return ((a.intValue() * 256) + b.intValue()) / 100; }
From source file:com.acmemotors.obd2.OBD2Controller.java
/** * Formula taken from http://en.wikipedia.org/wiki/OBD-II_PIDs * @param response Full response for the 01 0C request * @return int value of the current RPMs *///from w w w . j a va 2s .c om protected int decodeRPM(String response) { String[] respsonseLines = response.split("\n"); StringBuilder pidString = new StringBuilder(); String[] elements = respsonseLines[1].split(" "); BigInteger a = new BigInteger(elements[7], 16); BigInteger b = new BigInteger(elements[8], 16); return ((a.intValue() * 256) + b.intValue()) / 4; }
From source file:net.sf.cb2xml.convert.MainframeToXml.java
private Element convertNode(Element element, Context context) throws JCopybookUnmarshallException { String text = null;/* ww w.j av a 2 s . c o m*/ String resultElementName = element.getAttribute("name").replaceAll("[^0-9^A-Z\\-]+", "||"); Element resultElement = resultDocument.createElement(resultElementName); try { int length = Integer.parseInt(element.getAttribute("display-length")); int childElementCount = 0; NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { Element childElement = (Element) node; if (!childElement.getAttribute("level").equals("88") && "item".equals(childElement.getNodeName())) { childElementCount++; if (childElement.hasAttribute("occurs")) { boolean dependOn = StringUtils.isNotEmpty(childElement.getAttribute("depending-on")); BigInteger count = numerics.get(childElement.getAttribute("depending-on")); int childOccurs = Integer.parseInt(childElement.getAttribute("occurs")); if (dependOn && count != null) { childOccurs = count.intValue(); } for (int j = 0; j < childOccurs; j++) { resultElement.appendChild(convertNode(childElement, context)); } } else { if (!"item".equals(childElement.getAttribute("name"))) resultElement.appendChild(convertNode(childElement, context)); } } } } if (childElementCount == 0 && !"true".equals(element.getAttribute("redefined"))) { text = mainframeBuffer.substring(context.offset, context.offset + length); if ("true".equals(element.getAttribute("numeric"))) { String textForNumeric = text.trim(); if (textForNumeric.isEmpty()) { textForNumeric = "true".equals(element.getAttribute("signed")) ? "{" : "0"; } textForNumeric = removeLeftZeros(textForNumeric); if ("true".equals(element.getAttribute("signed"))) { String originalDigit = textForNumeric.substring(textForNumeric.length() - 1, textForNumeric.length()); String digit = SignedNumericMappingTable.decodeMap.get(originalDigit); if (digit == null) throw new Exception("bad signed numeric last digit: " + originalDigit); textForNumeric = (digit.startsWith("-") ? "-" : "") + textForNumeric.substring(0, textForNumeric.length() - 1) + (digit.length() == 2 ? digit.substring(1) : digit); } if (textForNumeric.length() == 0) text = "0"; else if (StringUtils.isNotEmpty(element.getAttribute("scale"))) { int scale = Integer.parseInt(element.getAttribute("scale")); textForNumeric = getDecimalValue(textForNumeric, scale); } else numerics.put(resultElementName, new BigInteger(textForNumeric)); text = textForNumeric; } context.offset += length; Text textNode = resultDocument.createTextNode(text.trim()); resultElement.appendChild(textNode); } return resultElement; } catch (Exception e) { if (e instanceof JCopybookUnmarshallException) throw (JCopybookUnmarshallException) e; throw new JCopybookUnmarshallException( String.format("can't parse copybook string on element '%s' and text '%s'", resultElementName, text), e, mainframeBuffer, XmlUtils.domToString(resultElement.getOwnerDocument()).toString(), resultElementName, text, element.getOwnerDocument()); } }
From source file:com.emergya.siradmin.invest.InvestmentUpdater.java
private Integer getAsInteger(BigInteger source) { return source != null ? source.intValue() : null; }
From source file:org.openremote.controller.protocol.http.HttpGetCommand.java
private int resolveRangeMinimum(String min) { if (min == null || min.equals("")) { return Integer.MIN_VALUE; }/* ww w . ja v a 2s. c o m*/ try { BigInteger minimum = new BigInteger(min); BigInteger integerMin = new BigInteger(Integer.toString(Integer.MIN_VALUE)); if (minimum.compareTo(integerMin) < 0) { return Integer.MIN_VALUE; } else { return minimum.intValue(); } } catch (NumberFormatException e) { // TODO : log return Integer.MIN_VALUE; } }
From source file:org.openremote.controller.protocol.http.HttpGetCommand.java
private int resolveRangeMaximum(String max) { if (max == null || max.equals("")) { return Integer.MAX_VALUE; }// w w w . j a v a 2 s . c om try { BigInteger maximum = new BigInteger(max); BigInteger integerMax = new BigInteger(Integer.toString(Integer.MAX_VALUE)); if (maximum.compareTo(integerMax) > 0) { return Integer.MAX_VALUE; } else { return maximum.intValue(); } } catch (NumberFormatException e) { // TODO : log return Integer.MAX_VALUE; } }