Example usage for java.lang Integer MIN_VALUE

List of usage examples for java.lang Integer MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Integer MIN_VALUE.

Prototype

int MIN_VALUE

To view the source code for java.lang Integer MIN_VALUE.

Click Source Link

Document

A constant holding the minimum value an int can have, -231.

Usage

From source file:com.chiorichan.util.ObjectUtil.java

public static int safeLongToInt(long l) {
    if (l < Integer.MIN_VALUE)
        return Integer.MIN_VALUE;
    if (l > Integer.MAX_VALUE)
        return Integer.MAX_VALUE;
    return (int) l;
}

From source file:com.rockhoppertech.music.Pattern.java

public static int max(int[] values) {
    int max = Integer.MIN_VALUE;
    for (int i : values) {
        if (i > max)
            max = i;// w  w  w  .  j av  a 2  s .  c  om
    }
    return max;

}

From source file:com.trendrr.oss.networking.strest.StrestHeaders.java

private static int hash(String name) {
    int h = 0;//from   w w  w  .  ja v  a2s .  c o m
    for (int i = name.length() - 1; i >= 0; i--) {
        char c = name.charAt(i);
        if (c >= 'A' && c <= 'Z') {
            c += 32;
        }
        h = 31 * h + c;
    }

    if (h > 0) {
        return h;
    } else if (h == Integer.MIN_VALUE) {
        return Integer.MAX_VALUE;
    } else {
        return -h;
    }
}

From source file:com.application.utils.ApplicationLoader.java

private String getRegistrationId() {
    final SharedPreferences prefs = getGCMPreferences(applicationContext);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.length() == 0) {
        Log.i(TAG, "Registration not found.");
        return "";
    }//from   w w w. ja v a2 s .com
    int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int currentVersion = getAppVersion();
    if (registeredVersion != currentVersion) {
        Log.i(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}

From source file:NumberUtils.java

/**
 * Convert the given number into an instance of the given target class.
 * @param number the number to convert/*from  w  w w  .j  av  a 2  s  . c  om*/
 * @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() + "]");
    }
}

From source file:fr.immotronic.ubikit.pems.smartbuilding.impl.node.DimmerNodeImpl.java

@Override
public int getBrightness() {
    if (isLocal()) {
        switch (getPemLocalID()) {
        case ENOCEAN:

            if (ap != null) {
                switch (ap) {
                case ONOFF_DEVICE:
                    return Integer.MIN_VALUE;

                default:
                    break;
                }//  ww w. j a v a2 s.  co m
            }

            if (sap != null) {
                switch (sap) {
                case EEP_D2_01_02:
                    EEPD201xxData data = (EEPD201xxData) getActualNodeValue();
                    if (data == null)
                        return Integer.MIN_VALUE;

                    return data.getDimmerValue();
                default:
                    break;
                }
            }
            break;
        }
    }
    return Integer.MIN_VALUE;
}

From source file:cubicchunks.lighting.FirstLightProcessor.java

/**
 * Diffuses skylight in the given cube and all cubes affected by this update.
 *
 * @param cube the cube whose skylight is to be initialized
 */// ww  w  .  j a v  a  2  s. com
