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:net.sourceforge.cobertura.metrics.model.location.SourceLocation.java

/**
 * {@inheritDoc}/* w  w w .ja  v  a 2s . c om*/
 */
@Override
public int compareTo(final SourceLocation that) {

    // Check sanity
    if (that == null) {
        return Integer.MIN_VALUE;
    }
    if (that == this) {
        return 0;
    }

    // All done.
    return toString().compareTo(that.toString());
}

From source file:eu.stratosphere.api.java.record.io.CsvOutputFormat.java

@Override
public void configure(Configuration parameters) {
    super.configure(parameters);

    int configNumFields = parameters.getInteger(NUM_FIELDS_PARAMETER, -1);

    if (ctorInstantiation) {
        if (configNumFields > 0) {
            throw new IllegalStateException("CsvOutputFormat instantiated via both parameters and config.");
        }/* www .  j ava2s  .com*/
        return; //already configured, no further actions required
    }

    if (configNumFields < 1) {
        throw new IllegalStateException("CsvOutputFormat not configured via parameters or config.");
    }

    this.numFields = configNumFields;

    @SuppressWarnings("unchecked")
    Class<Value>[] arr = new Class[this.numFields];
    this.classes = arr;

    for (int i = 0; i < this.numFields; i++) {
        @SuppressWarnings("unchecked")
        Class<? extends Value> clazz = (Class<? extends Value>) parameters
                .getClass(FIELD_TYPE_PARAMETER_PREFIX + i, null);
        if (clazz == null) {
            throw new IllegalArgumentException(
                    "Invalid configuration for CsvOutputFormat: " + "No type class for parameter " + i);
        }

        this.classes[i] = clazz;
    }

    this.recordPositions = new int[this.numFields];
    boolean anyRecordPosDefined = false;
    boolean allRecordPosDefined = true;

    for (int i = 0; i < this.numFields; i++) {
        int pos = parameters.getInteger(RECORD_POSITION_PARAMETER_PREFIX + i, Integer.MIN_VALUE);
        if (pos != Integer.MIN_VALUE) {
            anyRecordPosDefined = true;
            if (pos < 0) {
                throw new IllegalArgumentException("Invalid configuration for CsvOutputFormat: "
                        + "Invalid record position for parameter " + i);
            }
            this.recordPositions[i] = pos;
        } else {
            allRecordPosDefined = false;
            this.recordPositions[i] = i;
        }
    }

    if (anyRecordPosDefined && !allRecordPosDefined) {
        throw new IllegalArgumentException("Invalid configuration for CsvOutputFormat: "
                + "Either none or all record positions must be defined.");
    }

    this.recordDelimiter = parameters.getString(RECORD_DELIMITER_PARAMETER,
            AbstractConfigBuilder.NEWLINE_DELIMITER);
    if (this.recordDelimiter == null) {
        throw new IllegalArgumentException("The delimiter in the DelimitedOutputFormat must not be null.");
    }
    this.charsetName = parameters.getString(RECORD_DELIMITER_ENCODING, null);
    this.fieldDelimiter = parameters.getString(FIELD_DELIMITER_PARAMETER, ",");
    this.lenient = parameters.getBoolean(LENIENT_PARSING, false);
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint.java

private int[] findMaxIndex(ArrayList<Integer> list) {
    int maxIndex = 0;
    int maxVal = Integer.MIN_VALUE;

    for (int i = 0; i < list.size(); i++) {
        if (list.get(i) > maxVal) {
            maxVal = list.get(i);//from w ww .j  av a2s.c  o m
            maxIndex = i;
        }
    }

    int[] ret = { maxIndex, maxVal };
    return ret;
}

From source file:edu.cmu.tetrad.search.TimeSeriesUtils.java

public static DataSet createShiftedData(DataSet data, int[] shifts) {
    TetradMatrix data2 = data.getDoubleData();

    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;

    for (int i1 = 0; i1 < shifts.length; i1++) {
        if (shifts[i1] < min)
            min = shifts[i1];// ww  w.j  a v a2 s. c  om
        if (shifts[i1] > max)
            max = shifts[i1];
    }

    int shiftRange = max - min;

    int[] _shifts = new int[shifts.length];

    for (int i = 0; i < shifts.length; i++) {
        _shifts[i] = shiftRange - (shifts[i] - min);
    }

    if (shiftRange > data2.rows()) {
        throw new IllegalArgumentException("Range of shifts greater than sample size.");
    }

    int shiftedDataLength = data2.rows() - shiftRange;
    TetradMatrix shiftedData = new TetradMatrix(shiftedDataLength, data2.columns());

    for (int j = 0; j < shiftedData.columns(); j++) {
        for (int i = 0; i < shiftedDataLength; i++) {
            shiftedData.set(i, j, data2.get(i + _shifts[j], j));
        }
    }

    return ColtDataSet.makeContinuousData(data.getVariables(), shiftedData);
}

From source file:io.hops.metadata.util.HopYarnAPIUtilities.java

/**
 * Sets new value for yarn variable and returns old one to be used by
 * application. Fetches multiple PKs from db to memory. It first tries to
 * return a PK from memory and if no PK is available, it fetces another
 * batch from NDB. This is done to avoid going to the DB every time a PK is
 * needed.//from  ww w.ja  v  a 2 s  . co  m
 *
 * @param type
 * @return
 */
public synchronized static int setYarnVariablesWithThreshold(final int type) {
    //If we have available PK in availableIDs, fetch it from memory
    //Else allocate more ids from database
    int id = availableIDs.get(type);
    if (id % YARN_VARIABLES_UPDATE_THRESHOLD != 0) {
        availableIDs.put(type, id + 1);
        LOG.debug("HOP :: return yarnVariable of type:" + type + ", val:" + id);
        return id;
    }
    LightWeightRequestHandler setYarnVariablesHandler = new LightWeightRequestHandler(YARNOperationType.TEST) {
        @Override
        public Object performTask() throws IOException {
            connector.beginTransaction();
            connector.writeLock();
            LOG.debug("HOP :: setYarnVariables Start-" + System.currentTimeMillis());
            YarnVariablesDataAccess yDA = (YarnVariablesDataAccess) YarnAPIStorageFactory
                    .getDataAccess(YarnVariablesDataAccess.class);
            YarnVariables found = (YarnVariables) yDA.findById(type);
            //If found was null just try to retrieve it again
            int counter = 1;
            while (found == null && counter < 5) {
                try {
                    LOG.info("HOP :: Retrying setYarnVariables=" + counter);
                    found = (YarnVariables) yDA.findById(type);
                    counter++;
                    Thread.sleep(20);
                } catch (Exception ex) {
                    LOG.error("HOP :: yarnVariable was null 2", ex);
                }
            }
            if (found != null) {
                availableIDs.put(type, found.getValue() + 1);
                int toReturn = found.getValue();
                found.setValue(found.getValue() + YARN_VARIABLES_UPDATE_THRESHOLD);
                yDA.add(found);
                connector.commit();
                LOG.debug("HOP :: setYarnVariables Finish-" + System.currentTimeMillis());
                return toReturn;
            }
            return null;

        }
    };
    try {
        return (Integer) setYarnVariablesHandler.handle();
    } catch (IOException ex) {
        LOG.error("Error setting YarnVariables", ex);
    }
    return Integer.MIN_VALUE;
}

From source file:hk.hku.cecid.ebms.admin.listener.PartnershipPageletAdaptor.java

/**
 * @param request/*from   www. j  a  v a2s.  c om*/
 * @throws DAOException
 * @throws IOException
 */
private void updatePartnership(Hashtable ht, HttpServletRequest request, PropertyTree dom)
        throws DAOException, IOException {

    // get the parameters
    String requestAction = (String) ht.get("request_action");

    String partnershipId = (String) ht.get("partnership_id");
    String cpaId = (String) ht.get("cpa_id");
    String service = (String) ht.get("service");
    String action = (String) ht.get("action_id");

    String transportEndpoint = (String) ht.get("transport_endpoint");
    String isHostnameVerified = (String) ht.get("is_hostname_verified");
    String syncReplyMode = (String) ht.get("sync_reply_mode");
    String ackRequested = (String) ht.get("ack_requested");
    String ackSignRequested = (String) ht.get("ack_sign_requested");
    String dupElimination = (String) ht.get("dup_elimination");
    String messageOrder = (String) ht.get("message_order");

    String disabled = (String) ht.get("disabled");
    String retries = (String) ht.get("retries");
    String retryInterval = (String) ht.get("retry_interval");

    String signRequested = (String) ht.get("sign_requested");
    String encryptRequested = (String) ht.get("encrypt_requested");

    boolean hasEncryptCert = ht.get("encrypt_cert") != null;
    InputStream encryptCertInputStream = null;
    if (hasEncryptCert) {
        encryptCertInputStream = (InputStream) ht.get("encrypt_cert");
    }
    boolean hasRemoveEncryptCert = false;
    if (ht.get("encrypt_cert_remove") != null) {
        if (((String) ht.get("encrypt_cert_remove")).equalsIgnoreCase("on")) {
            hasRemoveEncryptCert = true;
        }
    }
    boolean hasVerifyCert = ht.get("verify_cert") != null;
    InputStream verifyCertInputStream = null;
    if (hasVerifyCert) {
        verifyCertInputStream = (InputStream) ht.get("verify_cert");
    }
    boolean hasRemoveVerifyCert = false;
    if (ht.get("verify_cert_remove") != null) {
        if (((String) ht.get("verify_cert_remove")).equalsIgnoreCase("on")) {
            hasRemoveVerifyCert = true;
        }
    }

    if ("add".equalsIgnoreCase(requestAction) || "update".equalsIgnoreCase(requestAction)
            || "delete".equalsIgnoreCase(requestAction)) {

        // validate and set to dao
        PartnershipDAO partnershipDAO = (PartnershipDAO) EbmsProcessor.core.dao.createDAO(PartnershipDAO.class);
        PartnershipDVO partnershipDVO = (PartnershipDVO) partnershipDAO.createDVO();

        partnershipDVO.setPartnershipId(partnershipId);

        if ("update".equalsIgnoreCase(requestAction)) {
            partnershipDAO.retrieve(partnershipDVO);
        }

        partnershipDVO.setCpaId(cpaId);
        partnershipDVO.setService(service);
        partnershipDVO.setAction(action);
        partnershipDVO.setTransportEndpoint(transportEndpoint);
        partnershipDVO.setIsHostnameVerified(isHostnameVerified);
        partnershipDVO.setSyncReplyMode(syncReplyMode);
        partnershipDVO.setAckRequested(ackRequested);
        partnershipDVO.setAckSignRequested(ackSignRequested);
        partnershipDVO.setDupElimination(dupElimination);
        partnershipDVO.setActor(null);
        partnershipDVO.setDisabled(disabled);
        partnershipDVO.setRetries(StringUtilities.parseInt(retries));
        partnershipDVO.setRetryInterval(StringUtilities.parseInt(retryInterval));
        partnershipDVO.setPersistDuration(null);
        partnershipDVO.setMessageOrder(messageOrder);
        partnershipDVO.setSignRequested(signRequested);
        partnershipDVO.setDsAlgorithm(null);
        partnershipDVO.setMdAlgorithm(null);
        partnershipDVO.setEncryptRequested(encryptRequested);
        partnershipDVO.setEncryptAlgorithm(null);

        if ("add".equalsIgnoreCase(requestAction)) {
            getPartnership(partnershipDVO, dom, "add_partnership/");
        }

        if (!cpaId.equals("")) {
            partnershipDVO.setCpaId(cpaId);
        } else {
            request.setAttribute(ATTR_MESSAGE, "CPA ID cannot be empty");
            return;
        }

        if (!service.equals("")) {
            partnershipDVO.setService(service);
        } else {
            request.setAttribute(ATTR_MESSAGE, "Service cannot be empty");
            return;
        }

        if (!action.equals("")) {
            partnershipDVO.setAction(action);
        } else {
            request.setAttribute(ATTR_MESSAGE, "Action cannot be empty");
            return;
        }

        URL transportEndpointURL = null;
        try {
            transportEndpointURL = new URL(transportEndpoint);
        } catch (Exception e) {
            request.setAttribute(ATTR_MESSAGE, "Transport Endpoint is invalid");
            return;
        }
        if (transportEndpointURL.getProtocol().equalsIgnoreCase("mailto")) {
            partnershipDVO.setTransportProtocol("smtp");
        } else if (transportEndpointURL.getProtocol().equalsIgnoreCase("http")
                || transportEndpointURL.getProtocol().equalsIgnoreCase("https")) {
            partnershipDVO.setTransportProtocol(transportEndpointURL.getProtocol());
        } else {
            request.setAttribute(ATTR_MESSAGE, "The endpoint protocol does not support");
            return;
        }

        if (partnershipDVO.getRetries() == Integer.MIN_VALUE) {
            request.setAttribute(ATTR_MESSAGE, "Retries must be integer");
            return;
        }
        if (partnershipDVO.getRetryInterval() == Integer.MIN_VALUE) {
            request.setAttribute(ATTR_MESSAGE, "Retry Interval must be integer");
            return;
        }

        // encrypt cert
        if (hasRemoveEncryptCert) {
            partnershipDVO.setEncryptCert(null);
        }
        if (hasEncryptCert) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOHandler.pipe(encryptCertInputStream, baos);
                CertificateFactory.getInstance("X.509")
                        .generateCertificate(new ByteArrayInputStream(baos.toByteArray()));
                partnershipDVO.setEncryptCert(baos.toByteArray());
            } catch (Exception e) {
                request.setAttribute(ATTR_MESSAGE, "Uploaded encrypt cert is not an X.509 cert");
                return;
            }
        }

        // verify cert
        if (hasRemoveVerifyCert) {
            partnershipDVO.setSignCert(null);
        }
        if (hasVerifyCert) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOHandler.pipe(verifyCertInputStream, baos);
                CertificateFactory.getInstance("X.509")
                        .generateCertificate(new ByteArrayInputStream(baos.toByteArray()));
                partnershipDVO.setSignCert(baos.toByteArray());
            } catch (Exception e) {
                request.setAttribute(ATTR_MESSAGE, "Uploaded verify cert is not an X.509 cert");
                return;
            }
        }

        // check partnership conflict
        if (!Boolean.valueOf(partnershipDVO.getDisabled()).booleanValue()) {
            Iterator allConflictDAOData = partnershipDAO.findPartnershipsByCPA(partnershipDVO).iterator();
            while (allConflictDAOData.hasNext()) {
                PartnershipDVO conflictDAOData = (PartnershipDVO) allConflictDAOData.next();
                if (conflictDAOData != null
                        && !conflictDAOData.getPartnershipId().equals(partnershipDVO.getPartnershipId())
                        && !Boolean.valueOf(conflictDAOData.getDisabled()).booleanValue()) {
                    request.setAttribute(ATTR_MESSAGE, "Partnership '" + conflictDAOData.getPartnershipId()
                            + "' with same combination of CPA ID, Service and Action has already been enabled");
                    return;
                }
            }
        }

        // dao action
        if ("add".equalsIgnoreCase(requestAction)) {
            partnershipDAO.create(partnershipDVO);
            request.setAttribute(ATTR_MESSAGE, "Partnership added successfully");
            dom.removeProperty("/partnerships/add_partnership");
            dom.setProperty("/partnerships/add_partnership", "");
        }
        if ("update".equalsIgnoreCase(requestAction)) {
            partnershipDAO.persist(partnershipDVO);
            request.setAttribute(ATTR_MESSAGE, "Partnership updated successfully");
        }
        if ("delete".equalsIgnoreCase(requestAction)) {

            partnershipDAO.remove(partnershipDVO);
            request.setAttribute(ATTR_MESSAGE, "Partnership deleted successfully");
        }

    }
}

From source file:coria2015.server.JsonRPCMethods.java

void handleJSON(JSONObject object) {
        String requestID = null;//from  w  w w .j av a2 s. c  o  m

        try {
            requestID = object.get("id").toString();
            if (requestID == null)
                throw new RuntimeException("No id in JSON request");

            Object command = object.get("method");
            if (command == null)
                throw new RuntimeException("No method in JSON");

            if (!object.containsKey("params"))
                throw new RuntimeException("No params in JSON");
            Object p = object.get("params");

            Collection<MethodDescription> candidates = methods.get(command.toString());
            int max = Integer.MIN_VALUE;
            MethodDescription argmax = null;
            for (MethodDescription candidate : candidates) {
                int score = Integer.MAX_VALUE;
                for (int i = 0; i < candidate.types.length && score > max; i++) {
                    score = convert(p, candidate, score, null, i);
                }
                if (score > max) {
                    max = score;
                    argmax = candidate;
                }
            }

            if (argmax == null)
                throw new RuntimeException("Cannot find a matching method");

            Object[] args = new Object[argmax.arguments.length];
            for (int i = 0; i < args.length; i++) {
                int score = convert(p, argmax, 0, args, i);
                assert score > Integer.MIN_VALUE;
            }
            Object result = argmax.method.invoke(this, args);
            mos.endMessage(requestID, result);
        } catch (Throwable t) {
            LOGGER.warning("Error while handling JSON request");
            try {
                while (t.getCause() != null)
                    t = t.getCause();
                mos.error(requestID, 1, t.getMessage());
            } catch (IOException e) {
                LOGGER.severe("Could not send the return code");
            }
            return;
        }
    }

From source file:de.tudarmstadt.ukp.dkpro.wsd.si.uby.UbySenseInventory.java

@Override
public String getMostFrequentSense(String sod, POS pos)
        throws SenseInventoryException, UnsupportedOperationException {
    // TODO: Implement a cache as this operation is expensive

    List<LexicalEntry> entries = getLexicalEntriesByPOS(sod.replace('_', ' '), pos);
    Sense mostFrequentSense = null;//from w w  w .  j  av a 2s.  c o  m
    int maxFrequency = Integer.MIN_VALUE;
    for (LexicalEntry lexicalEntry : entries) {
        for (Sense sense : lexicalEntry.getSenses()) {
            int senseFrequency = 0;
            boolean foundFrequencies = false;

            // Sum frequencies over all corpora and generators
            for (Frequency frequency : sense.getFrequencies()) {
                senseFrequency += frequency.getFrequency();
                foundFrequencies = true;
            }
            if (foundFrequencies && senseFrequency > maxFrequency) {
                maxFrequency = senseFrequency;
                mostFrequentSense = sense;
            }
        }
    }

    if (mostFrequentSense != null) {
        return mostFrequentSense.getId();
    } else {
        return null;
    }
}

From source file:com.tesora.dve.common.DBHelper.java

/**
 * @param query/*from   ww  w  . j  av a  2 s.co  m*/
 *            The query to run
 * @return <b>true</b> if the first result is a ResultSet object;
 *         <b>false</b> if it is an update count or there are no results
 * @throws SQLException
 */
