it.unimi.dsi.Util.format()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(15.1k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中it.unimi.dsi.Util.format()方法的一些代码示例,展示了Util.format()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.format()方法的具体详情如下:
包路径:it.unimi.dsi.Util
类名称:Util
方法名:format

Util.format介绍

[英]Formats a number.

This method formats a double separating thousands and printing just two fractional digits.
[中]格式化一个数字。
这种方法格式化一个分隔千位的双精度格式,只打印两个小数位数。

代码示例

代码示例来源:origin: it.unimi.dsi/dsiutils

private String itemsPerTimeInterval(long startCount, final long currentTime, long baseTime) {
  final double secondsPerItem = ((count - startCount) * 1000.0) / (currentTime - baseTime);
  if (speedTimeUnit == TimeUnit.SECONDS || speedTimeUnit == null && secondsPerItem >= 1) return Util.format(secondsPerItem) + " " + itemsName +  "/s";
  if (speedTimeUnit == TimeUnit.MINUTES || speedTimeUnit == null && secondsPerItem * 60 >= 1) return Util.format(secondsPerItem * 60) + " " + itemsName +  "/m";
  if (speedTimeUnit == TimeUnit.HOURS || speedTimeUnit == null && secondsPerItem * 3600 >= 1) return Util.format(secondsPerItem * 3600) + " " + itemsName +  "/h";
  return Util.format(secondsPerItem * 86400) + " " + itemsName +  "/d";
}

代码示例来源:origin: it.unimi.di/mg4j

private static String format( long v, long total ) {
  return v + " (" + Util.formatSize( v / 8 ) + "B, " + Util.format( 100. * v / total ) + "%)\n";
}

代码示例来源:origin: blazegraph/database

/** Formats a size.
 *
 * <P>This method formats a long using suitable unit multipliers (e.g., <samp>K</samp>, <samp>M</samp>, <samp>G</samp>, and <samp>T</samp>)
 * and printing just two fractional digits.
 * @param l a number, representing a size (e.g., memory).
 * @return a string containing a pretty print of the number using unit multipliers.
 */
public static String formatSize( final long l ) {
  if ( l >= 1000000000000L ) return format( l / 1000000000000.0 ) + "T";
  if ( l >= 1000000000L ) return format( l / 1000000000.0 ) + "G";
  if ( l >= 1000000L ) return format( l / 1000000.0 ) + "M";
  if ( l >= 1000L ) return format( l / 1000.0 ) + "K";
  return Long.toString( l );
}

代码示例来源:origin: it.unimi.di/mg4j-big

public void printStats( PrintStream stats ) {
    stats.println( "Number of documents: " + Util.format( numberOfDocuments ) );
    stats.println( "Number of terms: " + Util.format( currentTerm + 1 ) );
    
    stats.println( "Frequencies: " + Util.format( bitsForFrequencies ) + " bits, " + Util.format( bitsForFrequencies / ( currentTerm + 1.0 ) ) + " bits/frequency." );
    stats.println( "Document pointers: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForPointers ) + " bits, " + Util.format( bitsForPointers / (double)numberOfPostings ) + " bits/pointer).");

    if ( hasCounts ) stats.println( "Counts: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForCounts ) + " bits, " + Util.format( bitsForCounts/ (double)numberOfPostings ) + " bits/count).");
    if ( hasPositions ) stats.println( "Occurrences: " + Util.format( numberOfOccurrences ) + " (" +  Util.format( bitsForPositions ) + " bits, " + Util.format( bitsForPositions / (double)numberOfOccurrences ) + " bits/occurrence).");
    if ( hasPayloads ) stats.println( "Payloads: " + Util.format( numberOfPostings )  + " (" + Util.format( bitsForPayloads ) + " bits, " + Util.format( bitsForPayloads / (double)numberOfPostings )  + " bits/payload)." );
    if ( hasPositions ) stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfOccurrences ) + " bits/occurrence" );
    else stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfPostings ) + " bits/posting" );
  }
}

代码示例来源:origin: it.unimi.di/mg4j

public void printStats( PrintStream stats ) {
    stats.println( "Number of documents: " + Util.format( numberOfDocuments ) );
    stats.println( "Number of terms: " + Util.format( currentTerm + 1 ) );
    
    stats.println( "Frequencies: " + Util.format( bitsForFrequencies ) + " bits, " + Util.format( bitsForFrequencies / ( currentTerm + 1.0 ) ) + " bits/frequency." );
    stats.println( "Document pointers: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForPointers ) + " bits, " + Util.format( bitsForPointers / (double)numberOfPostings ) + " bits/pointer).");

    if ( hasCounts ) stats.println( "Counts: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForCounts ) + " bits, " + Util.format( bitsForCounts/ (double)numberOfPostings ) + " bits/count).");
    if ( hasPositions ) stats.println( "Occurrences: " + Util.format( numberOfOccurrences ) + " (" +  Util.format( bitsForPositions ) + " bits, " + Util.format( bitsForPositions / (double)numberOfOccurrences ) + " bits/occurrence).");
    if ( hasPayloads ) stats.println( "Payloads: " + Util.format( numberOfPostings )  + " (" + Util.format( bitsForPayloads ) + " bits, " + Util.format( bitsForPayloads / (double)numberOfPostings )  + " bits/payload)." );
    if ( hasPositions ) stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfOccurrences ) + " bits/occurrence" );
    else stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfPostings ) + " bits/posting" );
  }
}

代码示例来源:origin: it.unimi.dsi/mg4j

public void printStats( PrintStream stats ) {
    stats.println( "Number of documents: " + Util.format( numberOfDocuments ) );
    stats.println( "Number of terms: " + Util.format( currentTerm + 1 ) );
    
    stats.println( "Frequencies: " + Util.format( bitsForFrequencies ) + " bits, " + Util.format( bitsForFrequencies / ( currentTerm + 1.0 ) ) + " bits/frequency." );
    stats.println( "Document pointers: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForPointers ) + " bits, " + Util.format( bitsForPointers / (double)numberOfPostings ) + " bits/pointer).");

    if ( hasCounts ) stats.println( "Counts: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForCounts ) + " bits, " + Util.format( bitsForCounts/ (double)numberOfPostings ) + " bits/count).");
    if ( hasPositions ) stats.println( "Occurrences: " + Util.format( numberOfOccurrences ) + " (" +  Util.format( bitsForPositions ) + " bits, " + Util.format( bitsForPositions / (double)numberOfOccurrences ) + " bits/occurrence).");
    if ( hasPayloads ) stats.println( "Payloads: " + Util.format( numberOfPostings )  + " (" + Util.format( bitsForPayloads ) + " bits, " + Util.format( bitsForPayloads / (double)numberOfPostings )  + " bits/payload)." );
    if ( hasPositions ) stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfOccurrences ) + " bits/occurrence" );
    else stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfPostings ) + " bits/posting" );
  }
}

代码示例来源:origin: it.unimi.dsi/mg4j-big

public void printStats( PrintStream stats ) {
    stats.println( "Number of documents: " + Util.format( numberOfDocuments ) );
    stats.println( "Number of terms: " + Util.format( currentTerm + 1 ) );
    
    stats.println( "Frequencies: " + Util.format( bitsForFrequencies ) + " bits, " + Util.format( bitsForFrequencies / ( currentTerm + 1.0 ) ) + " bits/frequency." );
    stats.println( "Document pointers: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForPointers ) + " bits, " + Util.format( bitsForPointers / (double)numberOfPostings ) + " bits/pointer).");

    if ( hasCounts ) stats.println( "Counts: " + Util.format( numberOfPostings ) + " (" + Util.format( bitsForCounts ) + " bits, " + Util.format( bitsForCounts/ (double)numberOfPostings ) + " bits/count).");
    if ( hasPositions ) stats.println( "Occurrences: " + Util.format( numberOfOccurrences ) + " (" +  Util.format( bitsForPositions ) + " bits, " + Util.format( bitsForPositions / (double)numberOfOccurrences ) + " bits/occurrence).");
    if ( hasPayloads ) stats.println( "Payloads: " + Util.format( numberOfPostings )  + " (" + Util.format( bitsForPayloads ) + " bits, " + Util.format( bitsForPayloads / (double)numberOfPostings )  + " bits/payload)." );
    if ( hasPositions ) stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfOccurrences ) + " bits/occurrence" );
    else stats.println( "Total: " + Util.format( writtenBits() ) + " bits, " + Util.format( writtenBits() / (double)numberOfPostings ) + " bits/posting" );
  }
}

代码示例来源:origin: blazegraph/database

/** Converts the data stored in this progress logger to a string. 
   * 
   * @return the data in this progress logger in a printable form.
   */
  
  public String toString() {
    final long t = stop - start + 1 ;
  
    if ( t <= 0 ) return "Illegal progress logger state";

    return "Elapsed: " + millis2hms( t ) + ( count != 0 ? " [" + Util.format( count ) + " " + itemsName + ", " + Util.format( count / ( t / 1000.0 ) ) + " " + itemsName + "/s]" : "" );
  }
}

代码示例来源:origin: it.unimi.dsi/mg4j-big

/** Converts the data stored in this meter to a string. 
   * 
   * @return the data in this meter in a printable form.
   */
  
  public String toString() {
    final long t = stop - start + 1 ;
  
    if ( t <= 0 ) return "Illegal meter state";

    return "Elapsed: " + millis2hms( t ) + ( count != 0 ? " [" + Util.format( count ) + " " + itemsName + ", " + Util.format( count / ( t / 1000.0 ) ) + " " + itemsName + "/s]" : "" );
  }
}

代码示例来源:origin: it.unimi.dsi/mg4j

/** Converts the data stored in this meter to a string. 
   * 
   * @return the data in this meter in a printable form.
   */
  
  public String toString() {
    final long t = stop - start + 1 ;
  
    if ( t <= 0 ) return "Illegal meter state";

    return "Elapsed: " + millis2hms( t ) + ( count != 0 ? " [" + Util.format( count ) + " " + itemsName + ", " + Util.format( count / ( t / 1000.0 ) ) + " " + itemsName + "/s]" : "" );
  }
}

代码示例来源:origin: com.blazegraph/dsi-utils

/** Converts the data stored in this progress logger to a string. 
   * 
   * @return the data in this progress logger in a printable form.
   */
  
  public String toString() {
    final long t = stop - start + 1 ;
  
    if ( t <= 0 ) return "Illegal progress logger state";

    return "Elapsed: " + millis2hms( t ) + ( count != 0 ? " [" + Util.format( count ) + " " + itemsName + ", " + Util.format( count / ( t / 1000.0 ) ) + " " + itemsName + "/s]" : "" );
  }
}

代码示例来源:origin: it.unimi.dsi/sux4j

/** Closes this store, disposing all associated resources. */
@Override
public void close() throws IOException {
  if (! closed) {
    LOGGER.debug("Wall clock for quicksort: " + Util.format(quickSortWallTime / 1E9) + "s");
    closed = true;
    for(final WritableByteChannel channel: writableByteChannel) channel.close();
    for(final File f: file) f.delete();
  }
}

代码示例来源:origin: it.unimi.dsi/dsiutils

private String timePerItem(long startCount, final long currentTime, long baseTime) {
  final double secondsPerItem = (currentTime - baseTime) / ((count - startCount) * 1000.0);
  if (itemTimeUnit == null && secondsPerItem >= 86400) return Util.format(secondsPerItem / 86400) + " d/" + itemName();
  if (itemTimeUnit == TimeUnit.HOURS || itemTimeUnit == null && secondsPerItem >= 3600) return Util.format(secondsPerItem / 3600) + " h/" + itemName();
  if (itemTimeUnit == TimeUnit.MINUTES || itemTimeUnit == null && secondsPerItem >= 60) return Util.format(secondsPerItem / 60) + " m/" + itemName();
  if (itemTimeUnit == TimeUnit.SECONDS || itemTimeUnit == null && secondsPerItem >= 1) return Util.format(secondsPerItem) + " s/" + itemName();
  if (itemTimeUnit == TimeUnit.MILLISECONDS || itemTimeUnit == null && secondsPerItem >= 1E-3) return Util.format(secondsPerItem * 1E3) + " ms/" + itemName();
  if (itemTimeUnit == TimeUnit.MICROSECONDS || itemTimeUnit == null && secondsPerItem >= 1E-6) return Util.format(secondsPerItem * 1E6) + " \u00b5s/" + itemName();
  return Util.format(secondsPerItem * 1E9) + " ns/" + itemName();
}

代码示例来源:origin: blazegraph/database

private void updateInternal() {
  final long currentTime = System.currentTimeMillis();
  final long millisToEnd = Math.round( ( expectedUpdates - count ) * ( ( currentTime - start ) / ( count + 1.0 ) ) );
  // Formatting is expensive, so we check for actual logging.
  if ( logger.isEnabledFor( priority ) ) 
    logger.log( priority, Util.format( count ) + " " + itemsName + ", " + 
        millis2hms( millis() ) + ", " + Util.format( ( count * 1000.0 ) / ( currentTime - start ) ) + " " + itemsName + 
        "/s"  + ( expectedUpdates > 0 ? "; " + Util.format( ( 100 * count ) / expectedUpdates ) + "% done, " + 
        millis2hms( millisToEnd ) + " to end" : "" ) + freeMemory() + ( info != null ? "; " + info : "" ) );
  lastLog = currentTime;
  return;
}

代码示例来源:origin: com.blazegraph/dsi-utils

private void updateInternal() {
  final long currentTime = System.currentTimeMillis();
  final long millisToEnd = Math.round( ( expectedUpdates - count ) * ( ( currentTime - start ) / ( count + 1.0 ) ) );
  // Formatting is expensive, so we check for actual logging.
  if ( logger.isEnabledFor( priority ) ) 
    logger.log( priority, Util.format( count ) + " " + itemsName + ", " + 
        millis2hms( millis() ) + ", " + Util.format( ( count * 1000.0 ) / ( currentTime - start ) ) + " " + itemsName + 
        "/s"  + ( expectedUpdates > 0 ? "; " + Util.format( ( 100 * count ) / expectedUpdates ) + "% done, " + 
        millis2hms( millisToEnd ) + " to end" : "" ) + freeMemory() + ( info != null ? "; " + info : "" ) );
  lastLog = currentTime;
  return;
}

代码示例来源:origin: it.unimi.dsi/webgraph

protected static void logBatches(final ObjectArrayList<File> batches, final long pairs, final ProgressLogger pl) {
  long length = 0;
  for(final File f : batches) length += f.length();
  pl.logger().info("Created " + batches.size() + " batches using " + Util.format((double)Byte.SIZE * length / pairs) + " bits/arc.");
}

代码示例来源:origin: it.unimi.dsi/dsiutils

@Override
  public String toString() {
    return "[size: " + Util.format(size64()) + " min: " + min + " max: " + max + " \u03BC: " + mean() + " \u03C3: " + sampleStandardDeviation() + " (" + Util.format(100 * sampleRelativeStandardDeviation()) + " %)]";
  }
}

代码示例来源:origin: it.unimi.di/mg4j-big

public enum IndexType {
  /** An old-style, interleaved index. */
  INTERLEAVED,
  /** A high-performance index which stores position separately. */
  HIGH_PERFORMANCE,
  /** A quasi-succinct index. */
  QUASI_SUCCINCT
}

代码示例来源:origin: it.unimi.di/mg4j

public enum IndexType {
  /** An old-style, interleaved index. */
  INTERLEAVED,
  /** A high-performance index which stores position separately. */
  HIGH_PERFORMANCE,
  /** A quasi-succinct index. */
  QUASI_SUCCINCT
}

代码示例来源:origin: it.unimi.dsi/dsiutils

private void updateInternal(final long currentTime) {
  final long millisToEnd = Math.round((expectedUpdates - count) * ((currentTime - startTime) / (count + 1.0)));
  // Formatting is expensive, so we check for actual logging.
  if (logger().isInfoEnabled())
    logger().info(Util.format(count) + " " + itemsName + ", " +
        millis2hms(millis()) + ", " + itemsPerTimeInterval(0, currentTime, startTime) + ", " + timePerItem(0, currentTime, startTime) +
        (displayLocalSpeed ? " [" + itemsPerTimeInterval(lastCount, currentTime, lastLogTime) + ", " + timePerItem(lastCount, currentTime, lastLogTime) + "]" : "") +
        (expectedUpdates > 0 ? "; " + Util.format((100 * count) / expectedUpdates) + "% done, " +
        millis2hms(millisToEnd) + " to end" : "") + freeMemory() + (info != null ? "; " + info : ""));
  lastLogTime = currentTime;
  lastCount = count;
  return;
}

相关文章