List of usage examples for java.math BigInteger longValue
public long longValue()
From source file:com.clustercontrol.poller.impl.WbemPollerImpl.java
/** * ?// ww w. ja v a2 s .c om * IP?DataTable???? * ????DataTable?? * * @param ipAddress IP * @param port ?? * @param protocol * @param user * @param password * @param nameSpace ??? * @param retries ???? * @param timeout ?? * @param cimList CIM?? * @param indexCheckFlg ??????????? */ @SuppressWarnings("unchecked") public DataTable polling(String ipAddress, int port, String protocol, String user, String password, String nameSpace, int retries, int timeout, Set<String> cimList // cim???? ) { // ? init(); if (port < 0) { m_log.debug("set Port. " + port + " to " + DEFAULT_PORT); port = DEFAULT_PORT; } // ? if (retries < 0) { m_log.debug("set Retries. " + retries + " to " + DEFAULT_RETRIES); retries = DEFAULT_RETRIES; } if (timeout < 0) { m_log.debug("set Timeout. " + timeout + " to " + DEFAULT_TIMEOUT); timeout = DEFAULT_TIMEOUT; } // ???? DataTable dataTable = new DataTable(); m_ipAddress = ipAddress; try { InetAddress address = InetAddress.getByName(ipAddress); if (address instanceof Inet6Address) { m_ipAddress = "[" + m_ipAddress + "]"; } } catch (UnknownHostException e) { m_log.warn("polling() ipAddress = " + ipAddress, e); } m_cimAgentAddress = protocol + "://" + m_ipAddress + ":" + port; if (nameSpace != null) { m_nameSpace = nameSpace; } // ? if (m_log.isDebugEnabled()) { m_log.debug("polling() start : " + m_ipAddress.toString()); m_log.debug("Port : " + port); m_log.debug("Protocol : " + protocol); m_log.debug("User : " + user); m_log.debug("Password : " + password); m_log.debug("Retries : " + retries); m_log.debug("Timeout : " + timeout); m_log.debug("URL : " + m_cimAgentAddress); } long enumerationStart = HinemosTime.currentTimeMillis(); CIMClient cimClient = null; try { // ***************************** // 1. Create user credentials // ***************************** UserPrincipal userPr = new UserPrincipal(user); PasswordCredential pwCred = new PasswordCredential(password.toCharArray()); // ***************************** // 2. Set NameSpace // - URL is set like: http(s)://<IP>:Port // - Namespace does not need to be specified in COPs if set in this constuctor // - There is no server authentication being done. Thus: No need for a truststore // ***************************** CIMNameSpace ns = new CIMNameSpace(m_cimAgentAddress, m_nameSpace); // ***************************** // 3. Create CIM Client // ***************************** cimClient = new CIMClient(ns, userPr, pwCred); // ***************************** // 4. Create Session Properties // ***************************** SessionProperties properties = cimClient.getSessionProperties(); if (properties == null) { properties = new SessionProperties(); cimClient.setSessionProperties(properties); } properties.setHttpTimeOut(timeout); m_cimText = new String[cimList.size()]; // ??????HashMap? HashMap<String, ArrayList<String>> requestMap = new HashMap<String, ArrayList<String>>(); String cimClass = ""; String cimProperty = ""; ArrayList<String> propertyList = null; int i = 0; for (String cimText : cimList) { m_cimText[i] = cimText; String[] targetValue = m_cimText[i].split("\\."); cimClass = targetValue[0]; cimProperty = targetValue[1]; propertyList = requestMap.get(cimClass); // ???????? if (propertyList != null && propertyList.size() != 0) { propertyList.add(cimProperty); } // ??????????? else { propertyList = new ArrayList<String>(); propertyList.add(cimProperty); requestMap.put(cimClass, propertyList); } i++; } CIMObjectPath cop = null; CIMInstance ci = null; CIMValue value = null; Enumeration<CIMInstance> enm = null; // ??? for (int j = 0; j < retries; j++) { boolean errorFlg = false; m_retMap = new HashMap<String, CIMValue>(); try { for (Map.Entry<String, ArrayList<String>> cimClassEntry : requestMap.entrySet()) { cimClass = cimClassEntry.getKey(); propertyList = cimClassEntry.getValue(); m_log.debug("CIMClass : " + cimClassEntry.getKey()); cop = new CIMObjectPath(cimClassEntry.getKey()); enm = cimClient.enumInstances(cop, true); i = 0; while (enm.hasMoreElements()) { ci = enm.nextElement(); for (String property : propertyList) { cimProperty = property; if (ci.getProperty(cimProperty) != null) { value = ci.getProperty(cimProperty).getValue(); // ????5?1??? // CIM?????????????? // // ?????Array index out of range: 0?? // test code /* if(value.getType().getType() == CIMDataType.STRING_ARRAY){ testCounter ++; if (testCounter > 10) { value = new CIMValue(new Vector<String>(), new CIMDataType(CIMDataType.STRING_ARRAY)); testCounter = 0; } } */ // test code if (!checkCIMData(value)) { errorFlg = true; continue; /* * ?????????? * (???????????????) */ } m_retMap.put(cimClass + "." + cimProperty + "." + i, value); } } if (errorFlg) { break; } i++; } if (errorFlg) { break; } } } catch (CIMException e) { errorFlg = true; for (String property : propertyList) { dataTable.putValue(new TableEntry(getEntryKey(cimClass + "." + property + ".0"), HinemosTime.currentTimeMillis(), ErrorType.IO_ERROR, e)); } m_log.warn("polling() warning :" + m_ipAddress.toString() + ", cimClass=" + cimClass + ", ID=" + e.getID() + ", message=" + e.getMessage()); } catch (Exception e) { errorFlg = true; for (String property : propertyList) { dataTable.putValue(new TableEntry(getEntryKey(cimClass + "." + property + ".0"), HinemosTime.currentTimeMillis(), ErrorType.IO_ERROR, e)); } m_log.warn("polling() warning :" + m_ipAddress.toString() + ", " + cimClass + " unforeseen error. " + e.getMessage(), e); } finally { if (errorFlg) { // m_retMap = new HashMap<String, CIMValue>(); /* * ???????????m_retMap? * ??? */ } else { break; } } } } catch (RuntimeException e) { m_log.warn("polling() warning :" + m_ipAddress.toString() + " unforeseen error. " + e.getMessage(), e); } finally { if (cimClient != null) { try { cimClient.close(); } catch (Exception e) { m_log.warn("polling():" + m_ipAddress.toString() + " Session close failed", e); } } } long enumerationStop = HinemosTime.currentTimeMillis(); // ? if (m_log.isDebugEnabled()) { m_log.debug("polling() end : time : " + (enumerationStop - enumerationStart)); } // *************** // ?? (?) // *************** try { // ????????????? if (m_retMap == null || m_retMap.size() == 0) { m_log.debug("wbemReceived() : " + m_ipAddress.toString() + " result is empty"); return dataTable; } long time = HinemosTime.currentTimeMillis(); // ? for (Map.Entry<String, CIMValue> entry : m_retMap.entrySet()) { String cimString = entry.getKey(); CIMValue value = entry.getValue(); if (value.getType().getType() == CIMDataType.UINT8) { long ret = ((UnsignedInt8) value.getValue()).longValue(); dataTable.putValue(getEntryKey(cimString), time, ret); m_log.debug("polling() dataTable put : " + "entryKey : " + getEntryKey(cimString) + ", time : " + time + ", value : " + ret); } else if (value.getType().getType() == CIMDataType.UINT16) { long ret = ((UnsignedInt16) value.getValue()).longValue(); dataTable.putValue(getEntryKey(cimString), time, ret); m_log.debug("polling() dataTable put : " + "entryKey : " + getEntryKey(cimString) + ", time : " + time + ", value : " + ret); } else if (value.getType().getType() == CIMDataType.UINT32) { long ret = ((UnsignedInt32) value.getValue()).longValue(); dataTable.putValue(getEntryKey(cimString), time, ret); m_log.debug("polling() dataTable put : " + "entryKey : " + getEntryKey(cimString) + ", time : " + time + ", value : " + ret); } else if (value.getType().getType() == CIMDataType.UINT64) { BigInteger bigInt = ((UnsignedInt64) value.getValue()).bigIntValue(); long ret = bigInt.longValue(); dataTable.putValue(getEntryKey(cimString), time, ret); m_log.debug("polling() dataTable put : " + "entryKey : " + getEntryKey(cimString) + ", time : " + time + ", value : " + ret); } else if (value.getType().getType() == CIMDataType.STRING) { String ret = (String) value.getValue(); dataTable.putValue(getEntryKey(cimString), time, ret); m_log.debug("polling() dataTable put : " + "entryKey : " + getEntryKey(cimString) + ", time : " + time + ", value : " + ret); } else if (value.getType().getType() == CIMDataType.STRING_ARRAY) { Vector<String> ret = (Vector<String>) value.getValue(); dataTable.putValue(getEntryKey(cimString), time, ret); m_log.debug("polling() dataTable put : " + "entryKey : " + getEntryKey(cimString) + ", time : " + time + ", value : " + ret); } else if (value.getType().getType() == CIMDataType.DATETIME) { CIMDateTime sdt = (CIMDateTime) value.getValue(); // CIMDateTime?Calendar? Calendar cal = sdt.getCalendar(); // Calendar?????????? long ret = cal.getTimeInMillis() / 1000; dataTable.putValue(getEntryKey(cimString), time, ret); m_log.debug("polling() dataTable put : " + "entryKey : " + getEntryKey(cimString) + ", time : " + time + ", value : " + ret); } else { m_log.debug("polling() data type is nothing"); } } } catch (Exception e) { // ????????? m_log.warn("polling() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); // ????? dataTable.clear(); for (Map.Entry<String, CIMValue> entry : m_retMap.entrySet()) { final String entryKey = getEntryKey(entry.getKey()); dataTable .putValue(new TableEntry(entryKey, HinemosTime.currentTimeMillis(), ErrorType.IO_ERROR, e)); } } return dataTable; }
From source file:ubic.gemma.analysis.sequence.ArrayDesignMapResultServiceImpl.java
@Override public Collection<CompositeSequenceMapValueObject> getSummaryMapValueObjects( Collection<Object[]> sequenceData) { Map<Long, CompositeSequenceMapValueObject> summary = new HashMap<Long, CompositeSequenceMapValueObject>(); Map<Long, HashSet<Long>> blatResultCount = new HashMap<Long, HashSet<Long>>(); for (Object o : sequenceData) { Object[] row = (Object[]) o; Long csId = ((BigInteger) row[0]).longValue(); String csName = (String) row[1]; String bioSequenceName = (String) row[2]; String bioSequenceNcbiId = (String) row[3]; Object blatId = row[4];/* w ww . j a va2 s .com*/ Object geneProductId = row[5]; String geneProductName = (String) row[6]; String geneProductAccession = (String) row[7]; Object geneProductGeneId = row[8]; String geneProductType = (String) row[9]; Object geneId = row[10]; String geneName = (String) row[11]; Integer geneAccession = (Integer) row[12]; // NCBI String arrayDesignShortName = (String) row[13]; BigInteger arrayDesignId = (BigInteger) row[14]; CompositeSequenceMapValueObject vo; if (summary.containsKey(csId)) { vo = summary.get(csId); } else { vo = new CompositeSequenceMapValueObject(); summary.put(csId, vo); } String csDesc = (String) row[15]; vo.setCompositeSequenceDescription(csDesc); vo.setArrayDesignId(arrayDesignId.longValue()); vo.setCompositeSequenceId(csId.toString()); vo.setCompositeSequenceName(csName); vo.setArrayDesignName(arrayDesignShortName); // fill in value object if (bioSequenceName != null && vo.getBioSequenceName() == null) { vo.setBioSequenceName(bioSequenceName); } // fill in value object if (bioSequenceNcbiId != null && vo.getBioSequenceNcbiId() == null) { vo.setBioSequenceNcbiId(bioSequenceNcbiId); } countBlatHits(blatResultCount, csId, vo, blatId); // fill in value object for geneProducts if (geneProductId != null) { Map<String, GeneProductValueObject> geneProductSet = vo.getGeneProducts(); // if the geneProduct is already in the map, do not do anything. // if it isn't there, put it in the map if (!geneProductSet.containsKey(geneProductId)) { GeneProductValueObject gpVo = new GeneProductValueObject(); gpVo.setId(((BigInteger) geneProductId).longValue()); gpVo.setName(geneProductName); gpVo.setNcbiId(geneProductAccession); if (geneProductGeneId != null) { gpVo.setGeneId(((BigInteger) geneProductGeneId).longValue()); } gpVo.setType(geneProductType); geneProductSet.put(((BigInteger) geneProductId).toString(), gpVo); } } // fill in value object for genes if (geneId != null) { Map<String, GeneValueObject> geneSet = vo.getGenes(); if (!geneSet.containsKey(geneId)) { GeneValueObject gVo = new GeneValueObject(); gVo.setId(((BigInteger) geneId).longValue()); gVo.setOfficialSymbol(geneName); gVo.setNcbiId(geneAccession); geneSet.put(((BigInteger) geneId).toString(), gVo); } } } return summary.values(); }
From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java
private static Payment createPaymentMessage(@Nonnull final Transaction transaction, @Nullable final Address refundAddress, @Nullable final BigInteger refundAmount, @Nullable final String memo, @Nullable final byte[] merchantData) { final Protos.Payment.Builder builder = Protos.Payment.newBuilder(); builder.addTransactions(ByteString.copyFrom(transaction.unsafeBitcoinSerialize())); if (refundAddress != null) { if (refundAmount.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) throw new IllegalArgumentException("refund amount too big for protobuf: " + refundAmount); final Protos.Output.Builder refundOutput = Protos.Output.newBuilder(); refundOutput.setAmount(refundAmount.longValue()); refundOutput//from w w w . j ava 2 s . c o m .setScript(ByteString.copyFrom(ScriptBuilder.createOutputScript(refundAddress).getProgram())); builder.addRefundTo(refundOutput); } if (memo != null) builder.setMemo(memo); if (merchantData != null) builder.setMerchantData(ByteString.copyFrom(merchantData)); return builder.build(); }
From source file:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java
@Test public void test_convertAny() throws Exception { final Boolean result = (Boolean) AnyUtils.convertAny(this.any); Assert.assertTrue(result);/* w w w.jav a 2 s . com*/ Assert.assertNull(AnyUtils.convertAny(null)); String str = (String) AnyUtils.convertAny(AnyUtils.toAny("2", TCKind.tk_string)); Assert.assertEquals("2", str); str = (String) AnyUtils.convertAny(AnyUtils.toAny("3", TCKind.tk_wstring)); Assert.assertEquals("3", str); final short b = (Short) AnyUtils.convertAny(AnyUtils.toAny(Byte.MAX_VALUE, TCKind.tk_octet)); Assert.assertEquals(Byte.MAX_VALUE, b); char c = (Character) AnyUtils.convertAny(AnyUtils.toAny(Character.MAX_VALUE, TCKind.tk_char)); Assert.assertEquals(Character.MAX_VALUE, c); c = (Character) AnyUtils.convertAny(AnyUtils.toAny(new Character('2'), TCKind.tk_wchar)); Assert.assertEquals('2', c); final short s = (Short) AnyUtils.convertAny(AnyUtils.toAny(Short.MAX_VALUE, TCKind.tk_short)); Assert.assertEquals(Short.MAX_VALUE, s); final int i = (Integer) AnyUtils.convertAny(AnyUtils.toAny(Integer.MAX_VALUE, TCKind.tk_long)); Assert.assertEquals(Integer.MAX_VALUE, i); final long l = (Long) AnyUtils.convertAny(AnyUtils.toAny(Long.MAX_VALUE, TCKind.tk_longlong)); Assert.assertEquals(Long.MAX_VALUE, l); final float f = (Float) AnyUtils.convertAny(AnyUtils.toAny(Float.MAX_VALUE, TCKind.tk_float)); Assert.assertEquals(Float.MAX_VALUE, f, 0.00001); final double d = (Double) AnyUtils.convertAny(AnyUtils.toAny(Double.MAX_VALUE, TCKind.tk_double)); Assert.assertEquals(Double.MAX_VALUE, d, 0.00001); final int us = (Integer) AnyUtils.convertAny(AnyUtils.toAny(Short.MAX_VALUE, TCKind.tk_ushort)); Assert.assertEquals(Short.MAX_VALUE, us); final long ui = (Long) AnyUtils.convertAny(AnyUtils.toAny(Integer.MAX_VALUE, TCKind.tk_ulong)); Assert.assertEquals(Integer.MAX_VALUE, ui); final BigInteger ul = (BigInteger) AnyUtils.convertAny(AnyUtils.toAny(Long.MAX_VALUE, TCKind.tk_ulonglong)); Assert.assertEquals(Long.MAX_VALUE, ul.longValue()); /** TODO Big Decimal not supported final BigDecimal fix = (BigDecimal) AnyUtils.convertAny(AnyUtils.toAny(new BigDecimal(1.0), TCKind.tk_fixed)); Assert.assertEquals(1.0, fix.doubleValue(), 0.00001); */ Any tmpAny = (Any) AnyUtils.convertAny(AnyUtils.toAny(AnyUtils.toAny(1, TCKind.tk_long), TCKind.tk_any)); Assert.assertNotNull(tmpAny); Assert.assertEquals(1, tmpAny.extract_long()); /** TODO Why do these not work in Jacorb? **/ // tmpAny = (Any) AnyUtils.convertAny(AnyUtils.toAny(AnyUtils.toAny((short) 1, TCKind.tk_short), TCKind.tk_value)); // Assert.assertNotNull(tmpAny); // Assert.assertEquals((short) 1, tmpAny.extract_short()); // final TypeCode tmpType = (TypeCode) AnyUtils.convertAny(AnyUtils.toAny(tmpAny.type(), TCKind.tk_TypeCode)); // Assert.assertNotNull(tmpType); // Assert.assertEquals(TCKind._tk_short, tmpType.kind().value()); // final Object obj = AnyUtils.convertAny(null, tmpType); // Assert.assertNull(obj); }
From source file:org.gss_project.gss.server.ejb.GSSDAOBean.java
private List<Long> getGroupIdsForUserId(Long userId) { List<BigInteger> groups = manager .createNativeQuery(//from www . j av a 2 s . c o m "select distinct groupsmember_id " + "from GSS_Group_GSS_User where members_id=:userId") .setParameter("userId", userId).getResultList(); List<Long> groupIds = new ArrayList<Long>(); for (BigInteger id : groups) groupIds.add(id.longValue()); return groupIds; }
From source file:com.abiquo.server.core.infrastructure.DatacenterDAO.java
/** * TODO: create queries/*from w w w .ja va2s .c om*/ * * @param datacenterId * @param enterpriseId * @return */ public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId, final int enterpriseId) { Object[] vmResources = (Object[]) getSession().createSQLQuery(SUM_VM_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); Long cpu = vmResources[0] == null ? 0 : ((BigDecimal) vmResources[0]).longValue(); Long ram = vmResources[1] == null ? 0 : ((BigDecimal) vmResources[1]).longValue(); Long hd = vmResources[2] == null ? 0 : ((BigDecimal) vmResources[2]).longValue(); BigDecimal extraHd = (BigDecimal) getSession().createSQLQuery(SUM_EXTRA_HD_RESOURCES) .setParameter("datacenterId", datacenterId).uniqueResult(); Long hdTot = extraHd == null ? hd : hd + extraHd.longValue() * 1024 * 1024; BigDecimal storage = (BigDecimal) getSession().createSQLQuery(SUM_STORAGE_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); BigInteger publicIps = (BigInteger) getSession().createSQLQuery(COUNT_IP_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); BigInteger vlan = (BigInteger) getSession().createSQLQuery(COUNT_VLAN_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); DefaultEntityCurrentUsed used = new DefaultEntityCurrentUsed(cpu.intValue(), ram, hdTot); // Storage usage is stored in MB used.setStorage(storage == null ? 0 : storage.longValue() * 1024 * 1024); used.setPublicIp(publicIps == null ? 0 : publicIps.longValue()); used.setVlanCount(vlan == null ? 0 : vlan.longValue()); return used; }
From source file:com.bonsai.wallet32.HDWallet.java
public AmountAndFee useAll(Wallet wallet, int acctnum, boolean spendUnconfirmed) throws InsufficientMoneyException { // Create a pretend send request and extract the recommended // fee. Which account are we using for this send? HDAccount acct = mAccounts.get(acctnum); // Pretend we are sending the bitcoin to ourselves. Address dest = acct.nextReceiveAddress(); SendRequest req = SendRequest.emptyWallet(dest); req.coinSelector = acct.coinSelector(spendUnconfirmed); req.aesKey = mAesKey;//from w w w . jav a2 s .co m // Let the wallet do the heavy lifting ... wallet.completeTx(req); // It doesn't look like req.fee gets set to the required fee // when using emptyWallet. Figure out the fee ourselves ... // BigInteger outAmt = req.tx.getValueSentFromMe(wallet); BigInteger inAmt = req.tx.getValueSentToMe(wallet); BigInteger feeAmt = outAmt.subtract(inAmt); return new AmountAndFee(inAmt.longValue(), feeAmt.longValue()); }
From source file:de.undercouch.bson4jackson.BsonGenerator.java
@Override public void writeNumber(BigInteger v) throws IOException, JsonGenerationException { int bl = v.bitLength(); if (bl < 32) { writeNumber(v.intValue());//from w ww . ja v a 2 s . co m } else if (bl < 64) { writeNumber(v.longValue()); } else { writeString(v.toString()); } }
From source file:org.opendaylight.netvirt.dhcpservice.DhcpPktHandler.java
private List<Action> getEgressAction(String interfaceName, BigInteger tunnelId) { List<Action> actions = null; try {/*from w w w .ja v a 2 s .c om*/ GetEgressActionsForInterfaceInputBuilder egressAction = new GetEgressActionsForInterfaceInputBuilder() .setIntfName(interfaceName); if (tunnelId != null) { egressAction.setTunnelKey(tunnelId.longValue()); } Future<RpcResult<GetEgressActionsForInterfaceOutput>> result = interfaceManagerRpc .getEgressActionsForInterface(egressAction.build()); RpcResult<GetEgressActionsForInterfaceOutput> rpcResult = result.get(); if (!rpcResult.isSuccessful()) { LOG.warn("RPC Call to Get egress actions for interface {} returned with Errors {}", interfaceName, rpcResult.getErrors()); } else { actions = rpcResult.getResult().getAction(); } } catch (InterruptedException | ExecutionException e) { LOG.warn("Exception when egress actions for interface {}", interfaceName, e); } return actions; }
From source file:dao.AdDao.java
public List<Long> getChosenIds(Long userId) { String sql = "select ad_id from chosen_ads where user_id=:userId"; Query query = getCurrentSession().createSQLQuery(sql); query.setParameter("userId", userId); List<BigInteger> preres = query.list(); List<Long> res = new ArrayList(); for (BigInteger id : preres) { res.add(id.longValue()); }//from w w w .j a v a2 s . com return res; }