public boolean executeQuery(String query) throws SQLException {
    closeStatement();

    checkConnected();

    if (logger.isDebugEnabled())
        logger.debug("ExecuteQuery '" + query + "' on " + getUrl());

    stmt = connection.createStatement();
    lastInsertID = 0L;

    if (isEnableResultSetStreaming()) {
        stmt.setFetchSize(Integer.MIN_VALUE);
    }
    boolean ret = stmt.execute(query, Statement.RETURN_GENERATED_KEYS);

    if (!ret) {
        // when stmt.execute returns false it means no result set is
        // expected get the number of rows affected
        rowCount = stmt.getUpdateCount();

        printLine(rowCount + " rows affected");

        ResultSet rs = stmt.getGeneratedKeys();
        if (rs.next()) {
            lastInsertID = rs.getLong(1);
        }
    } else {
        // a stmt returning a result set was run
        resultSet = stmt.getResultSet();
        if (useBufferedQuery)
            resultSet.setFetchSize(Integer.MAX_VALUE);
    }
    return ret;
}

From source file:com.demandware.vulnapp.util.Helpers.java

/**
 * safely transforms a long to an Integer. If the value is greater than 
 * int max, it is set to int max, if less than int min, it is set to int min,
 * otherwise it is directly cast./*from w  ww  .  j  av  a  2 s.  c o m*/
 */
public static int safeCastToInt(long longVal) {
    int intVal = 0;
    if (longVal < Integer.MIN_VALUE) {
        intVal = Integer.MIN_VALUE;
    } else if (longVal > Integer.MAX_VALUE) {
        intVal = Integer.MAX_VALUE;
    } else {
        intVal = (int) longVal;
    }
    return intVal;
}