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.redhat.lightblue.ResponseTest.java

@Test
public void testToJson() {
    response.setStatus(OperationStatus.COMPLETE);
    response.setModifiedCount(Integer.MAX_VALUE);
    response.setMatchCount(Integer.MIN_VALUE);
    response.setTaskHandle("taskHandle");
    response.setSessionInfo(null);//from  w  ww  .  ja  v a 2  s.  c o  m
    response.setEntityData(JsonObject.getFactory().objectNode());
    response.getDataErrors().addAll(getPopulatedDataErrors(3));
    response.getErrors().addAll(getPopulatedErrors(3));

    ObjectNode expectedNode = JsonObject.getFactory().objectNode();
    expectedNode.put("status", OperationStatus.COMPLETE.name().toLowerCase());
    expectedNode.put("modifiedCount", Integer.MAX_VALUE);
    expectedNode.put("matchCount", Integer.MIN_VALUE);
    expectedNode.put("taskHandle", "taskHandle");
    expectedNode.set("session", JsonObject.getFactory().objectNode());
    expectedNode.set("entityData", JsonObject.getFactory().objectNode());
    ArrayNode arr = JsonObject.getFactory().arrayNode();
    expectedNode.set("dataErrors", arr);
    for (DataError err : getPopulatedDataErrors(3)) {
        arr.add(err.toJson());
    }

    ArrayNode arr2 = JsonObject.getFactory().arrayNode();
    expectedNode.set("errors", arr2);
    for (Error err : getPopulatedErrors(3)) {
        arr2.add(err.toJson());
    }

    assertFalse(response.toJson().equals(expectedNode));
}

From source file:de.walware.statet.r.core.rsource.ast.FCall.java

@Override
final void updateStopOffset() {
    if (fArgsCloseOffset != Integer.MIN_VALUE) {
        fStopOffset = fArgsCloseOffset + 1;
    } else {/*from   w  w  w  .  j  a v  a 2 s  . c om*/
        fStopOffset = fArgs.fStopOffset;
    }
}

From source file:edu.ku.brc.specify.toycode.mexconabio.CopyFromGBIF.java

/**
 * //from  ww  w  .  j  a v a 2s.  co m
 */
public void process() {
    boolean doQueryForCollNum = true;

    String pSQL = "INSERT INTO raw (old_id,data_provider_id,data_resource_id,resource_access_point_id, institution_code, collection_code, "
            + "catalogue_number, scientific_name, author, rank, kingdom, phylum, class, order_rank, family, genus, species, subspecies, latitude, longitude,  "
            + "lat_long_precision, max_altitude, min_altitude, altitude_precision, min_depth, max_depth, depth_precision, continent_ocean, country, state_province, county, collector_name, "
            + "locality,year, month, day, basis_of_record, identifier_name, identification_date,unit_qualifier, created, modified, deleted, collector_num) "
            + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

    String gbifSQLBase = "SELECT r.id, r.data_provider_id, r.data_resource_id, r.resource_access_point_id, r.institution_code, r.collection_code, "
            + "r.catalogue_number, r.scientific_name, r.author, r.rank, r.kingdom, r.phylum, r.class, r.order_rank, r.family, r.genus, r.species, r.subspecies, "
            + "r.latitude, r.longitude, r.lat_long_precision, r.max_altitude, r.min_altitude, r.altitude_precision, r.min_depth, r.max_depth, r.depth_precision, "
            + "r.continent_ocean, r.country, r.state_province, r.county, r.collector_name, r.locality, r.year, r.month, r.day, r.basis_of_record, r.identifier_name, "
            + "r.identification_date, r.unit_qualifier, r.created, r.modified, r.deleted";

    String gbifSQL;
    if (doQueryForCollNum) {
        gbifSQL = gbifSQLBase + " FROM raw_occurrence_record r";
    } else {
        gbifSQL = gbifSQLBase
                + ", i.identifier FROM raw_occurrence_record r, identifier_record i WHERE r.id = i.occurrence_id AND i.identifier_type = 3";
    }

    BasicSQLUtils.update(srcDBConn, "DELETE FROM raw WHERE id > 0");

    long totalRecs = BasicSQLUtils.getCount(dbConn, "SELECT COUNT(*) FROM raw_occurrence_record");
    long procRecs = 0;
    long startTime = System.currentTimeMillis();
    int secsThreshold = 0;

    PrintWriter pw = null;

    final double HRS = 1000.0 * 60.0 * 60.0;

    Statement gStmt = null;
    PreparedStatement pStmt = null;
    PreparedStatement stmt = null;

    try {
        pw = new PrintWriter("gbif.log");

        pStmt = srcDBConn.prepareStatement(pSQL);

        stmt = dbConn2.prepareStatement(
                "SELECT identifier FROM identifier_record WHERE occurrence_id = ? AND identifier_type = 3");
        //stmt.setFetchSize(Integer.MIN_VALUE);

        System.out.println("Total Records: " + totalRecs);
        pw.println("Total Records: " + totalRecs);

        gStmt = dbConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        gStmt.setFetchSize(Integer.MIN_VALUE);

        String fullSQL = gbifSQL;
        System.out.println(fullSQL);

        ResultSet gRS = gStmt.executeQuery(fullSQL);
        ResultSetMetaData rsmd = gRS.getMetaData();
        int lastColInx = rsmd.getColumnCount() + (doQueryForCollNum ? 1 : 0);

        while (gRS.next()) {
            int id = gRS.getInt(1);
            pStmt.setObject(1, id);

            for (int i = 2; i <= rsmd.getColumnCount(); i++) {
                Object obj = gRS.getObject(i);
                pStmt.setObject(i, obj);
            }

            String collNum = null;
            if (doQueryForCollNum) {
                //String tmpSQL = String.format("SELECT identifier FROM identifier_record WHERE occurrence_id = %d AND identifier_type = 3", id);
                //System.out.println(tmpSQL);
                stmt.setInt(1, id);
                ResultSet rs = stmt.executeQuery();
                if (rs.next()) {
                    collNum = rs.getString(1);
                }
                rs.close();
            } else {
                collNum = gRS.getString(lastColInx - 1);
            }

            if (StringUtils.isNotEmpty(collNum)) {
                if (collNum.length() < 256) {
                    pStmt.setString(lastColInx, collNum);

                } else {
                    pStmt.setString(lastColInx, collNum.substring(0, 255));
                }
            } else {
                pStmt.setObject(lastColInx, null);
            }

            try {
                pStmt.executeUpdate();

            } catch (Exception ex) {
                System.err.println("For ID[" + gRS.getObject(1) + "]");
                ex.printStackTrace();
                pw.print("For ID[" + gRS.getObject(1) + "] " + ex.getMessage());
                pw.flush();
            }

            procRecs++;
            if (procRecs % 10000 == 0) {
                long endTime = System.currentTimeMillis();
                long elapsedTime = endTime - startTime;

                double avergeTime = (double) elapsedTime / (double) procRecs;

                double hrsLeft = (((double) elapsedTime / (double) procRecs) * (double) totalRecs - procRecs)
                        / HRS;

                int seconds = (int) (elapsedTime / 60000.0);
                if (secsThreshold != seconds) {
                    secsThreshold = seconds;

                    String msg = String.format(
                            "Elapsed %8.2f hr.mn   Ave Time: %5.2f    Percent: %6.3f  Hours Left: %8.2f ",
                            ((double) (elapsedTime)) / HRS, avergeTime,
                            100.0 * ((double) procRecs / (double) totalRecs), hrsLeft);
                    System.out.println(msg);
                    pw.println(msg);
                    pw.flush();
                }
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            if (gStmt != null) {
                gStmt.close();
            }
            if (pStmt != null) {
                pStmt.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            pw.close();

        } catch (Exception ex) {

        }
    }
    System.out.println("Done transferring.");
    pw.println("Done transferring.");

    /*
    int     count = 0;
    boolean cont = true;
    while (cont)
    {
    long start = System.currentTimeMillis();
            
    Statement         gStmt = null;
    PreparedStatement pStmt = null;
            
    try
    {
        gStmt = dbConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
                
        String fullSQL = gbifSQL + String.format(" AND r.id >= %d AND r.id < %d", count, count+recordStep);
        //System.out.println(fullSQL);
                
        int               cnt  = 0;
        ResultSet         rs   = gStmt.executeQuery(fullSQL);
        ResultSetMetaData rsmd = rs.getMetaData();
                
        //System.out.println("Done with query.");
                
        pStmt = srcDBConn.prepareStatement(pSQL);
        count += recordStep;
                
        while (rs.next())
        {
            Integer id  = rs.getInt(1);
            pStmt.setInt(1, id);
                    
            for (int i=2;i<=rsmd.getColumnCount();i++)
            {
                Object obj = rs.getObject(i);
                pStmt.setObject(i, obj);
            }
                    
            pStmt.executeUpdate();
                
            cnt++;
            procRecs++;
        }
        rs.close();
                
        if (count == 0)
        {
            break;
        }
                
    } catch (Exception ex)
    {
        ex.printStackTrace();
                
    } finally 
    {
        try
        {
            if (gStmt != null)
            {
                gStmt.close();
            }
            if (pStmt != null)
            {
                pStmt.close();
            }
        } catch (Exception ex)
        {
                    
        }
    }
            
    long endTime   = System.currentTimeMillis();
    long deltaTime = endTime - start;
               
    long elapsedTime = endTime - startTime;
            
    double avergeTime = (double)elapsedTime / (double)procRecs;
            
    double hrsLeft = (((double)procRecs / (double)elapsedTime) * (double)totalRecs)  / 3600000.0;
            
    int seconds = (int)(elapsedTime / 60000.0);
    if (secsThreshold != seconds)
    {
        secsThreshold = seconds;
                
        System.out.println(String.format("Elapsed %8.2f hr.mn   Time: %5.2f  Ave Time: %5.2f    Percent: %6.3f  Hours Left: Elapsed %8.2f ", 
                ((double)(elapsedTime)) / 3600000.0, 
                ((double)(deltaTime)) / 1000.0, 
                avergeTime,
                100.0 * ((double)procRecs / (double)totalRecs),
                hrsLeft));
    }
    }
    System.out.println("Done transferring.");*/

    /*Statement uStmt = null;
    try
    {
    uStmt = srcDBConn.createStatement();
    int rv = uStmt.executeUpdate("ALTER TABLE raw ADD FULLTEXT(catalogue_number, genus, species, subspecies, collector_num)");
            
    System.out.println("Indexing rv = "+rv);
            
    } catch (Exception ex)
    {
    ex.printStackTrace();
            
    } finally 
    {
    try
    {
        if (uStmt != null)
        {
            uStmt.close();
        }
    } catch (Exception ex)
    {
        ex.printStackTrace();
    }
    }
    System.out.println("Done Indexing.");*/
}

From source file:com.splicemachine.derby.impl.sql.execute.operations.SpliceBaseOperation.java

@Override
public int modifiedRowCount() {
    long modifiedRowCount = 0;
    long badRecords = 0;
    try {/*from w w w  . j a v a2s.  c  o  m*/
        while (locatedRowIterator.hasNext()) {
            LocatedRow next = locatedRowIterator.next();
            ExecRow row = next.getRow();
            modifiedRowCount += row.getColumn(1).getLong();
            if (row.nColumns() > 1) {
                badRecords += row.getColumn(2).getLong();
                getActivation().getLanguageConnectionContext().setBadFile(row.getColumn(3).getString());
            }
        }
        if (modifiedRowCount > Integer.MAX_VALUE || modifiedRowCount < Integer.MIN_VALUE) {
            // DB-5369: int overflow when modified rowcount is larger than max int
            // Add modified row count as a long value in warning
            activation.addWarning(
                    StandardException.newWarning(SQLState.LANG_MODIFIED_ROW_COUNT_TOO_LARGE, modifiedRowCount));
            return -1;
        }
        getActivation().getLanguageConnectionContext().setRecordsImported(modifiedRowCount);
        getActivation().getLanguageConnectionContext().setFailedRecords(badRecords);
        return (int) modifiedRowCount;
    } catch (StandardException se) {
        Exceptions.throwAsRuntime(PublicAPI.wrapStandardException(se));
        return 0; //never reached
    }
}

From source file:com.hunch.api.HunchAPI.java

/**
 * Retrieves a specific Hunch topic.//from  w w  w. j  a v a2  s .  c o  m
 * 
 * Specify either a topicId, or a urlName, but not both.
 * 
 * @param topicId
 *            The id of the topic to return
 * @param urlName
 *            The url textual identifier for the topic, which can be found
 *            in the Hunch URL for the topic
 * @param topicImgSize
 *            The size of the image to return for this topic.
 */
public void getTopic(String topicId, String urlName, String topicImgSize,
        final HunchTopic.Callback completedCallback) {
    if (topicId == null && urlName == null)
        throw new IllegalArgumentException("must set topicId or urlName!");

    if (topicId != null && urlName != null)
        throw new IllegalArgumentException("can not set both topicId and urlName!");

    HunchAPIRequest getTopicRequest = new HunchAPIRequest("getTopic");

    getTopicRequest.addParam("topicId", topicId);
    getTopicRequest.addParam("urlName", urlName);
    getTopicRequest.addParam("topicImgSize", topicImgSize);

    getTopicRequest.execute(new HunchAPIResponseCallback() {

        @Override
        public void callComplete(JSONObject j) {
            JSONObject topic;
            try {
                topic = j.getJSONObject("topic");
            } catch (JSONException e) {
                throw new RuntimeException("couldn't execute a getTopicRequest!", e);
            }

            int id = Integer.MIN_VALUE, eitherOr = Integer.MIN_VALUE;
            try {
                id = topic.getInt("id");
                eitherOr = topic.getInt("eitherOrTopic");
            } catch (JSONException e) {
                throw new RuntimeException("couldn't execute a getTopicRequest!", e);
            }

            IHunchTopic hTopic;
            HunchTopic.Builder b = HunchTopic.getBuilder();

            b.init(j);
            try {
                b.setId(String.valueOf(id)).setDecision(topic.getString("decision"))
                        .setUrlName(topic.getString("urlName")).setShortName(topic.getString("shortName"))
                        .setHunchUrl(topic.getString("hunchUrl")).setImageUrl(topic.getString("imageUrl"))
                        .setResultType(topic.getString("resultType")).setIsEitherOr(eitherOr == 1);

                JSONObject category = topic.getJSONObject("category");

                HunchCategory hCategory = HunchCategory.getBuilder().init(category)
                        .setUrlName(category.getString("categoryUrlName"))
                        .setName(category.getString("categoryName"))
                        .setImageUrl(category.getString("categoryImageUrl")).build();

                b.setCategory(hCategory);

                hTopic = b.build();

            } catch (JSONException e) {
                throw new RuntimeException("couldn't build HunchTopic object!", e);
            }

            completedCallback.callComplete(hTopic);
        }
    });

}

From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEPA512xxDataImpl.java

public EEPA512xxDataImpl(int EEPType, Channel channels[], Date date) {
    switch (EEPType) {
    case 0x00:/*from w  w w .  j av  a 2 s .  c  o  m*/
        this.channels = new Channel[15];
        for (int i = 0; i < 15; i++) {
            if (channels == null || channels[i] == null)
                this.channels[i] = null;
            else
                this.channels[i] = new Channel(channels[i].toJSON());
        }
        break;
    default:
        this.channels = new Channel[1];
        if (channels == null)
            this.channels[0] = new Channel(Integer.MIN_VALUE, null, Integer.MIN_VALUE, null);
        else
            this.channels[0] = new Channel(channels[0].toJSON());
        break;
    }

    this.EEPType = EEPType;
    this.tariffInfo = 0;
    this.date = date;
}

From source file:com.sun.faces.taglib.html_basic.DataTableTag.java

protected void setProperties(UIComponent component) {
    super.setProperties(component);
    UIData data = null;//from  w ww . ja  v a2s.  c  o  m
    try {
        data = (UIData) component;
    } catch (ClassCastException cce) {
        throw new IllegalStateException("Component " + component.toString()
                + " not expected type.  Expected: UIData.  Perhaps you're missing a tag?");
    }

    if (first != null) {
        if (isValueReference(first)) {
            ValueBinding vb = Util.getValueBinding(first);
            data.setValueBinding("first", vb);
        } else {
            int _first = new Integer(first).intValue();
            data.setFirst(_first);
        }
    }
    if (rows != null) {
        if (isValueReference(rows)) {
            ValueBinding vb = Util.getValueBinding(rows);
            data.setValueBinding("rows", vb);
        } else {
            int _rows = new Integer(rows).intValue();
            data.setRows(_rows);
        }
    }
    if (value != null) {
        if (isValueReference(value)) {
            ValueBinding vb = Util.getValueBinding(value);
            data.setValueBinding("value", vb);
        } else {
            data.setValue(value);
        }
    }
    data.setVar(_var);
    if (bgcolor != null) {
        if (isValueReference(bgcolor)) {
            ValueBinding vb = Util.getValueBinding(bgcolor);
            data.setValueBinding("bgcolor", vb);
        } else {
            data.getAttributes().put("bgcolor", bgcolor);
        }
    }
    if (border != null) {
        if (isValueReference(border)) {
            ValueBinding vb = Util.getValueBinding(border);
            data.setValueBinding("border", vb);
        } else {
            int _border = new Integer(border).intValue();
            if (_border != Integer.MIN_VALUE) {
                data.getAttributes().put("border", new Integer(_border));
            }
        }
    }
    if (cellpadding != null) {
        if (isValueReference(cellpadding)) {
            ValueBinding vb = Util.getValueBinding(cellpadding);
            data.setValueBinding("cellpadding", vb);
        } else {
            data.getAttributes().put("cellpadding", cellpadding);
        }
    }
    if (cellspacing != null) {
        if (isValueReference(cellspacing)) {
            ValueBinding vb = Util.getValueBinding(cellspacing);
            data.setValueBinding("cellspacing", vb);
        } else {
            data.getAttributes().put("cellspacing", cellspacing);
        }
    }
    if (columnClasses != null) {
        if (isValueReference(columnClasses)) {
            ValueBinding vb = Util.getValueBinding(columnClasses);
            data.setValueBinding("columnClasses", vb);
        } else {
            data.getAttributes().put("columnClasses", columnClasses);
        }
    }
    if (dir != null) {
        if (isValueReference(dir)) {
            ValueBinding vb = Util.getValueBinding(dir);
            data.setValueBinding("dir", vb);
        } else {
            data.getAttributes().put("dir", dir);
        }
    }
    if (footerClass != null) {
        if (isValueReference(footerClass)) {
            ValueBinding vb = Util.getValueBinding(footerClass);
            data.setValueBinding("footerClass", vb);
        } else {
            data.getAttributes().put("footerClass", footerClass);
        }
    }
    if (frame != null) {
        if (isValueReference(frame)) {
            ValueBinding vb = Util.getValueBinding(frame);
            data.setValueBinding("frame", vb);
        } else {
            data.getAttributes().put("frame", frame);
        }
    }
    if (headerClass != null) {
        if (isValueReference(headerClass)) {
            ValueBinding vb = Util.getValueBinding(headerClass);
            data.setValueBinding("headerClass", vb);
        } else {
            data.getAttributes().put("headerClass", headerClass);
        }
    }
    if (lang != null) {
        if (isValueReference(lang)) {
            ValueBinding vb = Util.getValueBinding(lang);
            data.setValueBinding("lang", vb);
        } else {
            data.getAttributes().put("lang", lang);
        }
    }
    if (onclick != null) {
        if (isValueReference(onclick)) {
            ValueBinding vb = Util.getValueBinding(onclick);
            data.setValueBinding("onclick", vb);
        } else {
            data.getAttributes().put("onclick", onclick);
        }
    }
    if (ondblclick != null) {
        if (isValueReference(ondblclick)) {
            ValueBinding vb = Util.getValueBinding(ondblclick);
            data.setValueBinding("ondblclick", vb);
        } else {
            data.getAttributes().put("ondblclick", ondblclick);
        }
    }
    if (onkeydown != null) {
        if (isValueReference(onkeydown)) {
            ValueBinding vb = Util.getValueBinding(onkeydown);
            data.setValueBinding("onkeydown", vb);
        } else {
            data.getAttributes().put("onkeydown", onkeydown);
        }
    }
    if (onkeypress != null) {
        if (isValueReference(onkeypress)) {
            ValueBinding vb = Util.getValueBinding(onkeypress);
            data.setValueBinding("onkeypress", vb);
        } else {
            data.getAttributes().put("onkeypress", onkeypress);
        }
    }
    if (onkeyup != null) {
        if (isValueReference(onkeyup)) {
            ValueBinding vb = Util.getValueBinding(onkeyup);
            data.setValueBinding("onkeyup", vb);
        } else {
            data.getAttributes().put("onkeyup", onkeyup);
        }
    }
    if (onmousedown != null) {
        if (isValueReference(onmousedown)) {
            ValueBinding vb = Util.getValueBinding(onmousedown);
            data.setValueBinding("onmousedown", vb);
        } else {
            data.getAttributes().put("onmousedown", onmousedown);
        }
    }
    if (onmousemove != null) {
        if (isValueReference(onmousemove)) {
            ValueBinding vb = Util.getValueBinding(onmousemove);
            data.setValueBinding("onmousemove", vb);
        } else {
            data.getAttributes().put("onmousemove", onmousemove);
        }
    }
    if (onmouseout != null) {
        if (isValueReference(onmouseout)) {
            ValueBinding vb = Util.getValueBinding(onmouseout);
            data.setValueBinding("onmouseout", vb);
        } else {
            data.getAttributes().put("onmouseout", onmouseout);
        }
    }
    if (onmouseover != null) {
        if (isValueReference(onmouseover)) {
            ValueBinding vb = Util.getValueBinding(onmouseover);
            data.setValueBinding("onmouseover", vb);
        } else {
            data.getAttributes().put("onmouseover", onmouseover);
        }
    }
    if (onmouseup != null) {
        if (isValueReference(onmouseup)) {
            ValueBinding vb = Util.getValueBinding(onmouseup);
            data.setValueBinding("onmouseup", vb);
        } else {
            data.getAttributes().put("onmouseup", onmouseup);
        }
    }
    if (rowClasses != null) {
        if (isValueReference(rowClasses)) {
            ValueBinding vb = Util.getValueBinding(rowClasses);
            data.setValueBinding("rowClasses", vb);
        } else {
            data.getAttributes().put("rowClasses", rowClasses);
        }
    }
    if (rules != null) {
        if (isValueReference(rules)) {
            ValueBinding vb = Util.getValueBinding(rules);
            data.setValueBinding("rules", vb);
        } else {
            data.getAttributes().put("rules", rules);
        }
    }
    if (style != null) {
        if (isValueReference(style)) {
            ValueBinding vb = Util.getValueBinding(style);
            data.setValueBinding("style", vb);
        } else {
            data.getAttributes().put("style", style);
        }
    }
    if (styleClass != null) {
        if (isValueReference(styleClass)) {
            ValueBinding vb = Util.getValueBinding(styleClass);
            data.setValueBinding("styleClass", vb);
        } else {
            data.getAttributes().put("styleClass", styleClass);
        }
    }
    if (summary != null) {
        if (isValueReference(summary)) {
            ValueBinding vb = Util.getValueBinding(summary);
            data.setValueBinding("summary", vb);
        } else {
            data.getAttributes().put("summary", summary);
        }
    }
    if (title != null) {
        if (isValueReference(title)) {
            ValueBinding vb = Util.getValueBinding(title);
            data.setValueBinding("title", vb);
        } else {
            data.getAttributes().put("title", title);
        }
    }
    if (width != null) {
        if (isValueReference(width)) {
            ValueBinding vb = Util.getValueBinding(width);
            data.setValueBinding("width", vb);
        } else {
            data.getAttributes().put("width", width);
        }
    }
}

From source file:md.MangaDownloader.java

public static String automaticVolumeName(List<MangaChaptersInfo> selectedChapters) {
    TreeSet<Integer> chapterNumbers = new TreeSet<Integer>();
    String alternative = "";
    for (MangaChaptersInfo m : selectedChapters) {
        try {//from w w  w  .  j  av a 2s. co m
            if (!m.chapterNumber.equals("")) {
                int test = Integer.parseInt(m.chapterNumber);
                chapterNumbers.add(test);
            }
        } catch (NumberFormatException e) {
            //If more than one alternative chapter name then all renamed to "Extras"
            if (alternative.equals("")) {
                alternative = m.chapterNumber;
            } else {
                alternative = STRINGS.getString("NAME_EXTRAS");
            }
        }
    }

    String result = "";
    if (!chapterNumbers.isEmpty()) {
        int firstInSequence = Integer.MIN_VALUE;
        int lastInSequence;

        for (Iterator<Integer> i = chapterNumbers.iterator(); i.hasNext();) {
            int actualNumber = i.next();
            if (firstInSequence == Integer.MIN_VALUE)
                firstInSequence = actualNumber;
            lastInSequence = actualNumber;
            int next;
            if (i.hasNext()) {
                next = chapterNumbers.higher(actualNumber);
            } else {
                next = Integer.MIN_VALUE;
            }
            if ((actualNumber + 1 != next) || (next == Integer.MIN_VALUE)) {
                //FIN DE SECUENCIA
                if (!result.equals("")) {
                    result += ", ";
                }
                if (firstInSequence == lastInSequence) {
                    result += String.format("%04d", firstInSequence);
                } else {
                    result += String.format("%04d - %04d", firstInSequence, lastInSequence);
                }
                firstInSequence = Integer.MIN_VALUE;
            }
        }

    }

    if (!alternative.equals("")) {
        if (!result.equals(""))
            result += " & ";
        result += alternative;
    }

    return result;
}

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

private int resolveResultAsInteger(String rawResult) throws ConversionException {
    try {//from   w  w  w.ja  v a 2 s .  c o  m
        BigInteger min = new BigInteger(Integer.toString(Integer.MIN_VALUE));
        BigInteger max = new BigInteger(Integer.toString(Integer.MAX_VALUE));

        BigInteger result = new BigInteger(rawResult);

        if (result.compareTo(min) < 0) {
            return Integer.MIN_VALUE;
        }

        else if (result.compareTo(max) > 0) {
            return Integer.MAX_VALUE;
        }

        else {
            return result.intValue();
        }
    }

    catch (NumberFormatException e) {
        throw new ConversionException("Cannot parse device return value to Java integer: " + e.getMessage(), e);
    }
}

From source file:com.strider.datadefender.DatabaseAnonymizer.java

/**
 * Creates the SELECT query for key and update columns.
 * //from  ww w  . ja  va2 s. c om
 * @param tableName
 * @param keys
 * @param columns
 * @return 
 */
private PreparedStatement getSelectQueryStatement(final IDBFactory dbFactory, final Table table,
        final Collection<String> keys, final Collection<String> columns) throws SQLException {

    final List<String> params = new LinkedList<>();
    final StringBuilder query = new StringBuilder("SELECT DISTINCT ");
    query.append(StringUtils.join(keys, ", ")).append(", ").append(StringUtils.join(columns, ", "))
            .append(" FROM ").append(table.getName());

    final List<Exclude> exclusions = table.getExclusions();
    if (exclusions != null) {
        String separator = " WHERE (";
        for (final Exclude exc : exclusions) {
            final String eq = exc.getEqualsValue();
            final String lk = exc.getLikeValue();
            final boolean nl = exc.isExcludeNulls();
            final String col = exc.getName();

            if (col != null && col.length() != 0) {
                if (eq != null) {
                    query.append(separator).append('(').append(col).append(" != ? OR ").append(col)
                            .append(" IS NULL)");
                    params.add(eq);
                    separator = AND;
                }
                if (lk != null && lk.length() != 0) {
                    query.append(separator).append('(').append(col).append(" NOT LIKE ? OR ").append(col)
                            .append(" IS NULL)");
                    params.add(lk);
                    separator = AND;
                }
                if (nl) {
                    query.append(separator).append(col).append(" IS NOT NULL");
                    separator = AND;
                }
            }
        }

        if (query.indexOf(" WHERE (") != -1) {
            separator = ") AND (";
        }

        for (final Exclude exc : exclusions) {
            final String neq = exc.getNotEqualsValue();
            final String nlk = exc.getNotLikeValue();
            final String col = exc.getName();

            if (neq != null) {
                query.append(separator).append(col).append(" = ?");
                separator = " OR ";
            }
            if (nlk != null && nlk.length() != 0) {
                query.append(separator).append(col).append(" LIKE ?");
                separator = " OR ";
            }

        }

        if (query.indexOf(" WHERE (") != -1) {
            query.append(')');
        }
    }

    final PreparedStatement stmt = dbFactory.getConnection().prepareStatement(query.toString(),
            ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
    if (dbFactory.getVendorName().equalsIgnoreCase("mysql")) {
        stmt.setFetchSize(Integer.MIN_VALUE);
    }

    int paramIndex = 1;
    for (final String param : params) {
        stmt.setString(paramIndex, param);
        ++paramIndex;
    }

    log.debug("Querying for: " + query.toString());
    if (params.size() > 0) {
        log.debug("\t - with parameters: " + StringUtils.join(params, ','));
    }

    return stmt;
}