public class Product extends Object
Represents a Product in a ProductLine.
The data of a Product originally comes from the Systembolaget's open data with their product line. An example product is shown below:
<artikel> <nr>152115</nr> <Artikelid>1087400</Artikelid> <Varnummer>1521</Varnummer> <Namn>Williams Caesar Augustus</Namn> <Namn2>Lager IPA Hybrid</Namn2> <Prisinklmoms>16.90</Prisinklmoms> <Pant>1.00</Pant> <Volymiml>330.00</Volymiml> <PrisPerLiter>51.21</PrisPerLiter> <Saljstart>2016-09-01</Saljstart> <Utgått>0</Utgått> <Varugrupp>Öl</Varugrupp> <Typ>Ljus lager</Typ> <Stil>Modern stil</Stil> <Forpackning>Burk</Forpackning> <Forslutning/> <Ursprung/> <Ursprunglandnamn>Storbritannien</Ursprunglandnamn> <Producent>Williams Brothers</Producent> <Leverantor>Brill & Co AB</Leverantor> <Argang/> <Provadargang/> <Alkoholhalt>4.00%</Alkoholhalt> <Sortiment>BS</Sortiment> <SortimentText>Övrigt sortiment</SortimentText> <Ekologisk>0</Ekologisk> <Etiskt>0</Etiskt> <Koscher>0</Koscher> <RavarorBeskrivning>Kornmalt samt humle av sorterna savinjski goldings, calypso och citra.</RavarorBeskrivning> </artikel>
This class uses a builder for creation of its instances. The builder is the nested class Product.Builder. A typical usage is shown below:
Product p1 = new Product.Builder() .name("Renat") .price(209.00) .alcohol(37.50) .volume(700) .nr(101) .productGroup("Okryddad sprit") .build(); // Do something with p1...Note that typically, Products aren't hardcoded like above. Typically, they rather are built using external data, e.g. from a database or some web API call, etc.
Modifier and Type | Class and Description |
---|---|
static class |
Product.Builder
Defines a Builder for an Object.
|
static interface |
Product.Exporter
Defines the interface for objects we can export a
Product instance to.
|
Modifier and Type | Field and Description |
---|---|
static Comparator<Product> |
ALCOHOL_ORDER
A Comparator that orders Products based on their alcohol level.
|
static Comparator<Product> |
NAME_CASE_INSENSITIVE_ORDER
A Comparator that orders Products based on their name, ignoring case.
|
static Comparator<Product> |
NAME_ORDER
A Comparator that orders Products based on their name.
|
static Comparator<Product> |
PRICE_ORDER
A Comparator that orders Products based on their price.
|
static Comparator<Product> |
VOLUME_ORDER
A Comparator that orders Products based on their volume.
|
Constructor and Description |
---|
Product(Product.Builder builder)
Constructs a Product using a Product.Builder
|
Product(String name,
double alcohol,
double price,
int volume)
Constructs a new Product.
|
Modifier and Type | Method and Description |
---|---|
double |
alcohol()
Returns the alcohol level of this Product
|
boolean |
equals(Object other)
Uses name, alcohol, volume, price and nr
when deciding if this Product is equal to
another Product.
|
void |
export(Product.Exporter builder)
This methods allows a Product to export itself to
an Exporter object, which could be used to create
various representations or other uses of this Product,
like for instance, a CSV row, an XML element, an
SQL insert statement, a PreparedStatement, a GUI component
or whatever.
|
int |
hashCode() |
String |
name()
Returns the name of this Product
|
int |
nr()
Returns the product number of this Product
|
double |
price()
Returns the price of this Product
|
String |
productGroup()
Returns the product group of this Product
|
String |
toString()
Returns this Product as a String on the format:
|
String |
type()
Returns the product type of this Product
|
int |
volume()
Returns the volume of this Product
|
public static final Comparator<Product> NAME_ORDER
public static final Comparator<Product> NAME_CASE_INSENSITIVE_ORDER
public static final Comparator<Product> PRICE_ORDER
public static final Comparator<Product> ALCOHOL_ORDER
public static final Comparator<Product> VOLUME_ORDER
public Product(Product.Builder builder)
builder
- The builder to use for building this Productpublic Product(String name, double alcohol, double price, int volume)
name
- The name of this Productalcohol
- The alcohol level (in percent alcohol by weight) of this Productprice
- The price of this Product (in SEK)volume
- The volume (in millilitres) of this productpublic void export(Product.Exporter builder)
builder
- The Exporter to export ourselves topublic String name()
public double alcohol()
public double price()
public int volume()
public String productGroup()
public String type()
public int nr()
public String toString()
NAME, PERCENT_ALCOHOL%, VOLUME ml, PRICE SEKFor instance:
Renat, 37.50%, 700 ml, 209.00 SEK
public boolean equals(Object other)