All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.binaryprefix.BinaryScaledAmount Maven / Gradle / Ivy

Go to download

Library for use in Java components of Vespa. Shared code which do not fit anywhere else.

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.binaryprefix;

/**
 * An amount scaled by a binary prefix.
 *
 * 

* Examples: 2 kilo, 2 mega, ... *

* * @author Tony Vaagenes */ public final class BinaryScaledAmount { public final double amount; public final BinaryPrefix binaryPrefix; public BinaryScaledAmount(double amount, BinaryPrefix binaryPrefix) { this.amount = amount; this.binaryPrefix = binaryPrefix; } public BinaryScaledAmount() { this(0, BinaryPrefix.unit); } public long as(BinaryPrefix newBinaryPrefix) { return Math.round(newBinaryPrefix.convertFrom(amount, binaryPrefix)); } public boolean equals(BinaryScaledAmount candidate) { return BinaryPrefix.unit.convertFrom(amount, binaryPrefix) == BinaryPrefix.unit.convertFrom(candidate.amount, candidate.binaryPrefix); } public BinaryScaledAmount multiply(double d) { return new BinaryScaledAmount(d*amount, binaryPrefix); } public BinaryScaledAmount divide(double d) { return multiply(1/d); } @Override public boolean equals(Object candidate) { if (!(candidate instanceof BinaryScaledAmount)) { return false; } else { return equals((BinaryScaledAmount)candidate); } } @Override public int hashCode() { return (int)BinaryPrefix.unit.convertFrom(amount, binaryPrefix); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy