Java Code Examples for org.elasticsearch.common.Strings#format1Decimals()

The following examples show how to use org.elasticsearch.common.Strings#format1Decimals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteSizeValue.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    long bytes = bytes();
    double value = bytes;
    String suffix = "b";
    if (bytes >= ByteSizeUnit.C5) {
        value = pbFrac();
        suffix = "pb";
    } else if (bytes >= ByteSizeUnit.C4) {
        value = tbFrac();
        suffix = "tb";
    } else if (bytes >= ByteSizeUnit.C3) {
        value = gbFrac();
        suffix = "gb";
    } else if (bytes >= ByteSizeUnit.C2) {
        value = mbFrac();
        suffix = "mb";
    } else if (bytes >= ByteSizeUnit.C1) {
        value = kbFrac();
        suffix = "kb";
    }
    return Strings.format1Decimals(value, suffix);
}
 
Example 2
Source File: SizeValue.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    long singles = singles();
    double value = singles;
    String suffix = "";
    if (singles >= SizeUnit.C5) {
        value = petaFrac();
        suffix = "p";
    } else if (singles >= SizeUnit.C4) {
        value = teraFrac();
        suffix = "t";
    } else if (singles >= SizeUnit.C3) {
        value = gigaFrac();
        suffix = "g";
    } else if (singles >= SizeUnit.C2) {
        value = megaFrac();
        suffix = "m";
    } else if (singles >= SizeUnit.C1) {
        value = kiloFrac();
        suffix = "k";
    }

    return Strings.format1Decimals(value, suffix);
}
 
Example 3
Source File: ByteSizeValue.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    long bytes = getBytes();
    double value = bytes;
    String suffix = ByteSizeUnit.BYTES.getSuffix();
    if (bytes >= ByteSizeUnit.C5) {
        value = getPbFrac();
        suffix = ByteSizeUnit.PB.getSuffix();
    } else if (bytes >= ByteSizeUnit.C4) {
        value = getTbFrac();
        suffix = ByteSizeUnit.TB.getSuffix();
    } else if (bytes >= ByteSizeUnit.C3) {
        value = getGbFrac();
        suffix = ByteSizeUnit.GB.getSuffix();
    } else if (bytes >= ByteSizeUnit.C2) {
        value = getMbFrac();
        suffix = ByteSizeUnit.MB.getSuffix();
    } else if (bytes >= ByteSizeUnit.C1) {
        value = getKbFrac();
        suffix = ByteSizeUnit.KB.getSuffix();
    }
    return Strings.format1Decimals(value, suffix);
}
 
Example 4
Source File: SizeValue.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    long singles = singles();
    double value = singles;
    String suffix = "";
    if (singles >= SizeUnit.C5) {
        value = petaFrac();
        suffix = "p";
    } else if (singles >= SizeUnit.C4) {
        value = teraFrac();
        suffix = "t";
    } else if (singles >= SizeUnit.C3) {
        value = gigaFrac();
        suffix = "g";
    } else if (singles >= SizeUnit.C2) {
        value = megaFrac();
        suffix = "m";
    } else if (singles >= SizeUnit.C1) {
        value = kiloFrac();
        suffix = "k";
    }

    return Strings.format1Decimals(value, suffix);
}
 
Example 5
Source File: TimeValue.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    if (duration < 0) {
        return Long.toString(duration);
    }
    long nanos = nanos();
    if (nanos == 0) {
        return "0s";
    }
    double value = nanos;
    String suffix = "nanos";
    if (nanos >= C6) {
        value = daysFrac();
        suffix = "d";
    } else if (nanos >= C5) {
        value = hoursFrac();
        suffix = "h";
    } else if (nanos >= C4) {
        value = minutesFrac();
        suffix = "m";
    } else if (nanos >= C3) {
        value = secondsFrac();
        suffix = "s";
    } else if (nanos >= C2) {
        value = millisFrac();
        suffix = "ms";
    } else if (nanos >= C1) {
        value = microsFrac();
        suffix = "micros";
    }
    return Strings.format1Decimals(value, suffix);
}
 
Example 6
Source File: DiskUsage.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return "[" + nodeId + "][" + nodeName + "][" + path + "] free: " + new ByteSizeValue(getFreeBytes()) +
            "[" + Strings.format1Decimals(getFreeDiskAsPercentage(), "%") + "]";
}
 
Example 7
Source File: DiskUsage.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return "[" + nodeId + "][" + nodeName + "][" + path + "] free: " + new ByteSizeValue(getFreeBytes()) +
            "[" + Strings.format1Decimals(getFreeDiskAsPercentage(), "%") + "]";
}