public void diffuseSkylight(Cube cube) {
    if (cube.getCubicWorld().getProvider().getHasNoSky()) {
        cube.setInitialLightingDone(true);
        return;
    }
    ICubicWorld world = cube.getCubicWorld();

    // Cache min/max Y, generating them may be expensive
    int[][] minBlockYArr = new int[16][16];
    int[][] maxBlockYArr = new int[16][16];

    int minBlockX = cubeToMinBlock(cube.getX());
    int maxBlockX = cubeToMaxBlock(cube.getX());

    int minBlockZ = cubeToMinBlock(cube.getZ());
    int maxBlockZ = cubeToMaxBlock(cube.getZ());

    // Determine the block columns that require updating. If there is nothing to update, store contradicting data so
    // we can skip the column later.
    for (int localX = 0; localX <= Cube.SIZE - 1; ++localX) {
        for (int localZ = 0; localZ <= Cube.SIZE - 1; ++localZ) {
            Pair<Integer, Integer> minMax = getMinMaxLightUpdateY(cube, localX, localZ);
            minBlockYArr[localX][localZ] = minMax == null ? Integer.MAX_VALUE : minMax.getLeft();
            maxBlockYArr[localX][localZ] = minMax == null ? Integer.MIN_VALUE : minMax.getRight();
        }
    }

    Int2ObjectMap<FastCubeBlockAccess> blockAccessMap = new Int2ObjectOpenCustomHashMap<>(10, 0.75f,
            CUBE_Y_HASH);

    Column column = cube.getColumn();
    for (int blockX = minBlockX; blockX <= maxBlockX; blockX++) {
        for (int blockZ = minBlockZ; blockZ <= maxBlockZ; blockZ++) {

            this.mutablePos.setPos(blockX, this.mutablePos.getY(), blockZ);
            int minBlockY = minBlockYArr[blockX - minBlockX][blockZ - minBlockZ];
            int maxBlockY = maxBlockYArr[blockX - minBlockX][blockZ - minBlockZ];

            // If no update is needed, skip the block column.
            if (minBlockY > maxBlockY) {
                continue;
            }

            int topBlockY = getOcclusionHeight(column, blockToLocal(blockX), blockToLocal(blockZ));

            // Iterate over all affected cubes.
            Iterable<Cube> cubes = column.getLoadedCubes(blockToCube(maxBlockY), blockToCube(minBlockY));
            for (Cube otherCube : cubes) {
                int cubeY = otherCube.getY();

                if (otherCube != cube && canStopUpdating(cube, this.mutablePos, topBlockY)) {
                    break;
                }

                if (otherCube != cube && !cube.isInitialLightingDone()) {
                    continue;
                }

                // Skip this cube if an update is not possible.
                if (!canUpdateCube(otherCube)) {
                    int minScheduledY = Math.max(cubeToMinBlock(cubeY), minBlockY);
                    int maxScheduledY = Math.min(cubeToMaxBlock(cubeY), maxBlockY);

                    // Queue the update to be processed once the cube is ready for it.
                    world.getLightingManager().queueDiffuseUpdate(otherCube, this.mutablePos.getX(),
                            this.mutablePos.getZ(), minScheduledY, maxScheduledY);
                    continue;
                }

                // Update the block column in this cube.
                if (!diffuseSkylightInBlockColumn(otherCube, this.mutablePos, minBlockY, maxBlockY,
                        blockAccessMap)) {
                    throw new IllegalStateException("Check light failed at " + this.mutablePos + "!");
                }
            }
        }
    }
    cube.setInitialLightingDone(true);
}

From source file:org.openremote.controller.protocol.http.HttpGetCommand.java

