Example usage for java.math BigInteger valueOf

List of usage examples for java.math BigInteger valueOf

Introduction

In this page you can find the example usage for java.math BigInteger valueOf.

Prototype

private static BigInteger valueOf(int val[]) 

Source Link

Document

Returns a BigInteger with the given two's complement representation.

Usage

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.tasklets.ProjectsListTasklet.java

private void searchAndInsertSubProject(final BigInteger projectId, final Set<BigInteger> projectsId)
        throws RemoteException {

    final String[] idStrList = clientStub.mc_project_get_all_subprojects(userName, password, projectId);
    for (final String idStr : idStrList) {
        final BigInteger subProjectId = BigInteger.valueOf(Long.parseLong(idStr));
        projectsId.add(subProjectId);/*w w  w  . j  a  v a2  s  .c om*/

        insertIntoDb(subProjectId, projectId);
        searchAndInsertSubProject(subProjectId, projectsId);
    }
}

From source file:com.redpill.maven.alfresco.CmisUploadMojo.java

private void uploadFile(String path, File file, Folder destinationFolder) throws FileNotFoundException {
    for (int x = 0; x < 3; x++) {
        try {//  www .  jav a2  s.  c  o  m
            Map<String, Serializable> properties = new HashMap<String, Serializable>();

            properties.put(PropertyIds.NAME, file.getName());
            properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");

            ContentStream contentStream = new ContentStreamImpl(file.getAbsolutePath(),
                    BigInteger.valueOf(file.length()), _mimetype, new FileInputStream(file));

            _session.clear();

            Document document = destinationFolder.createDocument(properties, contentStream,
                    VersioningState.MAJOR);

            getLog().info("Uploaded '" + file.getName() + "' to '" + path + "' with a document id of '"
                    + document.getId() + "'");

            return;
        } catch (Exception ex) {
            getLog().debug("Upload failed, retrying...");
        }
    }
}

From source file:org.n52.youngs.harvest.PoxCswSource.java

private HttpEntity createRequest(long startPosition, long maxRecords) {
    Marshaller m;/*from   w  w w.  j  a v a  2 s.  co  m*/
    try {
        m = getMarshaller();
    } catch (JAXBException e) {
        log.error("Could not create marshaller", e);
        return null;
    }

    GetRecordsType getRecords = new GetRecordsType();
    ObjectFactory objectFactory = new ObjectFactory();
    JAXBElement<GetRecordsType> jaxb_getRecords = objectFactory.createGetRecords(getRecords);

    getRecords.setResultType(ResultType.RESULTS);
    getRecords.setOutputSchema(getOutputSchemaParameter());
    getRecords.setStartPosition(BigInteger.valueOf(startPosition));
    getRecords.setMaxRecords(BigInteger.valueOf(maxRecords));
    QueryType query = new QueryType();
    ElementSetNameType esn = new ElementSetNameType();
    esn.setValue(ElementSetType.FULL);
    query.setElementSetName(esn);
    query.setTypeNames(Lists.newArrayList(new QName(getOutputSchemaParameter(),
            getTypeNamesParameter().substring(getTypeNamesParameter().indexOf(":") + 1))));
    getRecords.setAbstractQuery(objectFactory.createQuery(query));

    Writer w = new StringWriter();
    try {
        m.marshal(jaxb_getRecords, w);
    } catch (JAXBException e) {
        log.error("Error marshalling request", e);
    }

    log.trace("Created GetRecords request starting at {} for {} records:\n{}", startPosition, maxRecords,
            w.toString());

    StringEntity entity = new StringEntity(w.toString(), Charsets.UTF_8);
    return entity;
}

From source file:com.xerox.amazonws.sqs.MessageQueue.java

/**
 * Attempts to receive a message from the queue.
 *
 * @param visibilityTimeout the duration (in seconds) the retrieved message is hidden from
 *                          subsequent calls to retrieve.
 * @return the message object/*  w ww.ja  va2 s  . c o  m*/
 */
public Message receiveMessage(int visibilityTimeout) throws SQSException {
    Message amessage[] = receiveMessages(BigInteger.valueOf(1L), BigInteger.valueOf(visibilityTimeout));
    if (amessage.length > 0)
        return amessage[0];
    else
        return null;
}

From source file:com.docd.purefm.file.JavaFile.java

/**
 * {@inheritDoc}//from  ww  w . jav  a  2s .c  om
 */
@Override
public BigInteger lengthTotal() {
    if (mFile.exists()) {
        try {
            return FileUtils.sizeOfAsBigInteger(mFile);
        } catch (StackOverflowError e) {
            //if we have too much directories, we can get this
            return BigInteger.valueOf(-1);
        }
    }
    return BigInteger.ZERO;
}

From source file:com.wavemaker.json.JSONMarshallerTest.java

public void testNumericTypes() throws Exception {

    JSONState jc = new JSONState();

    ObjectWithTypes owt = new ObjectWithTypes();
    owt.setBigDecimal(BigDecimal.valueOf(12.2));
    owt.setIntVal(12);//from  ww  w.  j a va 2s . co  m
    owt.setFloatVal(13.3f);
    owt.setBigInteger(BigInteger.valueOf(13));
    owt.setBoolVal(false);

    String s = JSONMarshaller.marshal(owt, jc, false);
    assertEquals("{\"bigDecimal\":12.2,\"bigInteger\":13,\"boolVal\":false,\"floatVal\":13.3,\"intVal\":12}",
            s);

    assertEquals(s, StringUtils.deleteWhitespace(JSONUnmarshaller.unmarshal(s).toString()));
}

From source file:com.healthcit.cacure.xforms.XModuleModel.java

public FormType createFormType(QuestionnaireForm form) {

    FormType formType = jaxbFactory.createFormType();

    formType.setAuthor(form.getAuthor().getUserName());
    formType.setDescription(form.getName());
    formType.setName(form.getName());//  w  w  w.j ava2 s .  co  m
    formType.setId(form.getUuid());

    FormSkipRule formSkipRule = form.getFormSkipRule();
    //      List<FormSkip> formSkipSet = form.getFormSkip();

    if (formSkipRule != null) {
        //for (FormSkip formSkip: formSkipSet) {
        String formSkipLogicalOp = formSkipRule.getLogicalOp();
        List<QuestionSkipRule> questionRules = formSkipRule.getQuestionSkipRules();
        for (QuestionSkipRule questionRule : questionRules) {

            SkipRuleType skipRuleType = new SkipRuleType();
            String logicalOp = questionRule.getLogicalOp();
            if (logicalOp != null) {
                skipRuleType.setLogicalOp(logicalOp);
            }

            List<AnswerSkipRule> parts = questionRule.getSkipParts();
            Map<String, String> skipAnswersMap = new HashMap<String, String>();
            for (AnswerSkipRule part : parts) {
                skipAnswersMap.put(part.getAnswerValueId(), part.getAnswerValue().getValue());
            }
            List<String> skipRuleTypeValues = skipRuleType.getValue();
            BaseSkipPatternDetail skipDetail = questionRule.getDetails();
            BaseQuestion skipTrigQustn = skipDetail.getSkipTriggerQuestion();

            skipRuleType.setQuestionId(skipTrigQustn.getUuid());
            skipRuleType.setRule(questionRule.getRuleValue()); //show -- hide.
            skipRuleType.setFormId(skipDetail.getSkipTriggerForm().getUuid());
            if (questionRule.getIdentifyingAnswerValue() != null) {
                skipRuleType.setRowId(questionRule.getIdentifyingAnswerValue().getPermanentId());
            }

            Answer answer = skipTrigQustn.getAnswer();

            //         for(Answer answer: answersList) 
            //         {
            List<AnswerValue> answerValuesList = answer.getAnswerValues();
            for (AnswerValue answerValue : answerValuesList) {
                if (skipAnswersMap.containsKey(answerValue.getPermanentId())) {
                    skipRuleTypeValues.add(answerValue.getValue());
                }
            }
            //         }

            formType.getSkipRule().add(skipRuleType);
        }
    }
    List<FormElement> formQuestions = form.getElements();
    int questionCount = formQuestions.size();
    formType.setQuestionCount(BigInteger.valueOf(questionCount));

    switch (form.getStatus()) {
    case IN_PROGRESS:
        formType.setStatus("in-progress");
        break;
    case IN_REVIEW:
        formType.setStatus("submitted");
        break;
    case APPROVED:
        formType.setStatus("completed");
        break;
    }
    return formType;
}

From source file:libra.preprocess.common.kmerhistogram.KmerRangePartitioner.java

public KmerRangePartition[] getEqualAreaPartitions() {
    KmerRangePartition[] partitions = new KmerRangePartition[this.numPartitions];

    // calc 4^kmerSize
    BigInteger kmerend = BigInteger.valueOf(4).pow(this.kmerSize);
    BigDecimal bdkmerend = new BigDecimal(kmerend);
    // moves between x (0~1) y (0~1)
    // sum of area (0.5)
    double kmerArea = 0.5;
    double sliceArea = kmerArea / this.numPartitions;

    // we think triangle is horizontally flipped so calc get easier.
    double x1 = 0;

    List<BigInteger> widths = new ArrayList<BigInteger>();
    BigInteger widthSum = BigInteger.ZERO;
    for (int i = 0; i < this.numPartitions; i++) {
        // x2*x2 = 2*sliceArea + x1*x1
        double temp = (2 * sliceArea) + (x1 * x1);
        double x2 = Math.sqrt(temp);

        BigDecimal bdx1 = BigDecimal.valueOf(x1);
        BigDecimal bdx2 = BigDecimal.valueOf(x2);

        // if i increases, bdw will be decreased
        BigDecimal bdw = bdx2.subtract(bdx1);

        BigInteger bw = bdw.multiply(bdkmerend).toBigInteger();
        if (bw.compareTo(BigInteger.ZERO) <= 0) {
            bw = BigInteger.ONE;/* w w w. ja va 2  s.  c  o  m*/
        }

        if (widthSum.add(bw).compareTo(kmerend) > 0) {
            bw = kmerend.subtract(widthSum);
        }

        if (i == this.numPartitions - 1) {
            // last case
            if (widthSum.add(bw).compareTo(kmerend) < 0) {
                bw = kmerend.subtract(widthSum);
            }
        }

        // save it
        widths.add(bw);
        widthSum = widthSum.add(bw);

        x1 = x2;
    }

    BigInteger cur_begin = BigInteger.ZERO;
    for (int i = 0; i < this.numPartitions; i++) {
        BigInteger slice_width = widths.get(this.numPartitions - 1 - i);

        BigInteger slice_begin = cur_begin;

        if (slice_begin.add(slice_width).compareTo(kmerend) > 0) {
            slice_width = kmerend.subtract(slice_begin);
        }

        BigInteger slice_end = cur_begin.add(slice_width).subtract(BigInteger.ONE);

        KmerRangePartition slice = new KmerRangePartition(this.kmerSize, this.numPartitions, i, slice_width,
                slice_begin, slice_end);
        partitions[i] = slice;

        cur_begin = cur_begin.add(slice_width);
    }

    return partitions;
}

From source file:net.sf.jml.message.p2p.MsnP2PMessage.java

private String toHex(long value) {
    return "0x" + BigInteger.valueOf(value).toString(16);
}

From source file:NumberUtils.java

/**
 * Convert the given number into an instance of the given target class.
 * @param number the number to convert//from   www . j  ava  2  s . c  o m
 * @param targetClass the target class to convert to
 * @return the converted number
 * @throws IllegalArgumentException if the target class is not supported
 * (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte
 * @see java.lang.Short
 * @see java.lang.Integer
 * @see java.lang.Long
 * @see java.math.BigInteger
 * @see java.lang.Float
 * @see java.lang.Double
 * @see java.math.BigDecimal
 */
public static Number convertNumberToTargetClass(Number number, Class<?> targetClass)
        throws IllegalArgumentException {

    //   Assert.notNull(number, "Number must not be null");
    //   Assert.notNull(targetClass, "Target class must not be null");

    if (targetClass.isInstance(number)) {
        return number;
    } else if (targetClass.equals(Byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Byte(number.byteValue());
    } else if (targetClass.equals(Short.class)) {
        long value = number.longValue();
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Short(number.shortValue());
    } else if (targetClass.equals(Integer.class)) {
        long value = number.longValue();
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Integer(number.intValue());
    } else if (targetClass.equals(Long.class)) {
        return new Long(number.longValue());
    } else if (targetClass.equals(Float.class)) {
        return new Float(number.floatValue());
    } else if (targetClass.equals(Double.class)) {
        return new Double(number.doubleValue());
    } else if (targetClass.equals(BigInteger.class)) {
        return BigInteger.valueOf(number.longValue());
    } else if (targetClass.equals(BigDecimal.class)) {
        // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return new BigDecimal(number.toString());
    } else {
        throw new IllegalArgumentException("Could not convert number [" + number + "] of type ["
                + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]");
    }
}