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:io.hops.metadata.util.HopYarnAPIUtilities.java

/**
 * Sets new value for yarn variable and returns old one to be used by
 * application./*from w  ww .  j  ava 2 s  .c om*/
 *
 * @param type
 * @return
 */
public synchronized static int setYarnVariables(final int type) {
    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 != null) {
                int toReturn = found.getValue();
                found.setValue(found.getValue() + 1);
                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:org.usrz.libs.httpd.handlers.RestHandlerProvider.java

@Override
protected HttpHandler get(Injector injector, Configurations configurations) {

    /* Setup our object mapper (could be qualified with path) */
    final ObjectMapper mapper = getInstance(injector, ObjectMapper.class, path);

    final Map<Class<?>, Integer> contractPriorities = new HashMap<>();
    contractPriorities.put(MessageBodyWriter.class, Integer.MIN_VALUE);
    contractPriorities.put(MessageBodyReader.class, Integer.MIN_VALUE);
    config.register(/*  w  w  w  . ja va  2s. co m*/
            new JacksonJsonProvider(mapper, new Annotations[] { Annotations.JACKSON, Annotations.JAXB }),
            Collections.unmodifiableMap(contractPriorities));

    /* Create a ServiceLocator parent of all locators and inject the configurations */
    final ServiceLocator locator = ServiceLocatorFactory.create(injector, path);

    /* Set up the ObjectMapper that will be used by this application */
    ServiceLocatorUtilities.addOneConstant(locator, mapper, null, ObjectMapper.class);

    /* Create a brand new Grizzly HTTP container from Jersey */
    log.debug("Jersey application at \"%s\" initializing", path.value());
    GrizzlyHttpContainer container = GrizzlyHttpContainerFactory.create(config, locator);
    log.info("Jersey application at \"%s\" initialized successfully", path.value());

    /* Create our handler and add it to our server configuration  */
    final HttpServer server = injector.getInstance(HttpServer.class);
    server.getServerConfiguration().addHttpHandler(container, path.value());
    log.info("Serving \"%s\" using Jersey application \"%s\"", path.value(), config.getApplicationName());

    /* All done! */
    return container;
}

From source file:com.vaushell.superpipes.tools.http.ImageExtractor.java

/**
 * Return the biggest image URI of this webpage.
 *
 * @param rootURI Webpage URI/*from  w  w  w. java2 s. c  o m*/
 * @return Biggest image
 * @throws IOException
 */
public BufferedImage extractBiggest(final URI rootURI) throws IOException {
    final List<URI> imagesURIs = new ArrayList<>();
    HttpEntity responseEntity = null;
    try {
        // Exec request
        final HttpGet get = new HttpGet(rootURI);

        try (final CloseableHttpResponse response = client.execute(get)) {
            final StatusLine sl = response.getStatusLine();
            if (sl.getStatusCode() != 200) {
                throw new IOException(sl.getReasonPhrase());
            }

            responseEntity = response.getEntity();

            try (final InputStream is = responseEntity.getContent()) {
                final Document doc = Jsoup.parse(is, "UTF-8", rootURI.toString());

                final Elements elts = doc.select("img");
                if (elts != null) {
                    for (final Element elt : elts) {
                        final String src = elt.attr("src");
                        if (src != null && !src.isEmpty()) {
                            try {
                                imagesURIs.add(rootURI.resolve(src));
                            } catch (final IllegalArgumentException ex) {
                                // Ignore wrong encoded URI
                            }
                        }
                    }
                }
            }
        }
    } finally {
        if (responseEntity != null) {
            EntityUtils.consume(responseEntity);
        }
    }

    final BufferedImage[] images = new BufferedImage[imagesURIs.size()];
    final ExecutorService service = Executors.newCachedThreadPool();
    for (int i = 0; i < imagesURIs.size(); ++i) {
        final int num = i;

        service.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    images[num] = HTTPhelper.loadPicture(client, imagesURIs.get(num));
                } catch (final IOException ex) {
                    images[num] = null;
                }
            }
        });
    }

    service.shutdown();

    try {
        service.awaitTermination(1L, TimeUnit.DAYS);
    } catch (final InterruptedException ex) {
        // Ignore
    }

    BufferedImage biggest = null;
    int biggestSize = Integer.MIN_VALUE;
    for (int i = 0; i < imagesURIs.size(); ++i) {
        if (images[i] != null) {
            final int actualSize = images[i].getWidth() * images[i].getHeight();
            if (actualSize > biggestSize) {
                biggest = images[i];

                biggestSize = actualSize;
            }
        }
    }

    return biggest;
}

From source file:com.textocat.textokit.morph.opencorpora.resource.MorphDictionaryImpl.java

@Override
public int getLemmaMaxId() {
    int max = Integer.MIN_VALUE;
    for (Integer curId : lemmaMap.keySet()) {
        if (curId == null) {
            continue;
        }//w w  w  .j  av a  2  s . co  m
        if (curId > max) {
            max = curId;
        }
    }
    return max;
}

From source file:com.idylwood.utils.MathUtils.java

public final static int max(int... values) {
    if (values.length == 0)
        return Integer.MIN_VALUE;
    int ret = values[0];
    for (int i = 1; i < values.length; i++)
        if (values[i] > ret)
            ret = values[i];/*from   w  ww.  j  a v  a  2s . c o  m*/
    return ret;
}

From source file:ArrayUtil.java

public static int[] multimaxIndex(int[] d) {
    int maxpos[] = new int[d.length], lastpos = 0, maxval = Integer.MIN_VALUE;
    for (int i = 0; i < d.length; i++)
        if (d[i] > maxval) {
            maxval = d[i];/*from  w  ww.ja  va 2  s  .co m*/
            maxpos = new int[d.length - i];
            lastpos = 0;
            maxpos[lastpos++] = i;
        } else if (d[i] == maxval) {
            maxpos[lastpos++] = i;
        }
    int r[] = new int[lastpos];
    System.arraycopy(maxpos, 0, r, 0, lastpos);
    return r;
}

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

@Override
public void process(final int type, final int options) {
    calcMaxScore();/*from  w  w  w  .  j a va2s .c  om*/

    String gbifSQL = "SELECT DISTINCT id, catalogue_number, genus, species, subspecies, latitude, longitude, country, state_province, collector_name, locality, year, month, day, collector_num ";

    String fromClause1a = "FROM raw WHERE collector_num LIKE ? AND year = ? AND genus = ?";
    String fromClause1b = "FROM raw WHERE collector_num IS NULL AND year = ? AND genus = ?";
    //String fromClause2  = "FROM raw WHERE collector_num IS NULL AND year = ? AND month = ? AND genus = ? AND id <> ?";

    //                        1       2           3        4           5         6          7         8           9               10          11       12    13    14      15
    String postSQL = "FROM raw WHERE collector_num IS NOT NULL GROUP BY collector_num, year, genus";
    String srcSQL = "SELECT id, catalogue_number, genus, species, subspecies, latitude, longitude, country, state_province, collector_name, locality, year, month, day, collector_num "
            + postSQL + " ORDER BY collector_num";

    String grphashSQL = "SELECT name FROM group_hash";

    String gbifgbifInsert = "INSERT INTO gbifgbif (reltype, score, GBIFID, SNIBID) VALUES (?,?,?,?)";

    Statement stmt = null;
    PreparedStatement gStmt1a = null;
    PreparedStatement gStmt1b = null;
    //PreparedStatement gStmt2  = null;
    PreparedStatement gsStmt = null;

    Object[] refRow = new Object[NUM_FIELDS];
    Object[] cmpRow = new Object[NUM_FIELDS];

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

    String blank = "X?";

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

        gStmt1a = dbGBIFConn.prepareStatement(gbifSQL + fromClause1a);
        gStmt1b = dbGBIFConn.prepareStatement(gbifSQL + fromClause1b);

        //gStmt2 = dbGBIFConn.prepareStatement(gbifSQL + fromClause2);
        gsStmt = dbDstConn.prepareStatement(gbifgbifInsert);

        stmt = dbSrcConn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
        stmt.setFetchSize(Integer.MIN_VALUE);

        System.out.println("Starting Query... " + totalRecs);
        pw.println("Starting Query... " + totalRecs);
        System.out.flush();
        pw.flush();

        HashSet<Integer> idHash = new HashSet<Integer>();
        int writeCnt = 0;
        ResultSet rs = stmt.executeQuery(grphashSQL);

        System.out
                .println(String.format("Starting Processing... Total Records %d  Max Score: %d  Threshold: %d",
                        totalRecs, maxScore, thresholdScore));
        pw.println(String.format("Starting Processing... Total Records %d  Max Score: %d  Threshold: %d",
                totalRecs, maxScore, thresholdScore));
        System.out.flush();
        pw.flush();

        Vector<Object[]> group = new Vector<Object[]>();
        ArrayList<Integer> ids = new ArrayList<Integer>();
        while (rs.next()) {
            String[] tokens = StringUtils.split(rs.getString(1), '_');

            String colNum = tokens[0].trim();
            String year = tokens[1].trim();
            String genus = tokens[2].trim();

            if (StringUtils.isEmpty(colNum) || colNum.equals(blank))
                colNum = null;
            if (StringUtils.isEmpty(year) || year.equals(blank))
                year = null;
            if (StringUtils.isEmpty(genus) || genus.equals(blank))
                genus = null;

            PreparedStatement gStmt1;
            if (colNum != null) {
                gStmt1 = gStmt1a;
                gStmt1.setString(1, "%" + colNum + "%");
            } else {
                gStmt1 = gStmt1b;
                gStmt1.setString(1, null);
            }
            gStmt1.setString(2, year);
            gStmt1.setString(3, genus);
            ResultSet gRS = gStmt1.executeQuery();

            ids.clear();
            int maxNonNullTot = -1;
            int maxNonNullInx = -1;
            int inx = 0;
            while (gRS.next()) {

                Object[] row = getRow();
                int cnt = fillRowWithScore(row, gRS);
                if (cnt > maxNonNullTot) {
                    maxNonNullInx = inx;
                    maxNonNullTot = cnt;
                }
                group.add(row);
                ids.add(gRS.getInt(1));
                inx++;
            }
            gRS.close();

            if (inx < 2) {
                for (Object[] r : group) {
                    recycleRow(r);
                }
                group.clear();
                continue;
            }

            System.arraycopy(group.get(maxNonNullInx), 0, refRow, 0, refRow.length);

            Integer srcId = ids.get(maxNonNullInx);

            for (int i = 0; i < group.size(); i++) {
                if (i != maxNonNullInx) {
                    int score = score(refRow, group.get(i));

                    if (score > thresholdScore) {
                        writeCnt++;

                        int gbifID = ids.get(i);
                        gsStmt.setInt(1, 1); // reltype
                        gsStmt.setInt(2, score); // score
                        gsStmt.setInt(3, gbifID);
                        gsStmt.setInt(4, srcId);
                        gsStmt.executeUpdate();

                        idHash.add(gbifID);
                    }
                }
            }

            idHash.clear();

            for (Object[] r : group) {
                recycleRow(r);
            }
            group.clear();

            if (gStmt1 == gStmt1b) {
                continue;
            }

            gStmt1 = gStmt1b;
            gStmt1.setString(1, year);
            gStmt1.setString(2, genus);

            gRS = gStmt1.executeQuery();
            while (gRS.next()) {
                fillRowWithScore(cmpRow, gRS);

                int gbifID = gRS.getInt(1);
                if (gbifID == srcId)
                    continue;

                int score = score(refRow, cmpRow);

                if (score > thresholdScore) {
                    writeCnt++;
                    gsStmt.setInt(1, 1); // reltype
                    gsStmt.setInt(2, score); // score
                    gsStmt.setInt(3, gbifID);
                    gsStmt.setInt(4, srcId);
                    gsStmt.executeUpdate();
                }
            }
            gRS.close();

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

                double timePerRecord = (elapsedTime / procRecs);

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

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

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

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

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (gStmt1a != null) {
                gStmt1a.close();
            }
            if (gStmt1b != null) {
                gStmt1b.close();
            }
            /*if (gStmt2 != null)
            {
            gStmt2.close();
            }*/
        } catch (Exception ex) {

        }
    }
    System.out.println("Done.");
    pw.println("Done.");
    pw.flush();
    pw.close();
}

From source file:com.googlecode.concurrentlinkedhashmap.MultiThreadedTest.java

@Test(dataProvider = "builder")
public void weightedConcurrency(Builder<Integer, List<Integer>> builder) {
    final ConcurrentLinkedHashMap<Integer, List<Integer>> map = builder.weigher(Weighers.<Integer>list())
            .maximumWeightedCapacity(threads).concurrencyLevel(threads).build();
    final Queue<List<Integer>> values = new ConcurrentLinkedQueue<List<Integer>>();
    for (int i = 1; i <= threads; i++) {
        Integer[] array = new Integer[i];
        Arrays.fill(array, Integer.MIN_VALUE);
        values.add(Arrays.asList(array));
    }//  www .  ja v  a  2s .  c  om
    executeWithTimeOut(map, new Callable<Long>() {
        @Override
        public Long call() throws Exception {
            return timeTasks(threads, new Runnable() {
                @Override
                public void run() {
                    List<Integer> value = values.poll();
                    for (int i = 0; i < iterations; i++) {
                        map.put(i % 10, value);
                    }
                }
            });
        }
    });
}

From source file:com.github.lynxdb.server.core.Aggregator.java

protected TimeSerie doInterpolate(List<TimeSerie> _series, Reducer _reducer) {
    Assert.notEmpty(_series);/*  w  w w.ja v a 2s.c  om*/

    List<SuperIterator> sil = new ArrayList<>();

    _series.forEach((TimeSerie t) -> {
        if (t.hasNext()) {
            SuperIterator<Entry> si = new SuperIterator<>(t);
            si.next();
            sil.add(si);
        }
    });

    Map<String, String> tags = new HashMap<>();
    tags.putAll(_series.get(0).getTags());

    _series.forEach((TimeSerie t) -> {
        Iterator<Map.Entry<String, String>> i = tags.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<String, String> e = i.next();
            if (!t.getTags().containsKey(e.getKey()) || !t.getTags().get(e.getKey()).equals(e.getValue())) {
                i.remove();
            }

        }
    });

    return new TimeSerie(_series.get(0).getName(), tags, new ChainableIterator<Entry>() {

        @Override
        public boolean hasNext() {
            return sil.stream().anyMatch((SuperIterator t) -> t.hasNext() || t.getCurrent() != null);
        }

        @Override
        public Entry next() {
            _reducer.reset();

            Iterator<SuperIterator> rr = sil.iterator();
            while (rr.hasNext()) {
                if (rr.next().getCurrent() == null) {
                    rr.remove();
                }
            }

            int max = Integer.MIN_VALUE;

            for (SuperIterator<Entry> r : sil) {
                max = Integer.max(max, r.getCurrent().getTime());
            }

            for (SuperIterator<Entry> r : sil) {
                if (r.getCurrent().getTime() == max) {
                    _reducer.update(r.getCurrent());
                    r.next();
                } else if (r.getPrevious() != null) {
                    _reducer.update(new Entry(max, interpolate(r.getCurrent(), r.getPrevious(), max)));
                }
            }
            return new Entry(max, _reducer.result());
        }
    });
}

From source file:com.izforge.izpack.core.data.DefaultVariablesTest.java

/**
 * Tests the {@link Variables#getInt(String)} and {@link Variables#getInt(String, int)} methods.
 *///w  ww  .j ava2  s.  c  o  m
@Test
public void testIntVariables() {
    // check basic set, get
    variables.set("var1", "0");
    variables.set("var2", Integer.toString(Integer.MIN_VALUE));
    variables.set("var3", Integer.toString(Integer.MAX_VALUE));
    assertEquals(0, variables.getInt("var1"));
    assertEquals(Integer.MIN_VALUE, variables.getInt("var2"));
    assertEquals(Integer.MAX_VALUE, variables.getInt("var3"));

    // check when the variable is null
    variables.set("null", null);
    assertEquals(-1, variables.getInt("null"));
    assertEquals(9999, variables.getInt("null", 9999));

    // check when the variable doesn't exist
    assertEquals(-1, variables.getInt("nonExistingVariable"));
    assertEquals(9999, variables.getInt("nonExistingVariable", 9999));

    // check when the variable is not an integer value
    variables.set("notAnInt", "abcdef");
    assertEquals(-1, variables.getInt("notAnInt"));
    assertEquals(9999, variables.getInt("notAnInt", 9999));

    // check behaviour when value < Integer.MIN_VALUE or > Integer.MAX_VALUE
    variables.set("exceed1", Long.toString(Long.MIN_VALUE));
    variables.set("exceed2", Long.toString(Long.MAX_VALUE));

    assertEquals(-1, variables.getInt("exceed1"));
    assertEquals(9999, variables.getInt("exceed1", 9999));
    assertEquals(-1, variables.getInt("exceed2"));
    assertEquals(9999, variables.getInt("exceed2", 9999));
}