Example usage for java.math BigInteger equals

List of usage examples for java.math BigInteger equals

Introduction

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

Prototype

public boolean equals(Object x) 

Source Link

Document

Compares this BigInteger with the specified Object for equality.

Usage

From source file:org.apache.blur.command.BaseCommandManager.java

protected synchronized int loadNewCommandsFromCommandPath() throws IOException {
    Path path = new Path(_commandPath);
    FileSystem fileSystem = path.getFileSystem(_configuration);
    int changeCount = 0;
    if (fileSystem.exists(path)) {
        FileStatus[] listStatus = fileSystem.listStatus(path);
        for (FileStatus fileStatus : listStatus) {
            BigInteger contentsCheck = checkContents(fileStatus, fileSystem);
            Path entryPath = fileStatus.getPath();
            BigInteger currentValue = _commandPathLastChange.get(entryPath);
            if (!contentsCheck.equals(currentValue)) {
                changeCount++;// w  w  w . j av a 2s.  co  m
                loadNewCommand(fileSystem, fileStatus, contentsCheck);
                _commandPathLastChange.put(entryPath, contentsCheck);
            }
        }
    }
    return changeCount;
}

From source file:it.nibbles.javacoin.block.BlockChainImpl.java

/**
 * Add a block to the chain. If the block is not connectable it will be added to the orphan pool.
 * No orphan is ever passed to the store.
 * @param rawBlock The block to add./*w ww .j ava 2  s  .c  o  m*/
 * @param checkOrphans Whether we should check if some orphans are now connectable.
 */
private int addBlock(Block block, boolean checkOrphans) throws VerificationException {
    logger.debug("Trying to add block: {}", block);

    // Internal validation
    block.validate();

    logger.debug("Checking whether block is already in the chain...");
    if (linkStorage.blockExists(block.getHash()))
        return 0;

    // Check 11: Check whether block is orphan block, in which case notify
    // listener to try to get that block and stop
    logger.debug("Checking whether block is orphan...");
    BlockChainLink previousLink = linkStorage.getLinkBlockHeader(block.getPreviousBlockHash());
    if (previousLink == null) {
        orphanBlocks.addBlock(block);

        // Notify listeners that we have a missing block
        if (listener != null)
            listener.notifyMissingBlock(block.getPreviousBlockHash());
        // Finish here for now, this block will be re-checked as soon as
        // its parent will be non-orphan
        return 0;
    }

    // Check 12: Check that nBits value matches the difficulty rules
    logger.debug("checking whether block has the appropriate target...");
    DifficultyTarget blockTarget = new DifficultyTarget(block.getCompressedTarget());
    BlockChainLink link = new BlockChainLink(block, // Create link for block
            previousLink.getTotalDifficulty().add(bitcoinFactory.newDifficulty(blockTarget)),
            previousLink.getHeight() + 1);
    DifficultyTarget calculatedTarget = getNextDifficultyTarget(previousLink, link.getBlock());
    if (blockTarget.compareTo(calculatedTarget) != 0)
        // Target has to exactly match the one calculated, otherwise it is
        // considered invalid!
        throw new VerificationException(
                "block has wrong target " + blockTarget + ", when calculated is: " + calculatedTarget);

    // Check 13: Reject if timestamp is before the median time of the last 11 blocks
    long medianTimestamp = getMedianTimestamp(previousLink);
    logger.debug("checking timestamp {} against median {}", block.getCreationTime(), medianTimestamp);
    if (block.getCreationTime() <= medianTimestamp)
        throw new VerificationException("block's creation time (" + block.getCreationTime()
                + ") is not after median of previous blocks: " + medianTimestamp);

    // Check 14: Check for known hashes
    BigInteger genesisHash = new BigInteger(1, bitcoinFactory.getGenesisBlock().getHash());
    BigInteger blockHash = new BigInteger(1, block.getHash());
    if (knownHashes.containsKey(genesisHash)) {
        BigInteger knownHash = knownHashes.get(genesisHash).get(link.getHeight());
        if ((knownHash != null) && (!knownHash.equals(blockHash)))
            throw new VerificationException(
                    "block should have a hash we already know, but it doesn't, might indicate a tampering or attack at depth: "
                            + link.getHeight());
    } else
        logger.warn(
                "known hashes don't exist for this chain, security checks for known blocks can not be made");
    // Checks 15,16,17,18: Check the transactions in the block
    // We diverge from the official list here since we don't maintain main and side branches
    // separately, and we have to make sure block is 100% compliant if we want to add it to the
    // tree (as non-orphan). Because of Block checks we know the first is a coinbase tx and
    // the rest are not. So execute checks from point 16. (Checks 16.3-5 are not
    // handles since they don't apply to this model)
    logger.debug("checking transactions...");
    // long time = System.currentTimeMillis();
    // long blockFees = serialTransactionVerifier(previousLink, block);
    // long time1 = System.currentTimeMillis() - time;
    long blockFees;
    try {
        //time = System.currentTimeMillis();
        //blockFees = parallelVerifier.verifyBlockTransactions(linkStorage, bitcoinFactory.getScriptFactory(), previousLink, block, simplifedVerification);
        blockFees = transactionsVerifier.verifyBlockTransactions(previousLink, block);
        //long time3 = System.currentTimeMillis() - time;
        //if (blockFees != parallelFees)
        //   throw new VerificationException("Calcolo fee non corrispondente: " + blockFees + " vs " + parallelFees);
        //else
        //   logger.info("time1: " + time1 + " time3: " + time3 + " fees: " + blockFees + " speedup: " + ((1.0 * time2) / time3));
    } catch (Exception e) {
        logger.error("Ex in nuovo codice verifica transazioni: " + e.getMessage(), e);
        throw new VerificationException(e.getMessage(), e);
    }

    // Verify coinbase if we have full verification and there is a coinbase
    logger.debug("verifying coinbase...");
    Transaction coinbaseTx = null;
    if (!block.getTransactions().isEmpty())
        coinbaseTx = block.getTransactions().get(0);
    if ((!simplifiedVerification) && (coinbaseTx.isCoinbase())) {
        long coinbaseValue = 0;
        for (TransactionOutput out : coinbaseTx.getOutputs()) {
            coinbaseValue += out.getValue();
        }
        // Check 16.2: Verify that the money produced is in the legal range
        // Valid if coinbase value is not greater than mined value plus fees in tx
        long coinbaseValid = getBlockCoinbaseValue(link);
        if (coinbaseValue > coinbaseValid + blockFees)
            throw new VerificationException(
                    "coinbase transaction in block " + block + " claimed more coins than appropriate: "
                            + coinbaseValue + " vs. " + (coinbaseValid + blockFees) + " (coinbase: "
                            + coinbaseValid + ", block fees: " + blockFees + ")");
    }

    // Check 16.6: Relay block to our peers
    // (Also: add or update the link in storage, and only relay if it's really new)
    logger.debug("adding block to storage...");
    linkStorage.addLink(link);
    if (listener != null)
        listener.notifyAddedBlock(block);

    // Check 19: For each orphan block for which this block is its prev,
    // run all these steps (including this one) recursively on that orphan
    int blocksAdded = 1;
    if (checkOrphans) {
        blocksAdded += connectOrphanBlocks(block);
    }
    return blocksAdded;
}

From source file:org.opendaylight.vpnservice.dhcpservice.DhcpExternalTunnelManager.java

public void updateCacheAndInstallNewFlows(BigInteger dpnId, List<BigInteger> listOfDpns,
        Pair<IpAddress, String> pair) throws ExecutionException {
    BigInteger newDesignatedDpn = chooseDpn(pair.getLeft(), pair.getRight(), listOfDpns);
    if (newDesignatedDpn.equals(DHCPMConstants.INVALID_DPID)) {
        return;//from www.j av  a2  s  . com
    }
    Set<String> listVmMacs = tunnelIpElanNameToVmMacCache.get(pair);
    if (listVmMacs != null && !listVmMacs.isEmpty()) {
        installDhcpFlowsForVms(pair.getLeft(), pair.getRight(), newDesignatedDpn, listVmMacs);
    }
}

From source file:cc.redberry.core.number.Complex.java

@Override
public Complex add(BigInteger bg) {
    NumberUtils.checkNotNull(bg);//from w w w .  j a v a 2s  .  co  m
    return bg.equals(BigInteger.ZERO) ? this : new Complex(real.add(bg), imaginary);
}

From source file:cc.redberry.core.number.Complex.java

@Override
public Complex subtract(BigInteger bg) {
    NumberUtils.checkNotNull(bg);/*from www  .ja  v a 2  s . c o  m*/
    return bg.equals(BigInteger.ZERO) ? this : new Complex(real.subtract(bg), imaginary);
}

From source file:org.opendaylight.vpnservice.dhcpservice.DhcpExternalTunnelManager.java

public BigInteger designateDpnId(IpAddress tunnelIp, String elanInstanceName, List<BigInteger> dpns) {
    BigInteger designatedDpnId = readDesignatedSwitchesForExternalTunnel(tunnelIp, elanInstanceName);
    if (designatedDpnId != null && !designatedDpnId.equals(DHCPMConstants.INVALID_DPID)) {
        logger.trace("Dpn {} already designated for tunnelIp - elan : {} - {}", designatedDpnId, tunnelIp,
                elanInstanceName);//from   w  ww  .  j  a v a2 s .  c om
        return designatedDpnId;
    }
    return chooseDpn(tunnelIp, elanInstanceName, dpns);
}

From source file:org.opendaylight.vpnservice.dhcpservice.DhcpExternalTunnelManager.java

public void installRemoteMcastMac(final BigInteger designatedDpnId, final IpAddress tunnelIp,
        final String elanInstanceName) {
    if (designatedDpnId.equals(DHCPMConstants.INVALID_DPID)) {
        return;//from www.  j  a v a 2 s.  c  o m
    }
    ListenableFuture<Boolean> checkEntityOwnerFuture = ClusteringUtils.checkNodeEntityOwner(
            entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
            HwvtepSouthboundConstants.ELAN_ENTITY_NAME);
    Futures.addCallback(checkEntityOwnerFuture, new FutureCallback<Boolean>() {
        @Override
        public void onSuccess(Boolean isOwner) {
            if (isOwner) {
                logger.info("Installing remote McastMac");
                L2GatewayDevice device = getDeviceFromTunnelIp(elanInstanceName, tunnelIp);
                String tunnelInterfaceName = getExternalTunnelInterfaceName(String.valueOf(designatedDpnId),
                        device.getHwvtepNodeId());
                IpAddress internalTunnelIp = null;
                if (tunnelInterfaceName != null) {
                    Interface tunnelInterface = DhcpServiceUtils.getInterfaceFromConfigDS(tunnelInterfaceName,
                            broker);
                    if (tunnelInterface == null) {
                        logger.trace("Tunnel Interface is not present {}", tunnelInterfaceName);
                        return;
                    }
                    internalTunnelIp = tunnelInterface.getAugmentation(IfTunnel.class).getTunnelSource();
                    WriteTransaction transaction = broker.newWriteOnlyTransaction();
                    putRemoteMcastMac(transaction, elanInstanceName, device, internalTunnelIp);
                    if (transaction != null) {
                        transaction.submit();
                    }
                }
            } else {
                logger.info("Installing remote McastMac is not executed for this node.");
            }
        }

        @Override
        public void onFailure(Throwable error) {
            logger.error("Failed to install remote McastMac", error);
        }
    });
}

From source file:org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager.java

public void updateCacheAndInstallNewFlows(BigInteger dpnId, List<BigInteger> listOfDpns,
        Pair<IpAddress, String> pair, WriteTransaction tx) throws ExecutionException {
    BigInteger newDesignatedDpn = chooseDpn(pair.getLeft(), pair.getRight(), listOfDpns);
    if (newDesignatedDpn.equals(DhcpMConstants.INVALID_DPID)) {
        return;/*from ww  w. j a  v a 2s.  c  o m*/
    }
    Set<String> setOfVmMacs = tunnelIpElanNameToVmMacCache.get(pair);
    if (setOfVmMacs != null && !setOfVmMacs.isEmpty()) {
        LOG.trace("Updating DHCP flows for VMs {} with new designated DPN {}", setOfVmMacs, newDesignatedDpn);
        installDhcpFlowsForVms(newDesignatedDpn, setOfVmMacs, tx);
    }
}

From source file:org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager.java

public BigInteger designateDpnId(IpAddress tunnelIp, String elanInstanceName, List<BigInteger> dpns) {
    BigInteger designatedDpnId = readDesignatedSwitchesForExternalTunnel(tunnelIp, elanInstanceName);
    if (designatedDpnId != null && !designatedDpnId.equals(DhcpMConstants.INVALID_DPID)) {
        LOG.trace("Dpn {} already designated for tunnelIp - elan : {} - {}", designatedDpnId, tunnelIp,
                elanInstanceName);// w w w.  jav  a  2  s . c o m
        return designatedDpnId;
    }
    return chooseDpn(tunnelIp, elanInstanceName, dpns);
}

From source file:org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager.java

public void installRemoteMcastMac(final BigInteger designatedDpnId, final IpAddress tunnelIp,
        final String elanInstanceName) {
    if (designatedDpnId.equals(DhcpMConstants.INVALID_DPID)) {
        return;//from  www . j a v a 2s .  c  om
    }
    ListenableFuture<Boolean> checkEntityOwnerFuture = ClusteringUtils.checkNodeEntityOwner(
            entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
            HwvtepSouthboundConstants.ELAN_ENTITY_NAME);
    Futures.addCallback(checkEntityOwnerFuture, new FutureCallback<Boolean>() {
        @Override
        public void onSuccess(Boolean isOwner) {
            if (isOwner) {
                LOG.info("Installing remote McastMac");
                L2GatewayDevice device = getDeviceFromTunnelIp(elanInstanceName, tunnelIp);
                String tunnelInterfaceName = getExternalTunnelInterfaceName(String.valueOf(designatedDpnId),
                        device.getHwvtepNodeId());
                IpAddress internalTunnelIp = null;
                if (tunnelInterfaceName != null) {
                    Interface tunnelInterface = interfaceManager
                            .getInterfaceInfoFromConfigDataStore(tunnelInterfaceName);
                    if (tunnelInterface == null) {
                        LOG.trace("Tunnel Interface is not present {}", tunnelInterfaceName);
                        return;
                    }
                    internalTunnelIp = tunnelInterface.getAugmentation(IfTunnel.class).getTunnelSource();
                    WriteTransaction transaction = broker.newWriteOnlyTransaction();
                    putRemoteMcastMac(transaction, elanInstanceName, device, internalTunnelIp);
                    if (transaction != null) {
                        transaction.submit();
                    }
                }
            } else {
                LOG.info("Installing remote McastMac is not executed for this node.");
            }
        }

        @Override
        public void onFailure(Throwable error) {
            LOG.error("Failed to install remote McastMac", error);
        }
    });
}