Cooking Units in Java
Asked Answered
O

4

22

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.

Oilstone answered 19/6, 2009 at 17:10 Comment(9)
I love this... deserved its own tagBrumley
What about "pinch", as in "a pinch of salt"?Spree
How many "pinches" in a "smidgen"?Snowcap
a "dash" plus a "pinch" is a "smidgen"... thats some hardcore math thereRech
You could always write one yourself?Yamauchi
@skaffman, are you campaigning for the Taxonomist Badge? <grin>Windbag
From Wikipedia: Dash is 0.62 ml, pinch is 0.31 ml, but I guess smidgen is not a standard measurement.Yamauchi
Haha, man the whole "Java" name isn't helping much here... searches just turn up coffee related content. In fact, this may be the perfect storm of impossible to find on Google, if it does exist at all.Googol
This is my favorite question of the month, haha.Consubstantiate
S
14

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.

Sigmatism answered 19/6, 2009 at 17:54 Comment(0)
R
2

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)

Reflection answered 19/6, 2009 at 17:54 Comment(0)
G
2

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.

Gemology answered 11/10, 2016 at 15:54 Comment(2)
Looks like JSR-365 just got accepted, too. Is this already planned to be included?Iffy
385 is the next version of JSR 363. The best place for those kinds of domain-specific units would be github.com/unitsofmeasurement/uom-domain. Please feel free to create a ticket as new feature request.Gemology
Y
1

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.

Yamauchi answered 19/6, 2009 at 17:21 Comment(1)
Here's a web service! webservicex.net/WS/WSDetails.aspx?WSID=25&CATID=13Googol

© 2022 - 2024 — McMap. All rights reserved.