private int resolveRangeMinimum(String min) {
    if (min == null || min.equals("")) {
        return Integer.MIN_VALUE;
    }/*from www  . ja va  2 s  .  c om*/

    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:com.ericsson.deviceaccess.spi.impl.GenericDeviceServiceImplTest.java

@Before
public void setup() throws Exception {
    action = context.mock(GDAction.class);
    eventManager = context.mock(EventManager.class);
    device = context.mock(GenericDeviceImpl.class);
    metadataFloat = context.mock(GDPropertyMetadata.class, "metadataFloat");
    metadataInt = context.mock(GDPropertyMetadata.class, "metadataInt");
    metadataString = context.mock(GDPropertyMetadata.class, "metadataString");
    metadataArr = new ArrayList<>();
    metadataArr.add(metadataFloat);//from w w  w .  j a va2s .c  o m
    metadataArr.add(metadataInt);
    metadataArr.add(metadataString);
    ReflectionTestUtil.setField(GDActivator.class, "eventManager", eventManager);

    context.checking(new Expectations() {
        {
            allowing(device).getId();
            will(returnValue("devId"));
            allowing(device).getURN();
            will(returnValue("devUrn"));
            allowing(device).getName();
            will(returnValue("dev"));
            allowing(device).getProtocol();
            will(returnValue("prot"));
            allowing(device).isOnline();
            will(returnValue(true));

            allowing(metadataFloat).getDefaultNumberValue();
            will(returnValue(42.0f));
            allowing(metadataFloat).getDefaultStringValue();
            will(returnValue("42.0"));
            allowing(metadataFloat).getName();
            will(returnValue("fProp"));
            allowing(metadataFloat).getType();
            will(returnValue(Float.class));
            allowing(metadataFloat).getTypeName();
            will(returnValue("Float"));
            allowing(metadataFloat).getValidValues();
            will(returnValue(null));
            allowing(metadataFloat).getMinValue();
            will(returnValue(Float.NEGATIVE_INFINITY));
            allowing(metadataFloat).getMaxValue();
            will(returnValue(Float.POSITIVE_INFINITY));
            allowing(metadataFloat).serialize(Format.JSON);
            will(returnValue("{\"type\":\"float\"}"));

            allowing(metadataInt).getDefaultNumberValue();
            will(returnValue(42));
            allowing(metadataInt).getDefaultStringValue();
            will(returnValue("42"));
            allowing(metadataInt).getName();
            will(returnValue("iProp"));
            allowing(metadataInt).getType();
            will(returnValue(Integer.class));
            allowing(metadataInt).getTypeName();
            will(returnValue("Integer"));
            allowing(metadataInt).getValidValues();
            will(returnValue(null));
            allowing(metadataInt).getMinValue();
            will(returnValue(Integer.MIN_VALUE));
            allowing(metadataInt).getMaxValue();
            will(returnValue(Integer.MAX_VALUE));
            allowing(metadataInt).serialize(Format.JSON);
            will(returnValue("{\"type\":\"int\"}"));

            allowing(metadataString).getDefaultNumberValue();
            will(returnValue(null));
            allowing(metadataString).getDefaultStringValue();
            will(returnValue("Forty-two"));
            allowing(metadataString).getName();
            will(returnValue("sProp"));
            allowing(metadataString).getType();
            will(returnValue(String.class));
            allowing(metadataString).getTypeName();
            will(returnValue("String"));
            allowing(metadataString).getValidValues();
            will(returnValue(null));
            allowing(metadataString).getMinValue();
            will(returnValue(null));
            allowing(metadataString).getMaxValue();
            will(returnValue(null));
            allowing(metadataString).serialize(Format.JSON);
            will(returnValue("{\"type\":\"string\"}"));

            allowing(action).getName();
            will(returnValue("action1"));
            allowing(action).updatePath(with(aNonNull(String.class)));
            allowing(action).getArgumentsMetadata();
            will(returnValue(new HashMap<>()));
            allowing(action).getResultMetadata();
            will(returnValue(new HashMap<>()));
        }
    });

    service = new GDServiceImpl("srv", metadataArr);
    service.setParentDevice(device);
    service.putAction(action);

    props = new GDPropertiesImpl(metadataArr, service);
}

From source file:com.grantingersoll.intell.clustering.KMeansClusteringEngine.java

@Override
public NamedList cluster(SolrParams params) {
    NamedList result = new NamedList();
    //check to see if we have new results
    try {//from  w  w w  . ja v a2s  . c om
        if (theFuture != null) {
            //see if we have new results, but don't wait too long for them
            ClusterJob job = theFuture.get(1, TimeUnit.MILLISECONDS);
            if (lastSuccessful != null) {
                //clean up the old ones
                //TODO: clean up the old dirs before switching lastSuccessful
            }
            lastSuccessful = job;
            theFuture = null;
        } else {

        }

    } catch (InterruptedException e) {
        log.error("Exception", e);
    } catch (ExecutionException e) {
        log.error("Exception", e);
    } catch (TimeoutException e) {
        log.error("Exception", e);
    }
    if (lastSuccessful != null) {//we have clusters
        //do we need the points?
        boolean includePoints = params.getBool(INCLUDE_POINTS, false);
        int clusterId = params.getInt(LIST_POINTS, Integer.MIN_VALUE);
        Map<Integer, List<String>> toPoints = lastSuccessful.clusterIdToPoints;
        String docId = params.get(IN_CLUSTER);
        if ((includePoints || clusterId != Integer.MIN_VALUE || docId != null) && toPoints == null) {
            //load the points
            try {
                toPoints = readPoints(new Path(lastSuccessful.jobDir + File.separator + "points"),
                        lastSuccessful.conf);
            } catch (IOException e) {
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                        "Unable to load points: " + lastSuccessful);
            }
        }
        if (params.getBool(LIST_CLUSTERS)) {
            NamedList nl = new NamedList();
            result.add("all", nl);

            Map<Integer, Cluster> clusterMap = lastSuccessful.clusters;
            if (clusterMap == null) {
                //we aren't caching, so load 'em up
                try {
                    clusterMap = loadClusters(lastSuccessful);
                } catch (Exception e) {
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                            "unable to load the clusters from " + lastSuccessful);
                }
            }

            for (Cluster cluster : clusterMap.values()) {
                NamedList clusterNL = new NamedList();
                nl.add(String.valueOf(cluster.getId()), clusterNL);
                clusterNL.add("numPoints", cluster.getNumPoints());
                //TODO: better format?
                clusterNL.add("center", cluster.getCenter().asFormatString());
                if (cluster.getRadius() != null) {
                    clusterNL.add("radius", cluster.getRadius().asFormatString());
                }
                if (includePoints) {
                    List<String> points = toPoints.get(cluster.getId());
                    clusterNL.add("points", points);
                }
            }
        }

        if (docId != null) {

        }
        //TODO: support sending in multiple ids

        if (clusterId != Integer.MIN_VALUE) {
            List<String> points = lastSuccessful.clusterIdToPoints.get(clusterId);
            if (points != null) {
                result.add(String.valueOf(clusterId), points);
            }
        }
    } else if (params.getBool(BUILD, false)) {
        RefCounted<SolrIndexSearcher> refCnt = core.getSearcher();
        int theK = params.getInt(K, 10);
        cluster(refCnt.get(), theK);
        refCnt.decref();
    }
    return result;
}