爪哇的烹饪单位

发布于 2024-07-24 07:34:50 字数 188 浏览 6 评论 0原文

是否有任何开源库可以用 Java 表示茶匙和汤匙等烹饪单位?

我只找到了 JSR-275 (https://jcp.org/en/jsr/详细信息?id=275)这很棒,但不了解烹饪装置。

Are there any open source libraries for representing cooking units such as Teaspoon and tablespoon in Java?

I have only found JSR-275 (https://jcp.org/en/jsr/detail?id=275) which is great but doesn't know about cooking units.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅唱ヾ落雨殇 2024-07-31 07:34:50

JScience 是可扩展的,因此您应该能够创建 javax.measure.unit.SystemOfUnits 的子类。 您将创建许多公共静态最终声明,如下所示:

public final class Cooking extends SystemOfUnits {
  private static HashSet<Unit<?>> UNITS = new HashSet<Unit<?>>();

  private Cooking() {
  }

  public static Cooking getInstance() {
    return INSTANCE;
  }
  private static final Cooking INSTANCE = new SI();

  public static final BaseUnit<CookingVolume> TABLESPOON = si(new BaseUnit<CookingVolume>("Tbsp"));

  ...

   public static final Unit<CookingVolume> GRAM = TABLESPOON.divide(1000);

}

public interface CookingVolume extends Quantity {
  public final static Unit<CookingVolume> UNIT = Cooking.TABLESPOON;
}

只要您知道转换系数是什么,定义其他单位和转换就非常简单。

JScience is extensible, so you should be able to create a subclass of javax.measure.unit.SystemOfUnits. You'll create a number of public static final declarations like this:

public final class Cooking extends SystemOfUnits {
  private static HashSet<Unit<?>> UNITS = new HashSet<Unit<?>>();

  private Cooking() {
  }

  public static Cooking getInstance() {
    return INSTANCE;
  }
  private static final Cooking INSTANCE = new SI();

  public static final BaseUnit<CookingVolume> TABLESPOON = si(new BaseUnit<CookingVolume>("Tbsp"));

  ...

   public static final Unit<CookingVolume> GRAM = TABLESPOON.divide(1000);

}

public interface CookingVolume extends Quantity {
  public final static Unit<CookingVolume> UNIT = Cooking.TABLESPOON;
}

It's pretty straightforward to define the other units and conversions, just as long as you know what the conversion factors are.

坚持沉默 2024-07-31 07:34:50

这可能会有一些用处:JUnitConv。 它是一个用于转换单位(包括烹饪单位)的 Java 小程序,但它是 GPL 许可的,因此您可以下载源代码并调整相关部分以供您自己使用。

另一方面,看起来创建一个符合 JSR 275 的 CookingUnits 类应该不难。(这就是我要做的)

This might be of some use: JUnitConv. It's a Java applet for converting units (including cooking units), but it's GPL-licensed so you could download the source and adapt the relevant parts for your own use.

On the other hand, it looks like it shouldn't be hard to create a CookingUnits class compliant with JSR 275. (That's what I'd do)

手长情犹 2024-07-31 07:34:50

恐怕,我们无法帮助您处理 JSR-275,因为它被拒绝了,但是 JSR-363 只是九月进入决赛,所以如果您对“烹饪单位”等单位系统有好主意,请在 UoM 系统

I'm afraid, we can't help you with JSR-275 as it was rejected, but JSR-363 just went Final in September, so if you have a great idea for unit systems like "Cooking Units", please just let us know under UoM-Systems.

夏末的微笑 2024-07-31 07:34:50

我想你可以解析维基页面以获取烹饪测量:烹饪重量和测量

它拥有所有度量以表格形式组织,因此解析它们应该很容易。

I guess you can parse the wiki page for cooking measurements: Cooking Weights and Measures

It has all the measures organized in tables, so it should be pretty easy to parse them out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文