List of usage examples for java.lang Long MIN_VALUE
long MIN_VALUE
To view the source code for java.lang Long MIN_VALUE.
Click Source Link
From source file:de.ma.it.common.excel.ExcelFileManager.java
/** * /* w w w .j a va 2 s.c o m*/ * @param row * @param cellIdx * @return * @throws IllegalArgumentException */ public Long readCellAsLong(HSSFRow row, int cellIdx) throws IllegalArgumentException { HSSFCell cell = getCell(row, cellIdx); if (cell == null) { return null; } int cellType = cell.getCellType(); // First evaluate formula if present if (cellType == HSSFCell.CELL_TYPE_FORMULA) { cellType = evaluator.evaluateFormulaCell(cell); } Long result; switch (cellType) { case HSSFCell.CELL_TYPE_NUMERIC: double numericCellValue = cell.getNumericCellValue(); if (numericCellValue > Long.MAX_VALUE) { throw new IllegalArgumentException("Value " + numericCellValue + " to big for integer!"); } result = Double.valueOf(numericCellValue).longValue(); break; case HSSFCell.CELL_TYPE_STRING: String stringCellValue = cell.getStringCellValue(); if (!StringUtils.isNumeric(stringCellValue)) { throw new IllegalArgumentException("Value " + stringCellValue + " is not numeric!"); } result = Double.valueOf(stringCellValue).longValue(); break; default: result = Long.MIN_VALUE; break; } return result; }
From source file:org.apache.hadoop.hbase.coprocessor.TestAggregateProtocol.java
@Test(timeout = 300000) public void testMaxWithInvalidRange2() throws Throwable { long max = Long.MIN_VALUE; Scan scan = new Scan(); scan.addColumn(TEST_FAMILY, TEST_QUALIFIER); scan.setStartRow(ROWS[4]);//from w w w . j a v a2 s . c o m scan.setStopRow(ROWS[4]); try { AggregationClient aClient = new AggregationClient(conf); final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci = new LongColumnInterpreter(); max = aClient.max(TEST_TABLE, ci, scan); } catch (Exception e) { max = 0; } assertEquals(0, max);// control should go to the catch block }
From source file:org.apache.cassandra.db.ColumnFamily.java
public ColumnStats getColumnStats() { // note that we default to MIN_VALUE/MAX_VALUE here to be able to override them later in this method // we are checking row/range tombstones and actual cells - there should always be data that overrides // these with actual values ColumnStats.MinLongTracker minTimestampTracker = new ColumnStats.MinLongTracker(Long.MIN_VALUE); ColumnStats.MaxLongTracker maxTimestampTracker = new ColumnStats.MaxLongTracker(Long.MAX_VALUE); StreamingHistogram tombstones = new StreamingHistogram(SSTable.TOMBSTONE_HISTOGRAM_BIN_SIZE); ColumnStats.MaxIntTracker maxDeletionTimeTracker = new ColumnStats.MaxIntTracker(Integer.MAX_VALUE); List<ByteBuffer> minColumnNamesSeen = Collections.emptyList(); List<ByteBuffer> maxColumnNamesSeen = Collections.emptyList(); boolean hasLegacyCounterShards = false; if (deletionInfo().getTopLevelDeletion().localDeletionTime < Integer.MAX_VALUE) { tombstones.update(deletionInfo().getTopLevelDeletion().localDeletionTime); maxDeletionTimeTracker.update(deletionInfo().getTopLevelDeletion().localDeletionTime); minTimestampTracker.update(deletionInfo().getTopLevelDeletion().markedForDeleteAt); maxTimestampTracker.update(deletionInfo().getTopLevelDeletion().markedForDeleteAt); }// w ww . j a va 2 s . c o m Iterator<RangeTombstone> it = deletionInfo().rangeIterator(); while (it.hasNext()) { RangeTombstone rangeTombstone = it.next(); tombstones.update(rangeTombstone.getLocalDeletionTime()); minTimestampTracker.update(rangeTombstone.timestamp()); maxTimestampTracker.update(rangeTombstone.timestamp()); maxDeletionTimeTracker.update(rangeTombstone.getLocalDeletionTime()); minColumnNamesSeen = ColumnNameHelper.minComponents(minColumnNamesSeen, rangeTombstone.min, metadata.comparator); maxColumnNamesSeen = ColumnNameHelper.maxComponents(maxColumnNamesSeen, rangeTombstone.max, metadata.comparator); } for (Cell cell : this) { minTimestampTracker.update(cell.timestamp()); maxTimestampTracker.update(cell.timestamp()); maxDeletionTimeTracker.update(cell.getLocalDeletionTime()); int deletionTime = cell.getLocalDeletionTime(); if (deletionTime < Integer.MAX_VALUE) tombstones.update(deletionTime); minColumnNamesSeen = ColumnNameHelper.minComponents(minColumnNamesSeen, cell.name(), metadata.comparator); maxColumnNamesSeen = ColumnNameHelper.maxComponents(maxColumnNamesSeen, cell.name(), metadata.comparator); if (cell instanceof CounterCell) hasLegacyCounterShards = hasLegacyCounterShards || ((CounterCell) cell).hasLegacyShards(); } return new ColumnStats(getColumnCount(), minTimestampTracker.get(), maxTimestampTracker.get(), maxDeletionTimeTracker.get(), tombstones, minColumnNamesSeen, maxColumnNamesSeen, hasLegacyCounterShards); }
From source file:org.apache.cassandra.db.clock.IncrementCounterContext.java
/** * Return a context w/ an aggregated count for each node id. * * @param contexts/*from ww w . j a v a 2 s . co m*/ * a list of contexts to be merged */ public byte[] merge(List<byte[]> contexts) { // strategy: // 1) take highest timestamp // 2) take highest delete timestamp // 3) map id -> count // a) local id: sum counts; keep highest timestamp // b) remote id: keep highest count (reconcile) // 4) create a context from sorted array long highestTimestamp = Long.MIN_VALUE; long highestDeleteTimestamp = Long.MIN_VALUE; Map<FBUtilities.ByteArrayWrapper, Long> contextsMap = new HashMap<FBUtilities.ByteArrayWrapper, Long>(); for (byte[] context : contexts) { // take highest timestamp highestTimestamp = Math.max(FBUtilities.byteArrayToLong(context, 0), highestTimestamp); highestDeleteTimestamp = Math.max(FBUtilities.byteArrayToLong(context, TIMESTAMP_LENGTH), highestDeleteTimestamp); // map id -> count for (int offset = HEADER_LENGTH; offset < context.length; offset += stepLength) { FBUtilities.ByteArrayWrapper id = new FBUtilities.ByteArrayWrapper( ArrayUtils.subarray(context, offset, offset + idLength)); long count = FBUtilities.byteArrayToLong(context, offset + idLength); Long previousCount = contextsMap.put(id, count); if (previousCount == null) continue; // local id: sum counts if (this.idWrapper.equals(id)) { contextsMap.put(id, count + previousCount); continue; } // remote id: keep highest count contextsMap.put(id, Math.max(count, previousCount)); } } List<Map.Entry<FBUtilities.ByteArrayWrapper, Long>> contextsList = new ArrayList<Map.Entry<FBUtilities.ByteArrayWrapper, Long>>( contextsMap.entrySet()); Collections.sort(contextsList, new Comparator<Map.Entry<FBUtilities.ByteArrayWrapper, Long>>() { public int compare(Map.Entry<FBUtilities.ByteArrayWrapper, Long> e1, Map.Entry<FBUtilities.ByteArrayWrapper, Long> e2) { // reversed int result = e2.getValue().compareTo(e1.getValue()); if (result != 0) return result; return FBUtilities.compareByteArrays(e2.getKey().data, e1.getKey().data); } }); int length = contextsList.size(); byte[] merged = new byte[HEADER_LENGTH + (length * stepLength)]; FBUtilities.copyIntoBytes(merged, 0, highestTimestamp); FBUtilities.copyIntoBytes(merged, TIMESTAMP_LENGTH, highestDeleteTimestamp); for (int i = 0; i < length; i++) { Map.Entry<FBUtilities.ByteArrayWrapper, Long> entry = contextsList.get(i); writeElementAtStepOffset(merged, i, entry.getKey().data, entry.getValue().longValue()); } return merged; }
From source file:mekhq.Utilities.java
/** * Returns the last file modified in a directory and all subdirectories * that conforms to a FilenameFilter/* w w w . java 2s . com*/ * @param dir * @param filter * @return */ public static File lastFileModified(String dir, FilenameFilter filter) { File fl = new File(dir); File[] files = fl.listFiles(filter); long lastMod = Long.MIN_VALUE; File choice = null; for (File file : files) { if (file.lastModified() > lastMod) { choice = file; lastMod = file.lastModified(); } } //ok now we need to recursively search any subdirectories, so see if they //contain more recent files files = fl.listFiles(); for (File file : files) { if (!file.isDirectory()) { continue; } File subFile = lastFileModified(file.getPath(), filter); if (null != subFile && subFile.lastModified() > lastMod) { choice = subFile; lastMod = subFile.lastModified(); } } return choice; }
From source file:com.zimbra.perf.chart.ChartUtil.java
public ChartUtil(File[] confFiles, File[] srcDirs, File destDir, String title, Date startAt, Date endAt, Date aggregateStartAt, Date aggregateEndAt, boolean skipSummary) { mConfs = confFiles;/*from w ww . j a va2s . c o m*/ mSrcDirs = srcDirs; mDestDir = destDir; mTitle = title; mStartAt = startAt != null ? startAt : new Date(Long.MIN_VALUE); mEndAt = endAt != null ? endAt : new Date(Long.MAX_VALUE); mAggregateStartAt = aggregateStartAt != null ? aggregateStartAt : new Date(Long.MIN_VALUE); mAggregateEndAt = aggregateEndAt != null ? aggregateEndAt : new Date(Long.MAX_VALUE); mSkipSummary = skipSummary; mUniqueDataColumns = new HashSet<DataColumn>(); mUniqueStringColumns = new HashSet<DataColumn>(); mColumnsByInfile = new HashMap<String, Set<Pair<String, DataSeries>>>(); mStringSeries = new HashMap<DataColumn, StringSeries>(); mDataSeries = new HashMap<DataColumn, DataSeries>(); mAggregates = new HashMap<DataColumn, Double>(); mAggregator = new Aggregator(); mStats = new HashMap<String, Double>(); }
From source file:org.apache.cocoon.components.store.impl.StoreJanitorImpl.java
private long longDiv(long top, long bottom) { try {//from ww w. j av a 2 s . c o m return top / bottom; } catch (Exception e) { return top > 0 ? Long.MAX_VALUE : Long.MIN_VALUE; } }
From source file:Counter.java
/** Main program entry point. */ public static void main(String argv[]) { // is there anything to do? if (argv.length == 0) { printUsage();/* w w w . ja v a 2 s .c o m*/ System.exit(1); } // variables Counter counter = new Counter(); PrintWriter out = new PrintWriter(System.out); XMLReader parser = null; int repetition = DEFAULT_REPETITION; boolean namespaces = DEFAULT_NAMESPACES; boolean namespacePrefixes = DEFAULT_NAMESPACE_PREFIXES; boolean validation = DEFAULT_VALIDATION; boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION; boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING; boolean honourAllSchemaLocations = DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS; boolean validateAnnotations = DEFAULT_VALIDATE_ANNOTATIONS; boolean dynamicValidation = DEFAULT_DYNAMIC_VALIDATION; boolean xincludeProcessing = DEFAULT_XINCLUDE; boolean xincludeFixupBaseURIs = DEFAULT_XINCLUDE_FIXUP_BASE_URIS; boolean xincludeFixupLanguage = DEFAULT_XINCLUDE_FIXUP_LANGUAGE; boolean memoryUsage = DEFAULT_MEMORY_USAGE; boolean tagginess = DEFAULT_TAGGINESS; // process arguments for (int i = 0; i < argv.length; i++) { String arg = argv[i]; if (arg.startsWith("-")) { String option = arg.substring(1); if (option.equals("p")) { // get parser name if (++i == argv.length) { System.err.println("error: Missing argument to -p option."); continue; } String parserName = argv[i]; // create parser try { parser = XMLReaderFactory.createXMLReader(parserName); } catch (Exception e) { try { Parser sax1Parser = ParserFactory.makeParser(parserName); parser = new ParserAdapter(sax1Parser); System.err.println("warning: Features and properties not supported on SAX1 parsers."); } catch (Exception ex) { parser = null; System.err.println("error: Unable to instantiate parser (" + parserName + ")"); } } continue; } if (option.equals("x")) { if (++i == argv.length) { System.err.println("error: Missing argument to -x option."); continue; } String number = argv[i]; try { int value = Integer.parseInt(number); if (value < 1) { System.err.println("error: Repetition must be at least 1."); continue; } repetition = value; } catch (NumberFormatException e) { System.err.println("error: invalid number (" + number + ")."); } continue; } if (option.equalsIgnoreCase("n")) { namespaces = option.equals("n"); continue; } if (option.equalsIgnoreCase("np")) { namespacePrefixes = option.equals("np"); continue; } if (option.equalsIgnoreCase("v")) { validation = option.equals("v"); continue; } if (option.equalsIgnoreCase("s")) { schemaValidation = option.equals("s"); continue; } if (option.equalsIgnoreCase("f")) { schemaFullChecking = option.equals("f"); continue; } if (option.equalsIgnoreCase("hs")) { honourAllSchemaLocations = option.equals("hs"); continue; } if (option.equalsIgnoreCase("va")) { validateAnnotations = option.equals("va"); continue; } if (option.equalsIgnoreCase("dv")) { dynamicValidation = option.equals("dv"); continue; } if (option.equalsIgnoreCase("xi")) { xincludeProcessing = option.equals("xi"); continue; } if (option.equalsIgnoreCase("xb")) { xincludeFixupBaseURIs = option.equals("xb"); continue; } if (option.equalsIgnoreCase("xl")) { xincludeFixupLanguage = option.equals("xl"); continue; } if (option.equalsIgnoreCase("m")) { memoryUsage = option.equals("m"); continue; } if (option.equalsIgnoreCase("t")) { tagginess = option.equals("t"); continue; } if (option.equals("-rem")) { if (++i == argv.length) { System.err.println("error: Missing argument to -# option."); continue; } System.out.print("# "); System.out.println(argv[i]); continue; } if (option.equals("h")) { printUsage(); continue; } System.err.println("error: unknown option (" + option + ")."); continue; } // use default parser? if (parser == null) { // create parser try { parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME); } catch (Exception e) { System.err.println("error: Unable to instantiate parser (" + DEFAULT_PARSER_NAME + ")"); continue; } } // set parser features try { parser.setFeature(NAMESPACES_FEATURE_ID, namespaces); } catch (SAXException e) { System.err.println("warning: Parser does not support feature (" + NAMESPACES_FEATURE_ID + ")"); } try { parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, namespacePrefixes); } catch (SAXException e) { System.err.println( "warning: Parser does not support feature (" + NAMESPACE_PREFIXES_FEATURE_ID + ")"); } try { parser.setFeature(VALIDATION_FEATURE_ID, validation); } catch (SAXException e) { System.err.println("warning: Parser does not support feature (" + VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation); } catch (SAXNotRecognizedException e) { System.err.println( "warning: Parser does not recognize feature (" + SCHEMA_VALIDATION_FEATURE_ID + ")"); } catch (SAXNotSupportedException e) { System.err .println("warning: Parser does not support feature (" + SCHEMA_VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking); } catch (SAXNotRecognizedException e) { System.err.println( "warning: Parser does not recognize feature (" + SCHEMA_FULL_CHECKING_FEATURE_ID + ")"); } catch (SAXNotSupportedException e) { System.err.println( "warning: Parser does not support feature (" + SCHEMA_FULL_CHECKING_FEATURE_ID + ")"); } try { parser.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, honourAllSchemaLocations); } catch (SAXNotRecognizedException e) { System.err.println( "warning: Parser does not recognize feature (" + HONOUR_ALL_SCHEMA_LOCATIONS_ID + ")"); } catch (SAXNotSupportedException e) { System.err.println( "warning: Parser does not support feature (" + HONOUR_ALL_SCHEMA_LOCATIONS_ID + ")"); } try { parser.setFeature(VALIDATE_ANNOTATIONS_ID, validateAnnotations); } catch (SAXNotRecognizedException e) { System.err.println("warning: Parser does not recognize feature (" + VALIDATE_ANNOTATIONS_ID + ")"); } catch (SAXNotSupportedException e) { System.err.println("warning: Parser does not support feature (" + VALIDATE_ANNOTATIONS_ID + ")"); } try { parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, dynamicValidation); } catch (SAXNotRecognizedException e) { System.err.println( "warning: Parser does not recognize feature (" + DYNAMIC_VALIDATION_FEATURE_ID + ")"); } catch (SAXNotSupportedException e) { System.err.println( "warning: Parser does not support feature (" + DYNAMIC_VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(XINCLUDE_FEATURE_ID, xincludeProcessing); } catch (SAXNotRecognizedException e) { System.err.println("warning: Parser does not recognize feature (" + XINCLUDE_FEATURE_ID + ")"); } catch (SAXNotSupportedException e) { System.err.println("warning: Parser does not support feature (" + XINCLUDE_FEATURE_ID + ")"); } try { parser.setFeature(XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID, xincludeFixupBaseURIs); } catch (SAXNotRecognizedException e) { System.err.println( "warning: Parser does not recognize feature (" + XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID + ")"); } catch (SAXNotSupportedException e) { System.err.println( "warning: Parser does not support feature (" + XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID + ")"); } try { parser.setFeature(XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID, xincludeFixupLanguage); } catch (SAXNotRecognizedException e) { System.err.println( "warning: Parser does not recognize feature (" + XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID + ")"); } catch (SAXNotSupportedException e) { System.err.println( "warning: Parser does not support feature (" + XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID + ")"); } // parse file parser.setContentHandler(counter); parser.setErrorHandler(counter); try { long timeBefore = System.currentTimeMillis(); long memoryBefore = Runtime.getRuntime().freeMemory(); for (int j = 0; j < repetition; j++) { parser.parse(arg); } long memoryAfter = Runtime.getRuntime().freeMemory(); long timeAfter = System.currentTimeMillis(); long time = timeAfter - timeBefore; long memory = memoryUsage ? memoryBefore - memoryAfter : Long.MIN_VALUE; counter.printResults(out, arg, time, memory, tagginess, repetition); } catch (SAXParseException e) { // ignore } catch (Exception e) { System.err.println("error: Parse error occurred - " + e.getMessage()); Exception se = e; if (e instanceof SAXException) { se = ((SAXException) e).getException(); } if (se != null) se.printStackTrace(System.err); else e.printStackTrace(System.err); } } }
From source file:edu.fullerton.ldvservlet.SrcList.java
private PageItem makeTable(ChanSourceData csd, int tblNum) throws WebUtilException { PageItemList ret;/*from w ww . ja v a 2 s . co m*/ ret = new PageItemList(); String cInfo = csd.getChanInfo().toString(); ret.add(new PageItemHeader(cInfo, 3)); ret.addBlankLines(1); String[] frmTypes = csd.getFrameTypes(); String frmStr = ""; for (String s : frmTypes) { frmStr += frmStr.isEmpty() ? s : (", " + s); } PageTable tbl = new PageTable(); TreeSet<TimeInterval> mergedIntervals = csd.getMergedIntervals(); long minGps = Long.MAX_VALUE; long maxGps = Long.MIN_VALUE; long totData = 0; int nIntervals = 0; PageTableRow row; boolean odd = true; String[] colHdrs = { "Start Gps", "Start UTC", "Stop Gps", "Stop UTC", "len (s)", "d HH:MM:SS" }; PageTableRow hdr = new PageTableRow(colHdrs, true); hdr.setRowType(PageTableRow.RowType.HEAD); tbl.addRow(hdr); for (TimeInterval ti : mergedIntervals) { Long strtGps = ti.getStartGps(); Long stopGps = ti.getStopGps(); String strtUtc = TimeAndDate.dateAsUtcString(TimeAndDate.gps2date(strtGps)); String stopUtc = TimeAndDate.dateAsUtcString(TimeAndDate.gps2date(stopGps)); minGps = Math.min(minGps, strtGps); maxGps = Math.max(maxGps, stopGps); long len = stopGps - strtGps; totData += len; nIntervals++; row = new PageTableRow(); row.add(strtGps.toString()); row.add(strtUtc); row.add(stopGps.toString()); row.add(stopUtc); PageTableColumn lenCol = new PageTableColumn(String.format("%1$,d", len)); lenCol.setAlign(PageItem.Alignment.RIGHT); row.add(lenCol); PageTableColumn hrTimeCol = new PageTableColumn(TimeAndDate.hrTime(len, true)); hrTimeCol.setAlign(PageItem.Alignment.RIGHT); row.add(hrTimeCol); row.setClassName(odd ? "odd" : "even"); odd = !odd; tbl.addRow(row); } float pct = totData > 0 ? 100.f * totData / (maxGps - minGps) : 0; String summary; if (nIntervals > 0) { String ftypeInfo = "Data is in frames of type: " + frmStr; ret.add(ftypeInfo); ret.addBlankLines(1); summary = String.format("Available from %1$s (%2$d) to " + "%3$s (%4$d), gaps: %5$d, coverage %6$.1f%%", TimeAndDate.dateAsUtcString(TimeAndDate.gps2date(minGps)), minGps, TimeAndDate.dateAsUtcString(TimeAndDate.gps2date(maxGps)), maxGps, nIntervals - 1, pct); ret.add(summary); ret.addBlankLines(2); String tblId = String.format("tbl%1$02d", tblNum); String btnId = String.format("btn%1$02d", tblNum); String jsCall = String.format("toggleShowById('%1$s','#%2$s')", tblId, btnId); PageFormButton optBtn = new PageFormButton("ShowHideBtn"); optBtn.setText("Show interval table"); optBtn.addEvent("onclick", jsCall); optBtn.setId(btnId); optBtn.setType("button"); optBtn.setClassName("showCmd"); ret.add(optBtn); tbl.setClassName("showHide"); tbl.setId(tblId); ret.add(tbl); ret.addBlankLines(2); } else { ret.add("No source data found."); } return ret; }