Skip to content

Instantly share code, notes, and snippets.

@kijuky
Created May 28, 2011 17:31
Show Gist options
  • Save kijuky/997051 to your computer and use it in GitHub Desktop.
Save kijuky/997051 to your computer and use it in GitHub Desktop.
独自Quantityの動作確認(JScience自動で取ってきます)
@GrabResolver(name='jsciencerepos', root='http://maven.obiba.org/maven2/')
@Grab('org.jscience:jscience:4.3.1')
import javax.measure.quantity.Quantity
import javax.measure.unit.ProductUnit
import javax.measure.unit.Unit
import org.jscience.physics.amount.Amount
import static javax.measure.unit.SI.*
interface HeatCapacityFlowRate extends Quantity {
def UNIT = new ProductUnit(KILO(WATT).divide(KELVIN))
}
a = Amount.valueOf("1 kW")
b = Amount.valueOf("1 K")
c = a.divide(b)
// どうせ型消去されるなら asType とかしても無意味
//CP = c.unit.asType(HeatCapacityFlowRate.class)
//d = c.to(CP) // > 1 kW/K
// そもそも、インターフェースという「型」を扱わない時点で、こんなのいらない
//d = c.to(HeatCapacityFlowRate.UNIT)
// 結局、使うんであれば、直接単位を打ち込むか、
// 既にある量(Quantity)に定義されたUNIT使うか、どちらか。
// Quantity使うなら、それは.javaで記述したほうが、どの言語からでも読めるので、そっちのほうがいい。
d = c.to(KILO(WATT).divide(KELVIN))
// もしくは、型を書いてしまうということもあるが、それはGroovy使う旨みがない
// Amount<HeatCapacityFlowRate> d = c.to(HeatCapacityFlowRate.UNIT)
@kijuky
Copy link
Author

kijuky commented May 28, 2011

CP は Unit[HeatCapacityFlowRate] なので、
c.to(CP) によって Amount[HeatCapacityFlowRate] が生まれます。
…型消去されてるので、あまり意味はありませんが。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment