Example usage for java.lang Double POSITIVE_INFINITY

List of usage examples for java.lang Double POSITIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Double POSITIVE_INFINITY.

Prototype

double POSITIVE_INFINITY

To view the source code for java.lang Double POSITIVE_INFINITY.

Click Source Link

Document

A constant holding the positive infinity of type double .

Usage

From source file:gedi.util.math.stat.distributions.GeneralizedExtremeValueDistribution.java

@Override
public double getNumericalVariance() {
    if (shape == 0)
        return scale * scale * Math.PI * Math.PI / 6;
    if (shape >= 0.5)
        return Double.POSITIVE_INFINITY;
    double g1 = Gamma.gamma(1 - shape);
    double g2 = Gamma.gamma(1 - 2 * shape);
    return scale * scale * (g2 - g1 * g1) / shape / shape;
}

From source file:ch.epfl.leb.sass.models.fluorophores.commands.internal.FluorophoreReceiverIT.java

/**
 * Test of generateFluorophoresRandom3D method, of class FluorophoreReceiver.
 *///w ww.  j av  a  2s  .  co  m
@Test
public void testGenerateFluorophoresRandom3D() {
    GenerateFluorophoresRandom3D.Builder fluorBuilder = new GenerateFluorophoresRandom3D.Builder();
    fluorBuilder.numFluors(25); // Number of fluorophores
    fluorBuilder.zLow(0);
    fluorBuilder.zHigh(5.0);

    // Create the set of fluorophores.
    fluorBuilder.camera(camera).psfBuilder(psfBuilder).fluorDynamics(fluorDynamics).illumination(illumination);
    FluorophoreCommand fluorCommand = fluorBuilder.build();
    List<Fluorophore> fluorophores = fluorCommand.generateFluorophores();
    assertEquals(25, fluorophores.size());

    double minZ = Double.POSITIVE_INFINITY;
    double maxZ = Double.NEGATIVE_INFINITY;
    for (Fluorophore f : fluorophores) {
        if (f.getZ() < minZ)
            minZ = f.getZ();

        if (f.getZ() > maxZ)
            maxZ = f.getZ();
    }

    assertTrue(maxZ <= 5.0);
    assertTrue(minZ >= 0.0);
}

From source file:egat.replicatordynamics.SymmetricConstrainedTransformedAmoebaSearch.java

public Strategy run(SymmetricGame game, Strategy initialStrategy, Set<Action> restrictedActions,
        boolean randomize) {

    Action[] actions = game.getActions().toArray(new Action[0]);

    boolean[] mask = new boolean[actions.length];

    int restrictedCount = 0;

    for (int i = 0; i < actions.length; i++) {

        mask[i] = restrictedActions.contains(actions[i]);

        if (mask[i]) {

            restrictedCount++;/*w w  w  . ja v a  2  s  . c  o m*/

        }

    }

    int[] restricted = new int[restrictedCount];

    for (int i = 0, restrictedIndex = 0; i < actions.length; i++) {

        if (mask[i]) {

            restricted[restrictedIndex++] = i;

        }
    }

    Player[] players = game.players().toArray(new Player[0]);

    PayoffMatrix pm = createPayoffMatrix(game, players, actions);

    // Normalize to a uniform distribution
    double[] distribution = new double[actions.length];

    double[] bestDist = new double[actions.length];

    if (initialStrategy == null) {
        double sum = 0.0;
        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] = Math.random();
                sum += bestDist[i];
            }
        }

        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] /= sum;
            }
        }

    } else {
        for (int i = 0; i < actions.length; i++) {
            if (mask[i]) {
                bestDist[i] = initialStrategy.getProbability(actions[i]).doubleValue();
            }
        }
    }

    double bestRegret = pm.regret(bestDist);

    // Initialize current strategy
    Strategy currentStrategy = buildStrategy(actions, bestDist, restricted);

    fireUpdatedStrategy(currentStrategy, 0, Double.NaN);

    int SIMPLICES = restricted.length;
    double[][] X = new double[SIMPLICES][SIMPLICES];
    double[] centroid = new double[SIMPLICES];
    double[] reflect = new double[SIMPLICES];
    double[] expand = new double[SIMPLICES];
    double[] contract = new double[SIMPLICES];
    double[] V = new double[SIMPLICES];
    double[] cur = distribution.clone();

    if (!randomize) {
        for (int s = 0; s < SIMPLICES; s++) {
            X[s][s] = 1.0;
            V[s] = calculateLagrangian(pm, X[s], restricted, distribution);
        }
    } else {
        for (int s = 0; s < SIMPLICES; s++) {
            generateSimplex(X[s]);
            V[s] = calculateLagrangian(pm, X[s], restricted, distribution);
        }
    }

    int highest = -1;
    int lowest = -1;
    int second = -1;

    for (int s = 0; s < SIMPLICES; s++) {
        if (highest < 0 || V[s] > V[highest]) {
            highest = s;
        }

        if (second < 0 || V[s] < V[second]) {

            if (lowest < 0 || V[s] < V[lowest]) {
                second = lowest;
                lowest = s;
            } else {
                second = s;
            }
        }
    }

    double curRegret = Double.POSITIVE_INFINITY;

    loop: for (int iteration = 1; SIMPLICES > 1; iteration++) {

        for (int r = 0; r < SIMPLICES - 1; r++) {
            centroid[r] = 0.0;

            for (int s = 0; s < SIMPLICES; s++) {
                if (s != highest) {
                    centroid[r] += X[s][r];
                }
            }

            centroid[r] /= SIMPLICES - 1.0;
        }

        for (int r = 0; r < SIMPLICES - 1; r++) {
            reflect[r] = 2 * centroid[r] - X[highest][r];
        }

        double reflectV = calculateLagrangian(pm, reflect, restricted, distribution);

        // Reflect
        if (V[lowest] <= reflectV && reflectV < V[second]) {
            System.arraycopy(reflect, 0, X[highest], 0, SIMPLICES - 1);
            V[highest] = reflectV;
        } else {

            boolean shrink = false;

            // Expand
            if (reflectV < V[lowest]) {
                for (int r = 0; r < SIMPLICES - 1; r++) {
                    expand[r] = centroid[r] + 2.0 * (reflect[r] - centroid[r]);
                }

                double expandV = calculateLagrangian(pm, expand, restricted, distribution);

                if (expandV < reflectV) {
                    System.arraycopy(expand, 0, X[highest], 0, SIMPLICES - 1);
                    V[highest] = expandV;
                } else {
                    System.arraycopy(reflect, 0, X[highest], 0, SIMPLICES - 1);
                    V[highest] = reflectV;
                }

                // Contract
            } else if (reflectV >= V[second]) {

                //Outside
                if (V[highest] > reflectV) {
                    for (int r = 0; r < SIMPLICES - 1; r++) {
                        contract[r] = centroid[r] + 0.5 * (reflect[r] - centroid[r]);
                    }
                    double contractV = calculateLagrangian(pm, contract, restricted, distribution);

                    if (contractV < reflectV) {
                        System.arraycopy(contract, 0, X[highest], 0, SIMPLICES - 1);
                        V[highest] = contractV;
                    } else {
                        shrink = true;
                    }

                    //Inside
                } else {
                    for (int r = 0; r < SIMPLICES - 1; r++) {
                        contract[r] = centroid[r] + 0.5 * (X[highest][r] - centroid[r]);
                    }

                    double contractV = calculateLagrangian(pm, contract, restricted, distribution);

                    if (contractV < V[highest]) {
                        System.arraycopy(contract, 0, X[highest], 0, SIMPLICES - 1);
                        V[highest] = contractV;
                    } else {
                        shrink = true;
                    }
                }

                // Shrink
                if (shrink) {
                    for (int s = 0; s < SIMPLICES; s++) {
                        if (s != lowest) {
                            for (int r = 0; r < SIMPLICES - 1; r++) {
                                X[s][r] = X[lowest][r] + 0.5 * (X[s][r] - X[lowest][r]);
                            }

                            V[s] = calculateLagrangian(pm, X[s], restricted, distribution);
                        }
                    }
                }
            }
        }

        highest = -1;
        lowest = -1;
        second = -1;

        for (int s = 0; s < SIMPLICES; s++) {
            if (highest < 0 || V[s] > V[highest]) {
                highest = s;
            }

            if (second < 0 || V[s] < V[second]) {

                if (lowest < 0 || V[s] < V[lowest]) {
                    second = lowest;
                    lowest = s;
                } else {
                    second = s;
                }
            }
        }

        Arrays.fill(cur, 0.0);
        double sum = 0.0;
        for (int r = 0; r < restricted.length - 1; r++) {
            cur[restricted[r]] = Math.max(0, X[lowest][r]);
            sum += cur[restricted[r]];
        }

        cur[restricted[restricted.length - 1]] = Math.max(0.0, 1 - sum);
        sum += cur[restricted[restricted.length - 1]];

        for (int r = 0; r < restricted.length; r++) {
            cur[restricted[r]] /= sum;
        }

        curRegret = pm.regret(cur);

        if (curRegret < bestRegret) {
            System.arraycopy(cur, 0, bestDist, 0, cur.length);
            bestRegret = curRegret;
        }

        // Build the new strategy
        currentStrategy = buildStrategy(actions, bestDist, restricted);

        fireUpdatedStrategy(currentStrategy, iteration, bestRegret);

        // Calculate the norm
        double norm = V[highest] - V[lowest];

        // Check termination condition
        if (terminate(norm, iteration))
            break;
    }

    return currentStrategy;
}

From source file:com.alibaba.citrus.util.internal.apache.lang.EqualsBuilderTests.java

public void testDouble() {
    double o1 = 1;
    double o2 = 2;
    assertTrue(new EqualsBuilder().append(o1, o1).isEquals());
    assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());
    assertTrue(!new EqualsBuilder().append(o1, Double.NaN).isEquals());
    assertTrue(new EqualsBuilder().append(Double.NaN, Double.NaN).isEquals());
    assertTrue(new EqualsBuilder().append(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY).isEquals());
}

From source file:com.clust4j.algo.NearestNeighbors.java

@Override
protected NearestNeighbors fit() {
    synchronized (fitLock) {

        if (null != res)
            return this;

        // CORNER! If k == m, we can't do kNeighbors + 1..
        int nNeighbors = FastMath.min(kNeighbors + 1, m); //kNeighbors + 1;
        final LogTimer timer = new LogTimer();

        // We can do parallel here!
        Neighborhood initRes = null;/* w  ww.j a  v  a2  s .co m*/
        if (parallel) {
            try {
                initRes = ParallelNNSearch.doAll(fit_X, this, nNeighbors);
            } catch (RejectedExecutionException r) {
                warn("parallel neighborhood search failed; falling back to serial query");
            }
        }

        // Gets here in serial mode or if parallel failed...
        if (null == initRes)
            initRes = new Neighborhood(tree.query(fit_X, nNeighbors, DUAL_TREE_SEARCH, SORT));
        info("queried " + this.alg + " for nearest neighbors in " + timer.toString());

        double[][] dists = initRes.getDistances();
        int[][] indices = initRes.getIndices();
        int i, j, ni = indices[0].length;

        // Set up sample range
        int[] sampleRange = VecUtils.arange(m);

        boolean allInRow, bval;
        boolean[] dupGroups = new boolean[m];
        boolean[][] sampleMask = new boolean[m][ni];
        for (i = 0; i < m; i++) {
            allInRow = true;

            for (j = 0; j < ni; j++) {
                bval = indices[i][j] != sampleRange[i];
                sampleMask[i][j] = bval;
                allInRow &= bval;
            }

            dupGroups[i] = allInRow; // duplicates in row?
        }

        // Comment from SKLEARN:
        // Corner case: When the number of duplicates are more
        // than the number of neighbors, the first NN will not
        // be the sample, but a duplicate.
        // In that case mask the first duplicate.
        // sample_mask[:, 0][dup_gr_nbrs] = False

        for (i = 0; i < m; i++)
            if (dupGroups[i])
                sampleMask[i][0] = false;

        // Build output indices
        int k = 0;
        int[] indOut = new int[m * (nNeighbors - 1)];
        double[] distOut = new double[m * (nNeighbors - 1)];
        for (i = 0; i < m; i++) {
            double minDist = Double.POSITIVE_INFINITY, maxDist = Double.NEGATIVE_INFINITY;

            for (j = 0; j < ni; j++) {
                if (sampleMask[i][j]) {
                    indOut[k] = indices[i][j];
                    distOut[k] = dists[i][j];

                    minDist = FastMath.min(dists[i][j], minDist);
                    maxDist = FastMath.max(dists[i][j], maxDist);

                    k++;
                }
            }

            fitSummary.add(new Object[] { i, minDist, maxDist, timer.wallTime() });
        }

        res = new Neighborhood(MatUtils.reshape(distOut, m, nNeighbors - 1),
                MatUtils.reshape(indOut, m, nNeighbors - 1));

        sayBye(timer);
        return this;
    }

}

From source file:jtrace.object.SceneObject.java

/**
 * Responsible for calculating first collision of ray with object,
 * returning the distance to this point from the origin of the ray.
 * Records the colliding and normal rays for future interrogation.
 * /*from   ww  w  . ja  v a  2s.  c om*/
 * @param ray incoming ray
 * @return distance from origin of ray to first intersection
 */
public double getFirstCollision(Ray ray) {
    double dist = getFirstCollisionObjectFrame(sceneToObjectRay(ray));

    if (dist > 0 && dist < Double.POSITIVE_INFINITY) {
        incidentRay = objectToSceneRay(incidentRay);
        normalRay = objectToSceneRay(normalRay);
    }

    return dist;
}

From source file:at.ac.tuwien.dsg.cloud.salsa.engine.smartdeployment.QUELLE.QuelleService.java

@POST
@Path("/recommend")
@Consumes(MediaType.APPLICATION_XML)/*from   www.j a v  a  2s  . co  m*/
@Produces(MediaType.APPLICATION_XML)
public Recommendations getRecommendation(MultiLevelRequirements multiLevelRequirements) {
    EngineLogger.logger
            .debug("Getting recommendation for multiple requirement: " + multiLevelRequirements.getName());

    List<MultiLevelRequirements> individualServiceUnitRequirements = multiLevelRequirements.flatten();
    List<ServiceUnitServicesRecommendation> recommendations = new ArrayList<>();

    // load cloud provider
    List<CloudProvider> cloudProviders = loadCloudAllDescription();
    EngineLogger.logger.debug("Loaded " + cloudProviders.size() + " provider done.");
    if (cloudProviders.isEmpty()) {
        EngineLogger.logger
                .error("Do not found any cloud provider infomation. Please submit at least one first !");
        return null;
    }

    for (MultiLevelRequirements reqs : individualServiceUnitRequirements) {
        RequirementsResolutionResult requirementsMatchingResult = requirementsMatchingEngine
                .analyzeMultiLevelRequirements(cloudProviders, reqs);
        Map<MultiLevelRequirements, Map<Requirements, List<ServiceUnitConfigurationSolution>>> bestElasticity = requirementsMatchingResult
                .getConcreteConfigurations(serviceUnitComparators);
        List<CloudServiceConfigurationRecommendation> recommendedConfigurations = new ArrayList<>();
        {
            for (MultiLevelRequirements levelRequirements : bestElasticity.keySet()) {
                Map<Requirements, List<ServiceUnitConfigurationSolution>> solutions = bestElasticity
                        .get(levelRequirements);
                String strategies = "";
                for (Strategy s : levelRequirements.getOptimizationStrategies()) {
                    strategies += "_" + s.getStrategyCategory();
                }

                for (Requirements requirements : solutions.keySet()) {
                    String solutionsNames = "";

                    int solutionsCount = solutions.get(requirements).size();

                    // compute average elasticities
                    double averageCostElasticity = 0d;
                    double averageSUElasticity = 0d;
                    double averageResourceElasticity = 0d;
                    double averageQualityElasticity = 0d;

                    double minCostElasticity = Double.POSITIVE_INFINITY;
                    double minSUElasticity = Double.POSITIVE_INFINITY;
                    double minResourceElasticity = Double.POSITIVE_INFINITY;
                    double minQualityElasticity = Double.POSITIVE_INFINITY;

                    double maxCostElasticity = Double.NEGATIVE_INFINITY;
                    double maxSUElasticity = Double.NEGATIVE_INFINITY;
                    double maxResourceElasticity = Double.NEGATIVE_INFINITY;
                    double maxQualityElasticity = Double.NEGATIVE_INFINITY;

                    for (ServiceUnitConfigurationSolution solutionConfiguration : solutions.get(requirements)) {

                        CloudServiceUnitAnalysisEngine cloudServiceElasticityAnalysisEngine = new CloudServiceUnitAnalysisEngine();
                        CloudServiceUnitAnalysisEngine.AnalysisResult analysisResult = cloudServiceElasticityAnalysisEngine
                                .analyzeElasticity(solutionConfiguration.getServiceUnit());
                        solutionsNames += " " + solutionConfiguration.getServiceUnit().getName();

                        double costElasticity = (Integer) analysisResult
                                .getValue(CloudServiceElasticityAnalysisEngine.COST_ELASTICITY);
                        double sUElasticity = (Integer) analysisResult.getValue(
                                CloudServiceElasticityAnalysisEngine.SERVICE_UNIT_ASSOCIATION_ELASTICITY);
                        double resourceElasticity = (Integer) analysisResult
                                .getValue(CloudServiceElasticityAnalysisEngine.RESOURCE_ELASTICITY);
                        double qualityElasticity = (Integer) analysisResult
                                .getValue(CloudServiceElasticityAnalysisEngine.QUALITY_ELASTICITY);

                        averageCostElasticity += costElasticity;
                        averageSUElasticity += sUElasticity;
                        averageResourceElasticity += resourceElasticity;
                        averageQualityElasticity += qualityElasticity;

                        if (minCostElasticity > costElasticity) {
                            minCostElasticity = costElasticity;
                        }

                        if (minSUElasticity > sUElasticity) {
                            minSUElasticity = sUElasticity;
                        }

                        if (minResourceElasticity > resourceElasticity) {
                            minResourceElasticity = resourceElasticity;
                        }

                        if (minQualityElasticity > qualityElasticity) {
                            minQualityElasticity = qualityElasticity;
                        }

                        if (maxCostElasticity < costElasticity) {
                            maxCostElasticity = costElasticity;
                        }

                        if (maxSUElasticity < sUElasticity) {
                            maxSUElasticity = sUElasticity;
                        }

                        if (maxResourceElasticity < resourceElasticity) {
                            maxResourceElasticity = resourceElasticity;
                        }

                        if (maxQualityElasticity < qualityElasticity) {
                            maxQualityElasticity = qualityElasticity;
                        }
                        recommendedConfigurations.add(new CloudServiceConfigurationRecommendation()
                                .withServiceUnitConfigurationSolution(requirements.getName(),
                                        solutionConfiguration, costElasticity, sUElasticity, resourceElasticity,
                                        qualityElasticity));

                        //                            ObjectMapper mapper = new ObjectMapper();
                        //                            System.out.println("solutionConfiguration" + mapper.writeValueAsString(solutionConfiguration));
                        //                            System.out.println("recommendedConfigurations: " + mapper.writeValueAsString(recommendedConfigurations));                            
                        recommendations.add(new ServiceUnitServicesRecommendation()
                                .withSolutionRecommendation(requirements, recommendedConfigurations));

                    }

                    //                        averageCostElasticity /= solutionsCount;
                    //                        averageSUElasticity /= solutionsCount;
                    //                        averageResourceElasticity /= solutionsCount;
                    //                        averageQualityElasticity /= solutionsCount;
                    //                        System.out.println(requirements.getName() + "," + strategies + "," + solutionsNames + "," + solutionsCount + "," + averageCostElasticity + ","
                    //                                + minCostElasticity + "," + maxCostElasticity + "," + averageSUElasticity + "," + minSUElasticity + "," + maxSUElasticity
                    //                                + "," + averageResourceElasticity + "," + minResourceElasticity + "," + maxResourceElasticity + ","
                    //                                + averageQualityElasticity + "," + minQualityElasticity + "," + maxQualityElasticity);
                    //                        System.out.println("\n");
                }

            }
        }
    }
    EngineLogger.logger.debug("Quelle recommendation is done, returning result ....");
    // wrapping
    return new Recommendations(recommendations);

    //        File saveAs = new File("/tmp/quelleresult");
    //        Writer result = new StringWriter();
    //        JAXBContext jaxbContext;
    //        try {
    //            jaxbContext = JAXBContext.newInstance(Recommendations.class);
    //            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    //            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    //            jaxbMarshaller.marshal(new Recommendations(recommendations), saveAs);
    //            
    //            jaxbMarshaller.marshal(new Recommendations(recommendations), result);
    //        } catch (JAXBException ex) {
    //            ex.printStackTrace();
    //        }             
    //        return result.toString();
}

From source file:com.inform.jamps.solver.gurobi.GurobiVariable.java

@Override
public String toString() {
    final StringBuilder sb = new StringBuilder(200);
    switch (type) {
    case BINARY://from w w w  . ja v  a2s  . c  om
        sb.append("Binary ");
        break;
    case CONTINUOUS:
        sb.append("Continuous ");
        break;
    case INTEGER:
        sb.append("Integer ");
        break;
    case SEMI_CONTINUOUS:
        sb.append("Semi-Continuous ");
        break;
    case SEMI_INTEGER:
        sb.append("Semi-Integer ");
        break;
    default:
        break;
    }
    sb.append(name);
    if (lowerBound > Double.NEGATIVE_INFINITY || upperBound < Double.POSITIVE_INFINITY) {
        if (Precision.equals(lowerBound, Double.NEGATIVE_INFINITY)) {
            sb.append(" (,");
        } else {
            sb.append(" [");
            sb.append(lowerBound);
            sb.append(',');
        }
        if (Precision.equals(upperBound, Double.POSITIVE_INFINITY)) {
            sb.append(')');
        } else {
            sb.append(' ');
            sb.append(upperBound);
            sb.append(']');
        }
    } else {
        sb.append(" (unbounded)");
    }
    return sb.toString();
}

From source file:ffx.xray.CCP4MapFilter.java

/**
 * {@inheritDoc}/*from w  w  w . j a va  2  s.  co m*/
 */
@Override
public boolean readFile(String filename, RealSpaceRefinementData refinementdata,
        CompositeConfiguration properties) {

    int imapdata;
    double cella, cellb, cellc, cellalpha, cellbeta, cellgamma;
    String stampstr;

    ByteOrder b = ByteOrder.nativeOrder();

    FileInputStream fis;
    DataInputStream dis;

    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    double mean = 0.0;
    double sd = 0.0;
    double rmsd = 0.0;

    // first determine byte order of file versus system
    try {
        fis = new FileInputStream(filename);
        dis = new DataInputStream(fis);

        dis.skipBytes(212);
        byte bytes[] = new byte[4];
        dis.read(bytes, 0, 4);
        ByteBuffer bb = ByteBuffer.wrap(bytes);

        imapdata = bb.order(ByteOrder.BIG_ENDIAN).getInt();
        stampstr = Integer.toHexString(imapdata);
        // System.out.println("stamp: " + stampstr);
        switch (stampstr.charAt(0)) {
        case '1':
        case '3':
            if (b.equals(ByteOrder.LITTLE_ENDIAN)) {
                b = ByteOrder.BIG_ENDIAN;
            }
            break;
        case '4':
            if (b.equals(ByteOrder.BIG_ENDIAN)) {
                b = ByteOrder.LITTLE_ENDIAN;
            }
            break;
        }

        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("\nOpening CCP4 map: %s\n", filename));
            sb.append(String.format("file type (machine stamp): %s\n", stampstr));
            logger.info(sb.toString());
        }

        fis.close();
    } catch (Exception e) {
        String message = "Fatal exception reading CCP4 map.\n";
        logger.log(Level.SEVERE, message, e);
        System.exit(-1);
    }

    try {
        fis = new FileInputStream(filename);
        dis = new DataInputStream(fis);

        byte bytes[] = new byte[2048];

        dis.read(bytes, 0, 1024);
        ByteBuffer bb = ByteBuffer.wrap(bytes);

        int ext[] = new int[3];
        ext[0] = bb.order(b).getInt();
        ext[1] = bb.order(b).getInt();
        ext[2] = bb.order(b).getInt();

        // mode (2 = reals, only one we accept)
        int mode = bb.order(b).getInt();

        int ori[] = new int[3];
        ori[0] = bb.order(b).getInt();
        ori[1] = bb.order(b).getInt();
        ori[2] = bb.order(b).getInt();

        int ni[] = new int[3];
        ni[0] = bb.order(b).getInt();
        ni[1] = bb.order(b).getInt();
        ni[2] = bb.order(b).getInt();

        cella = bb.order(b).getFloat();
        cellb = bb.order(b).getFloat();
        cellc = bb.order(b).getFloat();
        cellalpha = bb.order(b).getFloat();
        cellbeta = bb.order(b).getFloat();
        cellgamma = bb.order(b).getFloat();

        int axisi[] = new int[3];
        for (int i = 0; i < 3; i++) {
            int axis = bb.order(b).getInt();
            switch (axis) {
            case 1:
                axisi[0] = i;
                break;
            case 2:
                axisi[1] = i;
                break;
            case 3:
                axisi[2] = i;
                break;
            }
        }

        min = bb.order(b).getFloat();
        max = bb.order(b).getFloat();
        mean = bb.order(b).getFloat();

        int sg = bb.order(b).getInt();

        int nsymb = bb.order(b).getInt();

        int skew = bb.order(b).getInt();

        for (int i = 0; i < 12; i++) {
            bb.order(b).getFloat();
        }

        for (int i = 0; i < 15; i++) {
            bb.order(b).getInt();
        }

        byte word[] = new byte[2048];
        bb.order(b).get(word, 0, 4);
        String mapstr = new String(word);
        // System.out.println("MAP?: " + mapstr);

        sd = bb.order(b).getFloat();
        rmsd = bb.order(b).getFloat();

        /*
         System.out.println("col: " + ori[0] + " " + ext[0] + " " + ni[0]);
         System.out.println("row: " + ori[1] + " " + ext[1] + " " + ni[1]);
         System.out.println("sec: " + ori[2] + " " + ext[2] + " " + ni[2]);
         System.out.println("order: " + axisi[0] + " " + axisi[1] + " " + axisi[2]);
         System.out.println("min: " + min + " max: " + max + " mean: " + mean);
         System.out.println("sd: " + sd + " rmsd: " + rmsd);
         System.out.println("sg: " + sg);
         System.out.println("a: " + cella + " b: " + cellb + " c: " + cellc
         + " alpha: " + cellalpha + " beta: " + cellbeta + " gamma: " + cellgamma);
         */
        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("  column origin: %d extent: %d\n", ori[0], ext[0]));
            sb.append(String.format("  row origin: %d extent: %d\n", ori[1], ext[1]));
            sb.append(String.format("  section origin: %d extent: %d\n", ori[2], ext[2]));
            sb.append(String.format("  axis order: %d %d %d\n", axisi[0], axisi[1], axisi[2]));
            sb.append(String.format("  number of X, Y, Z columns: %d %d %d\n", ni[0], ni[1], ni[2]));
            sb.append(String.format("  spacegroup #: %d (name: %s)\n", sg, SpaceGroup.spaceGroupNames[sg - 1]));
            sb.append(String.format("  cell: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", cella, cellb, cellc,
                    cellalpha, cellbeta, cellgamma));
            logger.info(sb.toString());
        }

        int nlabel = bb.order(b).getInt();

        // System.out.println("nsymb: " + nsymb + " nlabel: " + nlabel);
        for (int i = 0; i < 10; i++) {
            bb.order(b).get(word, 0, 80);
            mapstr = new String(word);
            // System.out.println("label " + i + " : " + mapstr);
        }

        if (nsymb > 0) {
            bb.rewind();
            dis.read(bytes, 0, nsymb);
            for (int i = 0; i < nsymb / 80; i += 80) {
                bb.order(b).get(word, 0, 80);
                mapstr = new String(word);
                // System.out.println("symm: " + mapstr);
            }
        }

        bb.rewind();
        dis.read(bytes, 0, 2048);
        refinementdata.data = new double[ext[0] * ext[1] * ext[2]];
        int ijk[] = new int[3];
        int index, x, y, z;
        refinementdata.ori[0] = ori[axisi[0]];
        refinementdata.ori[1] = ori[axisi[1]];
        refinementdata.ori[2] = ori[axisi[2]];
        int nx = ext[axisi[0]];
        int ny = ext[axisi[1]];
        int nz = ext[axisi[2]];
        refinementdata.ext[0] = nx;
        refinementdata.ext[1] = ny;
        refinementdata.ext[2] = nz;
        refinementdata.ni[0] = ni[0];
        refinementdata.ni[1] = ni[1];
        refinementdata.ni[2] = ni[2];
        for (ijk[2] = 0; ijk[2] < ext[2]; ijk[2]++) {
            for (ijk[1] = 0; ijk[1] < ext[1]; ijk[1]++) {
                for (ijk[0] = 0; ijk[0] < ext[0]; ijk[0]++) {
                    x = ijk[axisi[0]];
                    y = ijk[axisi[1]];
                    z = ijk[axisi[2]];
                    index = x + nx * (y + ny * z);
                    refinementdata.data[index] = bb.order(b).getFloat();
                    if (!bb.hasRemaining()) {
                        bb.rewind();
                        dis.read(bytes, 0, 2048);
                    }
                }
            }
        }
        fis.close();
    } catch (Exception e) {
        String message = "Fatal exception reading CCP4 map.\n";
        logger.log(Level.SEVERE, message, e);
        System.exit(-1);
    }

    return true;
}

From source file:at.pcgamingfreaks.Bukkit.Utils.java

/**
 * Calculates the distance between two players
 *
 * @param player1 The first player/*w  w w . j av a 2s  .  c o m*/
 * @param player2 The second player
 * @return The distance between the two players in meter/blocks. Double.POSITIVE_INFINITY if they aren't in the same world.
 */
public static double getDistance(@NotNull Player player1, @NotNull Player player2) {
    Validate.notNull(player1, "None of the players can be null!");
    Validate.notNull(player2, "None of the players can be null!");
    if (player1.equals(player2)) {
        return 0;
    }
    if (player1.getWorld().getName().equalsIgnoreCase(player2.getWorld().getName())) {
        return player1.getLocation().distance(player2.getLocation());
    }
    return Double.POSITIVE_INFINITY;
}