Compare commits
No commits in common. "22064c8c7ccf194a98ce661d3c06f232ae9cec00" and "6de543b0a0a25c76412db193172298a344dfbf28" have entirely different histories.
22064c8c7c
...
6de543b0a0
61 changed files with 181 additions and 1861 deletions
|
|
@ -5,7 +5,7 @@ package org.pasteque.common.datasource;
|
|||
*/
|
||||
public class AssociationInconsistencyException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -979786104345156783L;
|
||||
|
||||
/** {@see getFromField()} */
|
||||
private final String fromField;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class APIVersionDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 4654741357430549138L;
|
||||
|
||||
/** {@see getLevel()} */
|
||||
private final int level;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class CategoryDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 8211717550217795453L;
|
||||
|
||||
/** {@see getParent} */
|
||||
private final Integer parent;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.pasteque.coreutil.ImmutableList;
|
|||
*/
|
||||
public class CompositionDTO extends ProductDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -3223110713928387147L;
|
||||
|
||||
/** Always true */
|
||||
protected final boolean composition = true;
|
||||
|
|
@ -92,7 +92,7 @@ public class CompositionDTO extends ProductDTO implements Serializable
|
|||
*/
|
||||
public class CompositionGroupDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -5237752185922817170L;
|
||||
|
||||
/** {@see getLabel()} */
|
||||
private final String label;
|
||||
|
|
@ -144,7 +144,7 @@ public class CompositionDTO extends ProductDTO implements Serializable
|
|||
*/
|
||||
public class CompositionProductDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 4024627602322411550L;
|
||||
|
||||
/** {@see getProduct()} */
|
||||
private final int product;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class CurrencyDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -6259735426241774167L;
|
||||
|
||||
/** {@see getSymbol()} */
|
||||
private final String symbol;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class CustomerDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2904701878615495822L;
|
||||
|
||||
/** {@see getCard()} */
|
||||
private final String card;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class DiscountProfileDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -2505636588019239236L;
|
||||
|
||||
/** See {@link getDiscountRate()}. */
|
||||
private final double discountRate;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class FloorDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -4474106026709243994L;
|
||||
|
||||
/** {@see getPlaces()} */
|
||||
private final ImmutableList<PlaceDTO> places;
|
||||
|
|
@ -71,7 +71,7 @@ public class FloorDTO extends CommonDTO implements Serializable
|
|||
*/
|
||||
public class PlaceDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 8129968704161611106L;
|
||||
|
||||
/** {@see getLabel()} */
|
||||
private final String label;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class ImageDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -7807272808383007554L;
|
||||
|
||||
/** {@see getModel()} */
|
||||
private final String model;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class OptionDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 8951727299457218490L;
|
||||
|
||||
/** {@see getName()} */
|
||||
private final String name;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class OrderDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -3898628758749878634L;
|
||||
|
||||
/** See {@link getId()}. */
|
||||
private final String id;
|
||||
|
|
@ -194,7 +194,7 @@ public class OrderDTO implements DTOInterface, Serializable
|
|||
*/
|
||||
public class OrderLineDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 8802466032089572015L;
|
||||
|
||||
/** See {@link getDispOrder()}. */
|
||||
private final int dispOrder;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import org.pasteque.coreutil.ImmutableList;
|
|||
*/
|
||||
public class PaymentModeDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 5324960228614648256L;
|
||||
|
||||
/** {@see getBackLabel()} */
|
||||
private final String backLabel;
|
||||
|
|
@ -139,7 +139,7 @@ public class PaymentModeDTO extends CommonDTO implements Serializable
|
|||
*/
|
||||
public class PaymentModeValueDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 5503522521532600750L;
|
||||
|
||||
/** {@see getValue()} */
|
||||
private final double value;
|
||||
|
|
@ -195,7 +195,7 @@ public class PaymentModeDTO extends CommonDTO implements Serializable
|
|||
*/
|
||||
public class PaymentModeReturnDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -5076562956398887860L;
|
||||
|
||||
/** {@see getMinAmount()} */
|
||||
private double minAmount;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class ProductDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -6083885399091129846L;
|
||||
|
||||
/** {@see getBarcode()} */
|
||||
protected final String barcode;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class ResourceDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -7746795788087018857L;
|
||||
|
||||
/** {@see getModel()} */
|
||||
private final String label;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import org.pasteque.coreutil.ImmutableList;
|
|||
*/
|
||||
public class RoleDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1835635017595972352L;
|
||||
|
||||
/** {@see getPermissions()} */
|
||||
private final ImmutableList<String> permissions;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.pasteque.coreutil.ImmutableList;
|
|||
*/
|
||||
public class TariffAreaDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -2639559615366931293L;
|
||||
|
||||
/** {@see getSymbol()} */
|
||||
private final ImmutableList<TariffAreaPriceDTO> prices;
|
||||
|
|
@ -70,7 +70,7 @@ public class TariffAreaDTO extends CommonDTO implements Serializable
|
|||
*/
|
||||
public class TariffAreaPriceDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 3384262202026051762L;
|
||||
|
||||
/** See {@link getProduct()}. */
|
||||
private int product;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class TaxDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 8232927221600250003L;
|
||||
|
||||
/** See {@link getTaxRate()}. */
|
||||
private final double taxRate;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class UserDTO extends CommonDTO implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 5162729826784894378L;
|
||||
|
||||
/** {@see getRole()} */
|
||||
private final int role;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.function.Consumer;
|
|||
*/
|
||||
public final class ImmutableList<T> implements Iterable<T>, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 4982637247874555568L;
|
||||
|
||||
/** See {@link get(int)} or {@link iterator()}. */
|
||||
private List<T> content;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package org.pasteque.coreutil;
|
|||
*/
|
||||
public class ParseException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 3552338953002779225L;
|
||||
|
||||
/**
|
||||
* Create a generic exception with only a message.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
|||
import org.pasteque.coreutil.datatransfer.integrity.InvalidFieldException;
|
||||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Physical cash register hardware Data Transfer Object.</p>
|
||||
|
|
@ -16,33 +15,30 @@ import org.pasteque.coreutil.extra.ExtraObject;
|
|||
*/
|
||||
public final class CashRegisterDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1079581813013284003L;
|
||||
|
||||
/** See {@link getReference()}. */
|
||||
/** {@see getReference()} */
|
||||
private String reference;
|
||||
/** See {@link getLabel()}. */
|
||||
|
||||
/** {@see getLabel()} */
|
||||
private String label;
|
||||
/** See {@link getNextTicketNumber()}. */
|
||||
|
||||
/** {@see getNextTicketNumber()} */
|
||||
private int nextTicketNumber;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create from all fields.
|
||||
* @param reference The unique reference.
|
||||
* @param label The display name.
|
||||
* @param nextTicketNumber See {@link getNextTicketNumber}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public CashRegisterDTO(
|
||||
String reference,
|
||||
String label,
|
||||
int nextTicketNumber,
|
||||
ExtraObject extra) {
|
||||
int nextTicketNumber) {
|
||||
this.reference = reference;
|
||||
this.label = label;
|
||||
this.nextTicketNumber = nextTicketNumber;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -55,7 +51,6 @@ public final class CashRegisterDTO implements DTOInterface, Serializable
|
|||
this.reference = reader.readString("reference");
|
||||
this.label = reader.readString("label");
|
||||
this.nextTicketNumber = reader.readInt("nextTicketId");
|
||||
this.extra = reader.readExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,14 +78,6 @@ public final class CashRegisterDTO implements DTOInterface, Serializable
|
|||
return nextTicketNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the reference and labels are set and nextTicketNumber is
|
||||
* positive or zero.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import org.pasteque.coreutil.ParseException;
|
|||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
||||
import org.pasteque.coreutil.datatransfer.parser.DTOFactory;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Non finished cash session Data Transfer Object.</p>
|
||||
|
|
@ -18,7 +17,7 @@ import org.pasteque.coreutil.extra.ExtraObject;
|
|||
*/
|
||||
public final class CashSessionDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2312930086844551950L;
|
||||
|
||||
/** See {@link getCashRegister()}. */
|
||||
private WeakAssociationDTO cashRegister;
|
||||
|
|
@ -32,8 +31,6 @@ public final class CashSessionDTO implements DTOInterface, Serializable
|
|||
private ImmutableList<MovementDTO> movements;
|
||||
/** See {@link getTickets()}. */
|
||||
private ImmutableList<FiscalTicketDTO> tickets;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a cash session from all fields.
|
||||
|
|
@ -43,7 +40,6 @@ public final class CashSessionDTO implements DTOInterface, Serializable
|
|||
* @param openDate See {@link getOpenDate()}.
|
||||
* @param movements See {@link getMovements()}.
|
||||
* @param tickets See {@link getTickets()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public CashSessionDTO(
|
||||
WeakAssociationDTO cashRegister,
|
||||
|
|
@ -51,15 +47,13 @@ public final class CashSessionDTO implements DTOInterface, Serializable
|
|||
boolean continuous,
|
||||
Date openDate,
|
||||
ImmutableList<MovementDTO> movements,
|
||||
ImmutableList<FiscalTicketDTO> tickets,
|
||||
ExtraObject extra) {
|
||||
ImmutableList<FiscalTicketDTO> tickets) {
|
||||
this.cashRegister = cashRegister;
|
||||
this.sequence = sequence;
|
||||
this.continuous = continuous;
|
||||
this.openDate = openDate;
|
||||
this.movements = movements;
|
||||
this.tickets = tickets;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -79,7 +73,6 @@ public final class CashSessionDTO implements DTOInterface, Serializable
|
|||
this.movements = mvtFacto.immutableReadObjects("movements");
|
||||
DTOFactory<FiscalTicketDTO> tktFacto = new DTOFactory<FiscalTicketDTO>(reader, FiscalTicketDTO.class);
|
||||
this.tickets = tktFacto.immutableReadObjects("tickets");
|
||||
this.extra = reader.readExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -138,14 +131,6 @@ public final class CashSessionDTO implements DTOInterface, Serializable
|
|||
return this.tickets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIntegrity() throws IntegrityExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public final class FiscalTicketDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1622469748625149642L;
|
||||
|
||||
/** See {@link getType()}. */
|
||||
private String type;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import java.util.Date;
|
|||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Change in currency amounts not introduced by the payment of a ticket.
|
||||
|
|
@ -17,7 +16,7 @@ import org.pasteque.coreutil.extra.ExtraObject;
|
|||
*/
|
||||
public final class MovementDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2409481140667639418L;
|
||||
|
||||
/** See {@link getPaymentMode()}. */
|
||||
private WeakAssociationDTO paymentMode;
|
||||
|
|
@ -27,8 +26,6 @@ public final class MovementDTO implements DTOInterface, Serializable
|
|||
private double currencyAmount;
|
||||
/** See {@link getDate()}. */
|
||||
private Date date;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a movement from all fields.
|
||||
|
|
@ -36,19 +33,16 @@ public final class MovementDTO implements DTOInterface, Serializable
|
|||
* @param currency See {@link getCurrency()}.
|
||||
* @param currencyAmount See {@link getCurrencyAmount()}.
|
||||
* @param date See {@link getDate()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public MovementDTO(
|
||||
WeakAssociationDTO paymentMode,
|
||||
WeakAssociationDTO currency,
|
||||
double currencyAmount,
|
||||
Date date,
|
||||
ExtraObject extra) {
|
||||
Date date) {
|
||||
this.paymentMode = paymentMode;
|
||||
this.currency = currency;
|
||||
this.currencyAmount = currencyAmount;
|
||||
this.date = date;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,7 +60,6 @@ public final class MovementDTO implements DTOInterface, Serializable
|
|||
reader.endObject();
|
||||
this.currencyAmount = reader.readDouble("currencyAmount");
|
||||
this.date = reader.readDate("date");
|
||||
this.extra = reader.readExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -101,14 +94,6 @@ public final class MovementDTO implements DTOInterface, Serializable
|
|||
return this.date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIntegrity() throws IntegrityExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import java.io.Serializable;
|
|||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Payment amount Data Transfer Object. A payment may refer to a single one
|
||||
|
|
@ -15,7 +14,7 @@ import org.pasteque.coreutil.extra.ExtraObject;
|
|||
*/
|
||||
public final class PaymentDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 3195260108460565293L;
|
||||
|
||||
/** See {@link getPaymentMode()}. */
|
||||
private WeakAssociationDTO paymentMode;
|
||||
|
|
@ -25,8 +24,6 @@ public final class PaymentDTO implements DTOInterface, Serializable
|
|||
private double amount;
|
||||
/** See {@link getCurrencyAmount()}. */
|
||||
private double currencyAmount;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a payment from all fields.
|
||||
|
|
@ -34,19 +31,16 @@ public final class PaymentDTO implements DTOInterface, Serializable
|
|||
* @param amount See {@link getAmount()}.
|
||||
* @param currency See {@link getCurrency()}.
|
||||
* @param currencyAmount See {@link getCurrencyAmount()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public PaymentDTO(
|
||||
WeakAssociationDTO paymentMode,
|
||||
double amount,
|
||||
WeakAssociationDTO currency,
|
||||
double currencyAmount,
|
||||
ExtraObject extra) {
|
||||
double currencyAmount) {
|
||||
this.paymentMode = paymentMode;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.currencyAmount = currencyAmount;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,7 +58,6 @@ public final class PaymentDTO implements DTOInterface, Serializable
|
|||
this.currency = new WeakAssociationDTO(reader);
|
||||
reader.endObject();
|
||||
this.currencyAmount = reader.readDouble("currencyAmount");
|
||||
this.extra = reader.readExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,14 +92,6 @@ public final class PaymentDTO implements DTOInterface, Serializable
|
|||
return this.currencyAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIntegrity() throws IntegrityExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import java.io.Serializable;
|
|||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Tax amount Data Transfer Object. A tax amount may refer to a single one
|
||||
|
|
@ -15,7 +14,7 @@ import org.pasteque.coreutil.extra.ExtraObject;
|
|||
*/
|
||||
public final class TaxAmountDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 7429827880917696693L;
|
||||
|
||||
/** See {@link getTax()}. */
|
||||
private WeakAssociationDTO tax;
|
||||
|
|
@ -27,8 +26,6 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
|
|||
private double amount;
|
||||
/** See {@link getIncludedInBase()}. */
|
||||
private boolean includedInBase;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a tax from all fields.
|
||||
|
|
@ -37,21 +34,18 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
|
|||
* @param base See {@link getBase()}.
|
||||
* @param amount See {@link getAmount()}.
|
||||
* @param includedInBase See {@link getIncludedInBase()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public TaxAmountDTO(
|
||||
WeakAssociationDTO tax,
|
||||
double taxRate,
|
||||
double base,
|
||||
double amount,
|
||||
boolean includedInBase,
|
||||
ExtraObject extra) {
|
||||
boolean includedInBase) {
|
||||
this.tax = tax;
|
||||
this.taxRate = taxRate;
|
||||
this.base = base;
|
||||
this.amount = amount;
|
||||
this.includedInBase = includedInBase;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,7 +62,6 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
|
|||
this.base = reader.readDouble("base");
|
||||
this.amount = reader.readDouble("amount");
|
||||
this.includedInBase = reader.readBoolean("includedInBase");
|
||||
this.extra = reader.readExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -113,14 +106,6 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
|
|||
return this.includedInBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIntegrity() throws IntegrityExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -4,39 +4,33 @@ import java.io.Serializable;
|
|||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* Tax Data Transfer Object.
|
||||
*/
|
||||
public final class TaxDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 525507510660586665L;
|
||||
/** See {@link getType()}. */
|
||||
private String type;
|
||||
/** See {@link getAmount()}. */
|
||||
private double amount;
|
||||
/** See {@link getIncludedInBase()}. */
|
||||
private boolean includedInBase;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a tax from all fields.
|
||||
* @param type See {@link getType()}.
|
||||
* @param amount See {@link getAmount()}.
|
||||
* @param includedInBase See {@link getIncludedInBase()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public TaxDTO(
|
||||
String type,
|
||||
double amount,
|
||||
boolean includedInBase,
|
||||
ExtraObject extra) {
|
||||
boolean includedInBase) {
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
this.includedInBase = includedInBase;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -49,7 +43,6 @@ public final class TaxDTO implements DTOInterface, Serializable
|
|||
this.type = reader.readString("type");
|
||||
this.amount = reader.readDouble("amount");
|
||||
this.includedInBase = reader.readBoolean("includedInBase");
|
||||
this.extra = reader.readExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -82,14 +75,6 @@ public final class TaxDTO implements DTOInterface, Serializable
|
|||
return this.includedInBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIntegrity() throws IntegrityExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import org.pasteque.coreutil.ParseException;
|
|||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
||||
import org.pasteque.coreutil.datatransfer.parser.DTOFactory;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Receipt of a finalized and paid order. Tickets are immutable unless changes
|
||||
|
|
@ -18,7 +17,7 @@ import org.pasteque.coreutil.extra.ExtraObject;
|
|||
*/
|
||||
public final class TicketDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 8831777799341373103L;
|
||||
|
||||
/** See {@link getCashRegister()}. */
|
||||
private WeakAssociationDTO cashRegister;
|
||||
|
|
@ -56,8 +55,6 @@ public final class TicketDTO implements DTOInterface, Serializable
|
|||
private double finalPrice;
|
||||
/** See {@link getFinalTaxedPrice()}. */
|
||||
private double finalTaxedPrice;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create an ticket from all fields.
|
||||
|
|
@ -79,7 +76,6 @@ public final class TicketDTO implements DTOInterface, Serializable
|
|||
* @param discountRate See {@link getDiscountRate()}.
|
||||
* @param finalPrice See {@link getFinalPrice()}.
|
||||
* @param finalTaxedPrice See {@link getFinalTaxedPrice()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public TicketDTO(
|
||||
WeakAssociationDTO cashRegister,
|
||||
|
|
@ -99,8 +95,7 @@ public final class TicketDTO implements DTOInterface, Serializable
|
|||
WeakAssociationDTO discountProfile,
|
||||
double discountRate,
|
||||
double finalPrice,
|
||||
double finalTaxedPrice,
|
||||
ExtraObject extra) {
|
||||
double finalTaxedPrice) {
|
||||
this.cashRegister = cashRegister;
|
||||
this.sequence = sequence;
|
||||
this.number = number;
|
||||
|
|
@ -119,7 +114,6 @@ public final class TicketDTO implements DTOInterface, Serializable
|
|||
this.discountRate = discountRate;
|
||||
this.finalPrice = finalPrice;
|
||||
this.finalTaxedPrice = finalTaxedPrice;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -152,7 +146,6 @@ public final class TicketDTO implements DTOInterface, Serializable
|
|||
this.taxes = taxFacto.immutableReadObjects("taxes");
|
||||
DTOFactory<PaymentDTO> pmtFacto = new DTOFactory<PaymentDTO>(reader, PaymentDTO.class);
|
||||
this.payments = pmtFacto.immutableReadObjects("payments");
|
||||
this.extra = reader.readExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -318,14 +311,6 @@ public final class TicketDTO implements DTOInterface, Serializable
|
|||
return this.finalTaxedPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIntegrity() throws IntegrityExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -341,7 +326,7 @@ public final class TicketDTO implements DTOInterface, Serializable
|
|||
*/
|
||||
public class TicketLineDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -9065013247136552814L;
|
||||
|
||||
/** See {@link getDispOrder()}. */
|
||||
private final int dispOrder;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
|
|||
*/
|
||||
public class WeakAssociationDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -4033459839844194734L;
|
||||
|
||||
/** See {@link getReference()}. */
|
||||
private final String reference;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import org.pasteque.coreutil.ParseException;
|
|||
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
|
||||
import org.pasteque.coreutil.datatransfer.parser.DTOFactory;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Receipt of a finalized cash session. Once a cash session is closed,
|
||||
|
|
@ -23,7 +22,7 @@ import org.pasteque.coreutil.extra.ExtraObject;
|
|||
*/
|
||||
public final class ZTicketDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -2784800199238764159L;
|
||||
|
||||
/** See {@link getCashRegister()}. */
|
||||
private WeakAssociationDTO cashRegister;
|
||||
|
|
@ -65,8 +64,6 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
private ImmutableList<PaymentDTO> payments;
|
||||
/** See {@link getCustBalances()}. */
|
||||
private ImmutableList<ZTicketCustBalanceDTO> custBalances;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create an ticket from all fields.
|
||||
|
|
@ -90,7 +87,6 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
* @param catTaxes See {@link getCatTaxes()}.
|
||||
* @param payments See {@link getPayments()}.
|
||||
* @param custBalances See {@link getCustBalances()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public ZTicketDTO(
|
||||
WeakAssociationDTO cashRegister,
|
||||
|
|
@ -112,8 +108,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
ZTicketCatSalesDTO[] catSales,
|
||||
ZTicketCatTaxesDTO[] catTaxes,
|
||||
PaymentDTO[] payments,
|
||||
ZTicketCustBalanceDTO[] custBalances,
|
||||
ExtraObject extra) {
|
||||
ZTicketCustBalanceDTO[] custBalances) {
|
||||
this.cashRegister = cashRegister;
|
||||
this.sequence = sequence;
|
||||
this.continuous = continuous;
|
||||
|
|
@ -134,7 +129,6 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
this.catTaxes = new ImmutableList<ZTicketCatTaxesDTO>(catTaxes);
|
||||
this.payments = new ImmutableList<PaymentDTO>(payments);
|
||||
this.custBalances = new ImmutableList<ZTicketCustBalanceDTO>(custBalances);
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -174,7 +168,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
this.payments = pmtFacto.immutableReadObjects("payments");
|
||||
DTOFactory<ZTicketCustBalanceDTO> custBFacto = new DTOFactory<ZTicketCustBalanceDTO>(reader, ZTicketCustBalanceDTO.class);
|
||||
this.custBalances = custBFacto.immutableReadObjects("custBalances");
|
||||
this.extra = reader.readExtra();
|
||||
reader.startArray("custBalances");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -360,14 +354,6 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
return this.custBalances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIntegrity() throws IntegrityExceptions {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -379,7 +365,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
*/
|
||||
public class ZTicketCatSalesDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -6392552469204214096L;
|
||||
|
||||
/** See {@link getCategory()}. */
|
||||
private final WeakAssociationDTO category;
|
||||
|
|
@ -441,7 +427,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
*/
|
||||
public class ZTicketCatTaxesDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -8934368775977813408L;
|
||||
|
||||
/** See {@link getCategory()}. */
|
||||
private final WeakAssociationDTO category;
|
||||
|
|
@ -531,7 +517,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
|
|||
*/
|
||||
public class ZTicketCustBalanceDTO implements DTOInterface, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 7698608167553284402L;
|
||||
|
||||
/** See {@link getCustomer()}. */
|
||||
private final WeakAssociationDTO customer;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,5 @@
|
|||
* <p>All the DTO are final to ensure the immutability. Extensions should use
|
||||
* encapsulation to add more data or ease-of-use, to ensure the major package
|
||||
* using them cannot be alterated.</p>
|
||||
* <p>This objects contains only amounts and minimal content description, all
|
||||
* other data are stored in extra objects allow extensions.</p>
|
||||
*/
|
||||
package org.pasteque.coreutil.datatransfer.dto;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package org.pasteque.coreutil.datatransfer.integrity;
|
|||
*/
|
||||
public abstract class IntegrityException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 6208213847306142896L;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public IntegrityException() {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||
*/
|
||||
public class IntegrityExceptions extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -2603644891253059810L;
|
||||
|
||||
/** {@see getCauses()} */
|
||||
private IntegrityException[] causes;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package org.pasteque.coreutil.datatransfer.integrity;
|
|||
*/
|
||||
public class InvalidFieldException extends IntegrityException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2512125224337518801L;
|
||||
|
||||
/** {@see getConstraint()} */
|
||||
private final IntegrityFieldConstraint constraint;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package org.pasteque.coreutil.datatransfer.integrity;
|
|||
*/
|
||||
public class InvalidRecordException extends IntegrityException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -6234201939816973179L;
|
||||
|
||||
/** {@see getConstraint()} */
|
||||
private final IntegrityRecordConstraint constraint;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import org.pasteque.coreutil.datatransfer.format.BinaryDTOFormat;
|
|||
/**
|
||||
* Read values from a JSON representation of data.
|
||||
*/
|
||||
public class JSONReader extends ReaderHelper
|
||||
public class JSONReader implements Reader
|
||||
{
|
||||
/** Constant for the state of not having parsed anything yet. */
|
||||
private static final String ROOT_NAME = "__ROOT__";
|
||||
|
|
@ -98,13 +98,13 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public boolean hasKey(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
return this.currentObject.has(key);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public List<String> listKeys() throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
Set<String> keySet = this.currentObject.keySet();
|
||||
|
|
@ -116,25 +116,25 @@ public class JSONReader extends ReaderHelper
|
|||
return keys;
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public int getArraySize() throws ParseException {
|
||||
this.checkCurrentArray();
|
||||
return this.currentArray.length();
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public boolean isNull(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
return this.currentObject.isNull(key);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public boolean isNull(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
return this.currentArray.isNull(index);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public boolean readBoolean(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -144,7 +144,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Boolean readBooleanOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : Boolean.valueOf(this.readBoolean(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readBoolean(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
try {
|
||||
|
|
@ -154,7 +159,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Boolean readBooleanOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : Boolean.valueOf(this.readBoolean(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -164,7 +174,17 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public String readStringOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : this.readString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readStringOrEmpty(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? "" : this.readString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
try {
|
||||
|
|
@ -174,7 +194,17 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public String readStringOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : this.readString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readStringOrEmpty(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? "" : this.readString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -184,7 +214,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Integer readIntOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : Integer.valueOf(this.readInt(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
try {
|
||||
|
|
@ -194,7 +229,13 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Integer readIntOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : Integer.valueOf(this.readInt(index));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double readDouble(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -204,7 +245,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Double readDoubleOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : Double.valueOf(this.readDouble(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble(int index) throws ParseException {
|
||||
this.checkCurrentArray();
|
||||
try {
|
||||
|
|
@ -214,7 +260,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Double readDoubleOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : Double.valueOf(this.readDouble(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date readDate(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -230,7 +281,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Date readDateOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : this.readDate(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date readDate(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
try {
|
||||
|
|
@ -246,7 +302,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public Date readDateOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : this.readDate(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readBinary(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -257,7 +318,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public byte[] readBinaryOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : this.readBinary(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readBinary(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
try {
|
||||
|
|
@ -268,7 +334,12 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public byte[] readBinaryOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : this.readBinary(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startObject() throws ParseException {
|
||||
if (this.currentObject == null && this.currentArray == null
|
||||
&& this.mainObject == null && this.mainArray == null) {
|
||||
|
|
@ -279,7 +350,7 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public void startObject(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -290,7 +361,7 @@ public class JSONReader extends ReaderHelper
|
|||
this.path.add(new Path(PathType.OBJECT, key));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public void startObject(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
try {
|
||||
|
|
@ -302,14 +373,14 @@ public class JSONReader extends ReaderHelper
|
|||
this.path.add(new Path(PathType.OBJECT, index));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public void endObject() throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
this.path.remove(this.path.size() - 1);
|
||||
this.runPath();
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public void startArray() throws ParseException {
|
||||
if (this.currentObject == null && this.currentArray == null
|
||||
&& this.mainObject == null && this.mainArray == null) {
|
||||
|
|
@ -320,7 +391,7 @@ public class JSONReader extends ReaderHelper
|
|||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public void startArray(String key) throws ParseException {
|
||||
this.checkCurrentObject();
|
||||
try {
|
||||
|
|
@ -332,7 +403,7 @@ public class JSONReader extends ReaderHelper
|
|||
this.path.add(new Path(PathType.ARRAY, key));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public void startArray(int index) throws ParseException {
|
||||
this.checkCurrentArrayIndex(index);
|
||||
try {
|
||||
|
|
@ -343,7 +414,7 @@ public class JSONReader extends ReaderHelper
|
|||
this.path.add(new Path(PathType.ARRAY, index));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
@Override
|
||||
public void endArray() throws ParseException {
|
||||
this.checkCurrentArray();
|
||||
this.path.remove(this.path.size() - 1);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package org.pasteque.coreutil.datatransfer.parser;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Data reader.</p>
|
||||
|
|
@ -269,15 +268,6 @@ public interface Reader
|
|||
*/
|
||||
public byte[] readBinaryOrNull(String key) throws ParseException;
|
||||
|
||||
/**
|
||||
* Read the extra object.
|
||||
* @return The root extra object. If not present, it must return an empty
|
||||
* extra object.
|
||||
* @throws ParseException When an error occurs while reading the extra
|
||||
* object.
|
||||
*/
|
||||
public ExtraObject readExtra() throws ParseException;
|
||||
|
||||
/**
|
||||
* Read binary data as base64 at the given index of the current element.
|
||||
* @param index The index to read in the current element.
|
||||
|
|
|
|||
|
|
@ -1,169 +0,0 @@
|
|||
package org.pasteque.coreutil.datatransfer.parser;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Common behaviour implementation of a data reader.</p>
|
||||
*/
|
||||
public abstract class ReaderHelper implements Reader
|
||||
{
|
||||
@Override // from Reader
|
||||
public abstract boolean hasKey(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract List<String> listKeys() throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract int getArraySize() throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract boolean isNull(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract boolean isNull(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract boolean readBoolean(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Boolean readBooleanOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : Boolean.valueOf(this.readBoolean(key));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract boolean readBoolean(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Boolean readBooleanOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : Boolean.valueOf(this.readBoolean(index));
|
||||
}
|
||||
@Override // from Reader
|
||||
public abstract String readString(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public String readStringOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : this.readString(key);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public String readStringOrEmpty(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? "" : this.readString(key);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract String readString(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public String readStringOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : this.readString(index);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public String readStringOrEmpty(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? "" : this.readString(index);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract int readInt(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Integer readIntOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : Integer.valueOf(this.readInt(key));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract int readInt(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Integer readIntOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : Integer.valueOf(this.readInt(index));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract double readDouble(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Double readDoubleOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : Double.valueOf(this.readDouble(key));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract double readDouble(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Double readDoubleOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : Double.valueOf(this.readDouble(index));
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract Date readDate(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Date readDateOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : this.readDate(key);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract Date readDate(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public Date readDateOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : this.readDate(index);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract byte[] readBinary(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public byte[] readBinaryOrNull(String key) throws ParseException {
|
||||
return (this.isNull(key)) ? null : this.readBinary(key);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract byte[] readBinary(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public byte[] readBinaryOrNull(int index) throws ParseException {
|
||||
return (this.isNull(index)) ? null : this.readBinary(index);
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public ExtraObject readExtra() throws ParseException {
|
||||
if (!this.hasKey(ExtraObject.EXTRA_ROOT_FIELD)
|
||||
|| this.isNull(ExtraObject.EXTRA_ROOT_FIELD)) {
|
||||
return new ExtraObject();
|
||||
} else {
|
||||
this.startObject("extra");
|
||||
ExtraObject o = new ExtraObject(this);
|
||||
this.endObject();
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void startObject() throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void startObject(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void startObject(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void endObject() throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void startArray() throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void startArray(String key) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void startArray(int index) throws ParseException;
|
||||
|
||||
@Override // from Reader
|
||||
public abstract void endArray() throws ParseException;
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
package org.pasteque.coreutil.datatransfer.parser;
|
||||
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
|
||||
/**
|
||||
* <p>Data writer.</p>
|
||||
* <p>A reader must always be initialized from its DTO, typically within
|
||||
|
|
@ -9,123 +7,6 @@ import org.pasteque.coreutil.ParseException;
|
|||
*/
|
||||
public interface Writer
|
||||
{
|
||||
/**
|
||||
* Add an int to the current array.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an array.
|
||||
*/
|
||||
public void writeInt(int value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add an int to the current object.
|
||||
* @param key The key of the value to write.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an object.
|
||||
*/
|
||||
public void writeInt(String key, int value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add an int to the current array.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an array.
|
||||
*/
|
||||
public void writeDouble(double value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add an int to the current object.
|
||||
* @param key The key of the value to write.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an object.
|
||||
*/
|
||||
public void writeDouble(String key, double value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add an int to the current array.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an array.
|
||||
*/
|
||||
public void writeBoolean(boolean value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add an int to the current object.
|
||||
* @param key The key of the value to write.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an object.
|
||||
*/
|
||||
public void writeBoolean(String key, boolean value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add an int to the current array.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an array.
|
||||
* @throws IllegalArgumentException When the value is null.
|
||||
* Use {@link writeNull()} instead.
|
||||
*/
|
||||
public void writeString(String value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add an int to the current object.
|
||||
* @param key The key of the value to write.
|
||||
* @param value The value to write.
|
||||
* @throws ParseException When writing from outside an object.
|
||||
* @throws IllegalArgumentException When the value is null.
|
||||
* Use {@link writeNull()} instead.
|
||||
*/
|
||||
public void writeString(String key, String value) throws ParseException;
|
||||
|
||||
/**
|
||||
* Add a null value to the current array.
|
||||
* @throws ParseException When writing from outside an array.
|
||||
*/
|
||||
public void writeNull() throws ParseException;
|
||||
|
||||
/**
|
||||
* Add a null value to the current object.
|
||||
* @param key The key of the value to write.
|
||||
* @throws ParseException When writing from outside an object.
|
||||
*/
|
||||
public void writeNull(String key) throws ParseException;
|
||||
|
||||
/**
|
||||
* Start (create) a dictionary as the root element or inside an array.
|
||||
* @throws ParseException When the root element is already created or
|
||||
* not currently inside an array.
|
||||
*/
|
||||
public void startObject() throws ParseException;
|
||||
|
||||
/**
|
||||
* Start (create) a dictionary as a child element.
|
||||
* @param key The key to read in the current dictionary.
|
||||
* @throws ParseException When writing a key from outside an object.
|
||||
*/
|
||||
public void startObject(String key) throws ParseException;
|
||||
|
||||
/**
|
||||
* Finalize the current object and return up into the tree.
|
||||
* @throws ParseException When the current element is not an object.
|
||||
*/
|
||||
public void endObject() throws ParseException;
|
||||
|
||||
/**
|
||||
* Start (create) an array as the root element or inside an array.
|
||||
* @throws ParseException When the root element is already created
|
||||
* or not currently inside an array.
|
||||
*/
|
||||
public void startArray() throws ParseException;
|
||||
|
||||
/**
|
||||
* Start (create) an array as a child element.
|
||||
* @param key The key in the parent dictionary.
|
||||
* @throws ParseException When writing a key from outside an object.
|
||||
*/
|
||||
public void startArray(String key) throws ParseException;
|
||||
|
||||
/**
|
||||
* Finalize the current array and return up into the tree.
|
||||
* @throws ParseException When the current element is not an array.
|
||||
*/
|
||||
public void endArray() throws ParseException;
|
||||
|
||||
/**
|
||||
* Get the encoded data.
|
||||
* @return The encoded data.
|
||||
|
|
|
|||
|
|
@ -1,193 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.pasteque.coreutil.ImmutableList;
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Extra data as an array.
|
||||
*/
|
||||
public final class ExtraArray implements ExtraData
|
||||
{
|
||||
/** See {@link getField(). */
|
||||
private final String field;
|
||||
/** See {@link getValue()}. */
|
||||
private final ImmutableList<ExtraData> value;
|
||||
/** See {@link getType()}. */
|
||||
private final ExtraType type;
|
||||
|
||||
/**
|
||||
* Construct an array from a list of values.
|
||||
* @param field The name of the field.
|
||||
* @param type The type of data in the array.
|
||||
* @param value The values in the array. Each data can have the index
|
||||
* as field name.
|
||||
* @throws IllegalArgumentException When the type of one value doesn't match
|
||||
* the type of the array.
|
||||
* @throws Error When one of the {@link ExtraType} is not handled.
|
||||
*/
|
||||
/* package */ ExtraArray(String field, ExtraType type, List<ExtraData> value)
|
||||
throws IllegalArgumentException {
|
||||
this.field = field;
|
||||
this.type = type;
|
||||
for (ExtraData extra : value) {
|
||||
if (!this.type.checkExtraType(extra)) {
|
||||
throw new IllegalArgumentException(String.format("Invalid type of data %s, expected %s", extra.getClass().toString(), type.getTypeExtraClass().toString()));
|
||||
}
|
||||
}
|
||||
this.value = new ImmutableList<ExtraData>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an array from a list of values.
|
||||
* @param field The name of the field.
|
||||
* @param type The type of data in the array.
|
||||
* @param value The values in the array. Each data can have the index
|
||||
* as field name.
|
||||
* @throws IllegalArgumentException When the type of one value doesn't match
|
||||
* the type of the array.
|
||||
* @throws Error When one of the {@link ExtraType} is not handled.
|
||||
*/
|
||||
/* package */ ExtraArray(String field, ExtraType type, ImmutableList<ExtraData> value)
|
||||
throws IllegalArgumentException {
|
||||
this.field = field;
|
||||
this.type = type;
|
||||
for (ExtraData extra : value) {
|
||||
if (!this.type.checkExtraType(extra)) {
|
||||
throw new IllegalArgumentException(String.format("Invalid type of data %s, expected %s", extra.getClass().toString(), type.getTypeExtraClass().toString()));
|
||||
}
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an array from a reader.
|
||||
* @param field The name of the field.
|
||||
* @param reader The reader to read data from. It must aready be pointing
|
||||
* to the array.
|
||||
* @throws ParseException When an error happens while reading the data.
|
||||
*/
|
||||
/* package */ ExtraArray(String field, Reader reader) throws ParseException {
|
||||
ExtraType arrayType = ExtraType.fromCode(reader.readString("ta"));
|
||||
reader.startArray("v");
|
||||
List<ExtraData> data = new ArrayList<ExtraData>(reader.getArraySize());
|
||||
for (int i = 0; i < reader.getArraySize(); i++) {
|
||||
switch (arrayType) {
|
||||
case STRING:
|
||||
data.add(new ExtraString(String.valueOf(i), reader.readString(i)));
|
||||
break;
|
||||
case BOOLEAN:
|
||||
data.add(new ExtraBoolean(String.valueOf(i), reader.readBoolean(i)));
|
||||
break;
|
||||
case INTEGER:
|
||||
data.add(new ExtraInt(String.valueOf(i), reader.readInt(i)));
|
||||
break;
|
||||
case DOUBLE:
|
||||
data.add(new ExtraDouble(String.valueOf(i), reader.readDouble(i)));
|
||||
break;
|
||||
case OBJECT:
|
||||
reader.startObject(i);
|
||||
try {
|
||||
data.add(new ExtraObject(String.valueOf(i), reader));
|
||||
} catch (ParseException e) {
|
||||
reader.endObject();
|
||||
reader.endArray();
|
||||
throw e;
|
||||
}
|
||||
reader.endObject();
|
||||
break;
|
||||
case ARRAY:
|
||||
reader.startObject(i);
|
||||
try {
|
||||
data.add(new ExtraArray(String.valueOf(i), reader));
|
||||
} catch (ParseException e) {
|
||||
reader.endObject();
|
||||
reader.endArray();
|
||||
throw e;
|
||||
}
|
||||
reader.endObject();
|
||||
break;
|
||||
case NULL:
|
||||
data.add(new ExtraNull(String.valueOf(i)));
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
}
|
||||
}
|
||||
reader.endArray();
|
||||
this.field = field;
|
||||
this.type = arrayType;
|
||||
this.value = new ImmutableList<ExtraData>(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field associated to this extra data.
|
||||
* @return the field name.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of value hold.
|
||||
* @return The type of values.
|
||||
*/
|
||||
public ExtraType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public ImmutableList<ExtraData> getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the content of this ExtraArray in the current writer object.
|
||||
* The Writer must already be inside the object to write.
|
||||
* @param to The writer to write to.
|
||||
* @throws ParseException When an error occurs while writing.
|
||||
*/
|
||||
private void innerWrite(Writer to) throws ParseException {
|
||||
to.writeString("t", ExtraType.ARRAY.getTypeCode());
|
||||
to.writeString("ta", this.type.getTypeCode());
|
||||
to.startArray("v");
|
||||
for (ExtraData v : this.value) {
|
||||
try {
|
||||
if (v == null || this.type == ExtraType.NULL) {
|
||||
to.writeNull();
|
||||
} else if (this.type == ExtraType.STRING) {
|
||||
to.writeString((String) v.getValue());
|
||||
} else if (this.type == ExtraType.BOOLEAN) {
|
||||
to.writeBoolean((Boolean) v.getValue());
|
||||
} else if (this.type == ExtraType.INTEGER) {
|
||||
to.writeInt((Integer) v.getValue());
|
||||
} else if (this.type == ExtraType.DOUBLE) {
|
||||
to.writeDouble((Double) v.getValue());
|
||||
} else if (this.type == ExtraType.OBJECT) {
|
||||
((ExtraObject) v).writeInArray(to);
|
||||
} else if (this.type == ExtraType.ARRAY) {
|
||||
to.startObject();
|
||||
((ExtraArray) v).innerWrite(to);
|
||||
to.endObject();
|
||||
} else {
|
||||
assert false;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
to.endArray();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
to.endArray();
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public void write(Writer to) throws ParseException {
|
||||
to.startObject(this.field);
|
||||
this.innerWrite(to);
|
||||
to.endObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Extra data as a boolean.
|
||||
*/
|
||||
public final class ExtraBoolean implements ExtraData
|
||||
{
|
||||
/** See {@link getField(). */
|
||||
private final String field;
|
||||
/** See {@link getBoolean()}. */
|
||||
private final boolean value;
|
||||
|
||||
/**
|
||||
* Create an extra data.
|
||||
* @param field The field name.
|
||||
* @param value the value.
|
||||
*/
|
||||
/* package */ ExtraBoolean(String field, boolean value) {
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field associated to this extra data.
|
||||
* @return the field name.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value.
|
||||
* @return The value.
|
||||
*/
|
||||
public boolean getBoolean() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public Object getValue() {
|
||||
return Boolean.valueOf(this.value);
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public void write(Writer to) throws ParseException {
|
||||
to.startObject(this.field);
|
||||
to.writeString("t", ExtraType.BOOLEAN.getTypeCode());
|
||||
to.writeBoolean("v", this.value);
|
||||
to.endObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,372 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>Generator to create and embed {@link org.pasteque.coreutil.extra.ExtraData}
|
||||
* in a dedicated object.</p>
|
||||
* <p>Create a builder and add fields for all extra data and close the builder
|
||||
* to get the root {@link org.pasteque.coreutil.extra.ExtraObject}
|
||||
* to pass to major objects.</p>
|
||||
*/
|
||||
public final class ExtraBuilder
|
||||
{
|
||||
/** The current object being built. Null when building an array. */
|
||||
private TempExtraObject currentObject;
|
||||
/** The current array being built. Null when building an object. */
|
||||
private TempExtraArray currentArray;
|
||||
/** The current branch of the tree of objects and array being built. */
|
||||
private List<ExtraData> path;
|
||||
|
||||
/**
|
||||
* Create an empty builder to create an {@link ExtraObject}.
|
||||
* It will be already pointing to the root object and values can be added
|
||||
* to it.
|
||||
*/
|
||||
public ExtraBuilder() {
|
||||
this.path = new ArrayList<ExtraData>();
|
||||
this.currentObject = new TempExtraObject(ExtraObject.EXTRA_ROOT_FIELD);
|
||||
this.path.add(this.currentObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the builder is currently building an object.
|
||||
* @throws IllegalStateException When not currently building an object.
|
||||
*/
|
||||
private void checkCurrentObject() throws IllegalStateException {
|
||||
if (this.currentObject == null) {
|
||||
throw new IllegalStateException("ExtraBuilder is not currently building an object.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the builder is currently building an array.
|
||||
* @throws IllegalStateException When not currently building an array.
|
||||
*/
|
||||
private void checkCurrentArray() throws IllegalStateException {
|
||||
if (this.currentArray == null) {
|
||||
throw new IllegalStateException("ExtraBuilder is not currently building an array.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End building the current object or array and move up to the path
|
||||
* to get back to editing the parent object or array.
|
||||
* @throws IllegalStateException When already at the root object.
|
||||
* @throws Error When the path contains anything but ExtraObject or ExtraArray.
|
||||
*/
|
||||
private void pathUp() throws IllegalStateException {
|
||||
if (path.size() <= 1) {
|
||||
throw new IllegalStateException("ExtraBuilder is already building the root object. Use close() instead.");
|
||||
}
|
||||
this.path.remove(this.path.size() - 1);
|
||||
ExtraData last = this.path.get(this.path.size() - 1);
|
||||
if (last instanceof TempExtraObject) {
|
||||
this.currentObject = (TempExtraObject) last;
|
||||
this.currentArray = null;
|
||||
} else if (last instanceof TempExtraArray) {
|
||||
this.currentObject = null;
|
||||
this.currentArray = (TempExtraArray) last;
|
||||
} else {
|
||||
throw new Error(String.format("Corrupted ExtraBuilder path. Expecting TempExtraObject or TempExtraArray, found %s", last.getClass().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start building a new object as a child of the current array.
|
||||
* @throws IllegalStateException When not currently building an array.
|
||||
*/
|
||||
public void startObject() throws IllegalStateException {
|
||||
this.checkCurrentArray();
|
||||
TempExtraObject newObject = new TempExtraObject(String.valueOf(this.currentArray.size()));
|
||||
this.currentArray.addValue(newObject);
|
||||
this.path.add(newObject);
|
||||
this.currentObject = newObject;
|
||||
this.currentArray = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start building a new object as a value of the current object.
|
||||
* @param field The name of the field of the current object that will hold
|
||||
* the new object.
|
||||
* @throws IllegalStateException When not currently building an object.
|
||||
*/
|
||||
public void startObject(String field) throws IllegalStateException {
|
||||
this.checkCurrentObject();
|
||||
TempExtraObject newObject = new TempExtraObject(field);
|
||||
this.currentObject.setValue(newObject);
|
||||
this.path.add(newObject);
|
||||
this.currentObject = newObject;
|
||||
this.currentArray = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* End building the current object and get back to editing its parent.
|
||||
* @throws IllegalStateException When not currently building an object or
|
||||
* when trying to end the root object.
|
||||
*/
|
||||
public void endObject() throws IllegalStateException {
|
||||
this.checkCurrentObject();
|
||||
this.pathUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start building a new array as a child of the current array.
|
||||
* @param type The type of data the array will contain.
|
||||
* @throws IllegalStateException When not currently building an array.
|
||||
*/
|
||||
public void startArray(ExtraType type) throws IllegalStateException {
|
||||
this.checkCurrentArray();
|
||||
TempExtraArray array = new TempExtraArray(this.currentArray.size(), type);
|
||||
this.currentArray.addValue(array);
|
||||
this.path.add(array);
|
||||
this.currentArray = array;
|
||||
this.currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start building a new array as a value of the current object.
|
||||
* @param field The name of the field of the current object that will hold
|
||||
* the new array.
|
||||
* @param type The type of data the array will contain.
|
||||
* @throws IllegalStateException When not currently building an object.
|
||||
*/
|
||||
public void startArray(String field, ExtraType type) throws IllegalStateException {
|
||||
this.checkCurrentObject();
|
||||
TempExtraArray array = new TempExtraArray(field, type);
|
||||
this.currentObject.setValue(array);
|
||||
this.path.add(array);
|
||||
this.currentArray = array;
|
||||
this.currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* End building the current array and get back to editing its parent.
|
||||
* @throws IllegalStateException When not currently building an array.
|
||||
*/
|
||||
public void endArray() throws IllegalStateException {
|
||||
this.checkCurrentArray();
|
||||
this.pathUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a null value to the current array.
|
||||
* @throws IllegalStateException When not currently building an array.
|
||||
*/
|
||||
public void addNull() throws IllegalStateException {
|
||||
this.checkCurrentArray();
|
||||
this.currentArray.addValue(new ExtraNull(this.currentArray.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a null value to the current object.
|
||||
* @param field The name of the field that holds the value.
|
||||
* @throws IllegalStateException When not currently building an object.
|
||||
*/
|
||||
public void addNull(String field) throws IllegalStateException {
|
||||
this.checkCurrentObject();
|
||||
ExtraNull value = new ExtraNull(field);
|
||||
this.currentObject.setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a value to the current array.
|
||||
* @param value The value to add. It adds a null value instead when null.
|
||||
* @throws IllegalStateException When not currently building an array.
|
||||
* @throws IllegalArgumentException When not building an array of String.
|
||||
*/
|
||||
public void add(String value) throws IllegalStateException {
|
||||
this.checkCurrentArray();
|
||||
if (value == null) {
|
||||
this.addNull();
|
||||
} else {
|
||||
this.currentArray.addValue(new ExtraString(this.currentArray.size(), value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a value to the current object.
|
||||
* @param field The name of the field that holds the value.
|
||||
* @param value The value to add. It adds a null value instead when null.
|
||||
* @throws IllegalStateException When not currently building an object.
|
||||
*/
|
||||
public void add(String field, String value) throws IllegalStateException {
|
||||
this.checkCurrentObject();
|
||||
if (value == null) {
|
||||
this.addNull(field);
|
||||
} else {
|
||||
this.currentObject.setValue(new ExtraString(field, value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a value to the current array.
|
||||
* @param value The value to add.
|
||||
* @throws IllegalStateException When not currently building an array.
|
||||
* @throws IllegalArgumentException When not building an array of Integers.
|
||||
*/
|
||||
public void add(int value) throws IllegalStateException {
|
||||
this.checkCurrentArray();
|
||||
this.currentArray.addValue(new ExtraInt(this.currentArray.size(), value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a value to the current object.
|
||||
* @param field The name of the field that holds the value.
|
||||
* @param value The value to add.
|
||||
* @throws IllegalStateException When not currently building an object.
|
||||
*/
|
||||
public void add(String field, int value) throws IllegalStateException {
|
||||
this.checkCurrentObject();
|
||||
this.currentObject.setValue(new ExtraInt(field, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop building extra data and get the final object.
|
||||
* Once close is called, no other operation can be done.
|
||||
* @return The finalized extra data to pass to a major object.
|
||||
*/
|
||||
public ExtraObject close() {
|
||||
TempExtraObject root = (TempExtraObject) this.path.get(0);
|
||||
this.path.clear();
|
||||
this.currentObject = null;
|
||||
this.currentArray = null;
|
||||
return (ExtraObject) root.finalizeExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to convert local temporary extra object and array
|
||||
* to the definitive extra data.
|
||||
*/
|
||||
private interface TempExtra {
|
||||
/**
|
||||
* Convert the temporary extra to the definitive one.
|
||||
* @return An immutable extra data.
|
||||
*/
|
||||
public ExtraData finalizeExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
* A buildable extra object.
|
||||
*/
|
||||
private class TempExtraObject implements ExtraData, TempExtra
|
||||
{
|
||||
private List<ExtraData> data;
|
||||
private String field;
|
||||
|
||||
public TempExtraObject(String field) {
|
||||
this.data = new ArrayList<ExtraData>();
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or replace a value to the current object.
|
||||
* If the field is already set, it is replaced.
|
||||
* @param value The value to add.
|
||||
*/
|
||||
private void setValue(ExtraData value) {
|
||||
for (int i = 0; i < this.data.size(); i++) {
|
||||
ExtraData v = this.data.get(i);
|
||||
if (value.getField().equals(v.getField())) {
|
||||
this.data.set(i, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.data.add(value);
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public ExtraData getValue() {
|
||||
return this.finalizeExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
* @param w Not used.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public void write(org.pasteque.coreutil.datatransfer.parser.Writer w) {}
|
||||
|
||||
@Override // from TempExtra
|
||||
public ExtraData finalizeExtra() {
|
||||
for (int i = 0; i < this.data.size(); i++) {
|
||||
ExtraData v = this.data.get(i);
|
||||
if ((v instanceof TempExtra)) {
|
||||
this.data.set(i, ((TempExtra) v).finalizeExtra());
|
||||
}
|
||||
}
|
||||
return new ExtraObject(this.field, this.data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A buildable extra array.
|
||||
*/
|
||||
private class TempExtraArray implements ExtraData, TempExtra
|
||||
{
|
||||
private List<ExtraData> data;
|
||||
private String field;
|
||||
private ExtraType type;
|
||||
|
||||
public TempExtraArray(String field, ExtraType type) {
|
||||
this.data = new ArrayList<ExtraData>();
|
||||
this.field = field;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the array as a string for the name of the next
|
||||
* element to add.
|
||||
* @return The size of the array as a string.
|
||||
*/
|
||||
public String size() {
|
||||
return String.valueOf(data.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a value to the array.
|
||||
* @param value The value to add.
|
||||
* @throws IllegalArgumentException When the type of one value doesn't match
|
||||
* the type of the array.
|
||||
*/
|
||||
private void addValue(ExtraData value) throws IllegalArgumentException {
|
||||
if (!this.type.checkExtraType(value)) {
|
||||
throw new IllegalArgumentException(String.format("Invalid type of data %s, expected %s", value.getClass().toString(), this.type.getTypeExtraClass().toString()));
|
||||
}
|
||||
this.data.add(value);
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public ExtraData getValue() {
|
||||
return this.finalizeExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
* @param w Not used.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public void write(org.pasteque.coreutil.datatransfer.parser.Writer w) {}
|
||||
|
||||
@Override // from TempExtra
|
||||
public ExtraData finalizeExtra() {
|
||||
for (int i = 0; i < this.data.size(); i++) {
|
||||
ExtraData v = this.data.get(i);
|
||||
if ((v instanceof TempExtra)) {
|
||||
this.data.set(i, ((TempExtra) v).finalizeExtra());
|
||||
}
|
||||
}
|
||||
return new ExtraArray(this.field, this.type, this.data);
|
||||
}
|
||||
}}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Data outside the minimal ones to be passed to the major version.
|
||||
*/
|
||||
public interface ExtraData
|
||||
{
|
||||
/**
|
||||
* Get the name of the field this data belongs to.
|
||||
* @return The name of the field.
|
||||
*/
|
||||
public String getField();
|
||||
|
||||
/**
|
||||
* Get the value of the data as an object.
|
||||
* @return The value.
|
||||
*/
|
||||
public Object getValue();
|
||||
|
||||
/**
|
||||
* Write the data to a writer.
|
||||
* @param to The writer to put the data in. The data is not responsible
|
||||
* of the state of the writer. The object holding the extra data must
|
||||
* ensure the writer is in a correct state.
|
||||
* @throws ParseException When the writer is in an incorrect state.
|
||||
*/
|
||||
public void write(Writer to) throws ParseException;
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Extra data as a double.
|
||||
*/
|
||||
public final class ExtraDouble implements ExtraData
|
||||
{
|
||||
/** See {@link getField(). */
|
||||
private final String field;
|
||||
/** See {@link getDouble()}. */
|
||||
private final double value;
|
||||
|
||||
/**
|
||||
* Create an extra data.
|
||||
* @param field The field name.
|
||||
* @param value the value.
|
||||
*/
|
||||
/* package */ ExtraDouble(String field, double value) {
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field associated to this extra data.
|
||||
* @return the field name.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value.
|
||||
* @return The value.
|
||||
*/
|
||||
public double getDouble() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public Object getValue() {
|
||||
return Double.valueOf(this.value);
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public void write(Writer to) throws ParseException {
|
||||
to.startObject(this.field);
|
||||
to.writeString("t", ExtraType.DOUBLE.getTypeCode());
|
||||
to.writeDouble("v", this.value);
|
||||
to.endObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Extra data as an int.
|
||||
*/
|
||||
public final class ExtraInt implements ExtraData
|
||||
{
|
||||
/** See {@link getField(). */
|
||||
private final String field;
|
||||
/** See {@link getInt()}. */
|
||||
private final int value;
|
||||
|
||||
/**
|
||||
* Create an extra data.
|
||||
* @param field The field name.
|
||||
* @param value the value.
|
||||
*/
|
||||
/* package */ ExtraInt(String field, int value) {
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field associated to this extra data.
|
||||
* @return the field name.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value.
|
||||
* @return The value.
|
||||
*/
|
||||
public int getInt() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public Object getValue() {
|
||||
return Integer.valueOf(this.value);
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public void write(Writer to) throws ParseException {
|
||||
to.startObject(this.field);
|
||||
to.writeString("t", ExtraType.INTEGER.getTypeCode());
|
||||
to.writeInt("v", this.value);
|
||||
to.endObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Extra data holding a null value. Use this class instead of
|
||||
* typed extra data with a null value.
|
||||
*/
|
||||
public final class ExtraNull implements ExtraData
|
||||
{
|
||||
/** See {@link getField(). */
|
||||
private final String field;
|
||||
|
||||
/**
|
||||
* Create an extra data.
|
||||
* @param field The field name.
|
||||
*/
|
||||
/* package */ ExtraNull(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field associated to this extra data.
|
||||
* @return the field name.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public Object getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public void write(Writer to) throws ParseException {
|
||||
to.startObject(this.field);
|
||||
to.writeString("t", ExtraType.NULL.getTypeCode());
|
||||
to.writeNull("v");
|
||||
to.endObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,200 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.pasteque.coreutil.ImmutableList;
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Reader;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Collection of {@link org.pasteque.coreutil.extra.ExtraData}
|
||||
* to extend major classes. An extra object is the root of the extra data
|
||||
* and can contain other extra objects as well.
|
||||
*/
|
||||
public final class ExtraObject implements ExtraData
|
||||
{
|
||||
/**
|
||||
* The name of the field for the root element of extra data.
|
||||
*/
|
||||
public static final String EXTRA_ROOT_FIELD = "extra";
|
||||
/** See {@link getField(). */
|
||||
private final String field;
|
||||
/** See {@link getObject(). */
|
||||
private final ImmutableList<ExtraData> value;
|
||||
|
||||
/**
|
||||
* Sort extra data by key and return an ordered list of them.
|
||||
* @param data The maybe unsorted list of extra data.
|
||||
* @return An immutable list of extra data containing all extra data
|
||||
* sorted alphabetically by their key.
|
||||
* @throws IllegalArgumentException When multiple extra data shares the
|
||||
* same key.
|
||||
*/
|
||||
private static ImmutableList<ExtraData> sortExtraKeys(Iterable<ExtraData> data)
|
||||
throws IllegalArgumentException {
|
||||
List<String> keys = new ArrayList<String>();
|
||||
List<ExtraData> sorted = new ArrayList<ExtraData>();
|
||||
for (ExtraData d : data) {
|
||||
keys.add(d.getField());
|
||||
}
|
||||
Collections.sort(keys);
|
||||
String lastKey = null;
|
||||
for (String key : keys) {
|
||||
if (key.equals(lastKey)) {
|
||||
throw new IllegalArgumentException(String.format("Key %s is set multiple times in extra object.", key));
|
||||
}
|
||||
for (ExtraData d : data) {
|
||||
if (d.getField().equals(key)) {
|
||||
sorted.add(d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastKey = key;
|
||||
}
|
||||
return new ImmutableList<ExtraData>(sorted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty extra data as the root element.
|
||||
*/
|
||||
public ExtraObject() {
|
||||
this(EXTRA_ROOT_FIELD, new ImmutableList<ExtraData>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an extra data as the root element.
|
||||
* @param value the value.
|
||||
* @throws IllegalArgumentException When multiple extra data shares the
|
||||
* same key.
|
||||
*/
|
||||
/* package */ ExtraObject(List<ExtraData> data) {
|
||||
this(EXTRA_ROOT_FIELD, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an extra data.
|
||||
* @param value the value.
|
||||
* @throws IllegalArgumentException When multiple extra data shares the
|
||||
* same key.
|
||||
*/
|
||||
/* package */ ExtraObject(String field, List<ExtraData> data) {
|
||||
this.field = field;
|
||||
this.value = sortExtraKeys(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an extra data.
|
||||
* @param value the value.
|
||||
* @throws IllegalArgumentException When multiple extra data shares the
|
||||
* same key.
|
||||
*/
|
||||
/* package */ ExtraObject(String field, ImmutableList<ExtraData> data) {
|
||||
this.field = field;
|
||||
this.value = sortExtraKeys(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate from raw data from a reader.
|
||||
* @param key The key to assign to this extra object.
|
||||
* @param reader The reader that must be currently pointing to this object.
|
||||
* @throws IllegalArgumentException When multiple extra data shares the
|
||||
* same key.
|
||||
* @throws ParseException When an error occurs while parsing the object.
|
||||
* See {@link org.pasteque.coreutil.datatransfer.parser.Reader} for details.
|
||||
*/
|
||||
/* package */ ExtraObject(String key, Reader reader)
|
||||
throws ParseException, IllegalArgumentException {
|
||||
List<String> keys = reader.listKeys();
|
||||
List<ExtraData> data = new ArrayList<ExtraData>(keys.size());
|
||||
for (String extraKey : keys) {
|
||||
reader.startObject(extraKey);
|
||||
String typeCode = reader.readString("t");
|
||||
ExtraType type = ExtraType.fromCode(typeCode);
|
||||
switch (type) {
|
||||
case STRING:
|
||||
data.add(new ExtraString(extraKey, reader.readString("v")));
|
||||
break;
|
||||
case BOOLEAN:
|
||||
data.add(new ExtraBoolean(extraKey, reader.readBoolean("v")));
|
||||
break;
|
||||
case INTEGER:
|
||||
data.add(new ExtraInt(extraKey, reader.readInt("v")));
|
||||
break;
|
||||
case DOUBLE:
|
||||
data.add(new ExtraDouble(extraKey, reader.readDouble("v")));
|
||||
break;
|
||||
case OBJECT:
|
||||
data.add(new ExtraObject(extraKey, reader));
|
||||
break;
|
||||
case ARRAY:
|
||||
data.add(new ExtraArray(extraKey, reader));
|
||||
case NULL:
|
||||
data.add(new ExtraNull(extraKey));
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
}
|
||||
reader.endObject();
|
||||
}
|
||||
this.field = key;
|
||||
this.value = sortExtraKeys(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate from raw data from a reader.
|
||||
* @param r The reader that must be currently pointing to this object.
|
||||
* @throws ParseException When an error occurs while parsing the object.
|
||||
* See {@link org.pasteque.coreutil.datatransfer.parser.Reader} for details.
|
||||
*/
|
||||
public ExtraObject(Reader r) throws ParseException {
|
||||
this(EXTRA_ROOT_FIELD, r);
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this object in an {@link ExtraArray} without providing a field
|
||||
* @param to The write to write this object to.
|
||||
* @throws ParseException When an error occurs while writing a field.
|
||||
*/
|
||||
/* package */ void writeInArray(Writer to) throws ParseException {
|
||||
to.startObject();
|
||||
for (ExtraData d : this.value) {
|
||||
try {
|
||||
d.write(to);
|
||||
} catch (ParseException e) {
|
||||
to.endObject();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
to.endObject();
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public void write(Writer to) throws ParseException {
|
||||
to.startObject(this.field);
|
||||
to.writeString("t", ExtraType.OBJECT.getTypeCode());
|
||||
to.startObject("v");
|
||||
for (ExtraData d : this.value) {
|
||||
try {
|
||||
d.write(to);
|
||||
} catch (ParseException e) {
|
||||
to.endObject();
|
||||
to.endObject();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
to.endObject();
|
||||
to.endObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import org.pasteque.coreutil.ParseException;
|
||||
import org.pasteque.coreutil.datatransfer.parser.Writer;
|
||||
|
||||
/**
|
||||
* Extra data as a {@link java.lang.String}. This can also holds the reference
|
||||
* of an associated object.
|
||||
*/
|
||||
public final class ExtraString implements ExtraData
|
||||
{
|
||||
/** See {@link getField(). */
|
||||
private final String field;
|
||||
/** See {@link getString()}. */
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* Create an extra data.
|
||||
* @param field The field name.
|
||||
* @param value the value.
|
||||
* @throws InvalidArgumentException When value is null.
|
||||
* @see org.pasteque.coreutil.extra.ExtraNull
|
||||
*/
|
||||
/* package */ ExtraString(String field, String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("ExtraData cannot have a null value. Use ExtraNull instead.");
|
||||
}
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field associated to this extra data.
|
||||
* @return the field name.
|
||||
*/
|
||||
@Override // from ExtraData
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value.
|
||||
* @return The value.
|
||||
*/
|
||||
public String getString() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override // from ExtraData
|
||||
public void write(Writer to) throws ParseException {
|
||||
to.startObject(this.field);
|
||||
to.writeString("t", ExtraType.STRING.getTypeCode());
|
||||
to.writeString("v", this.value);
|
||||
to.endObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
package org.pasteque.coreutil.extra;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Enumeration of available data types}.
|
||||
*/
|
||||
public enum ExtraType
|
||||
{
|
||||
/** Type of {@link java.lang.String}, matching {@link ExtraString} data. */
|
||||
STRING("s", String.class, ExtraString.class),
|
||||
/** Type of boolean data. */
|
||||
BOOLEAN("b", Boolean.class, ExtraBoolean.class),
|
||||
/** Type of integer data. */
|
||||
INTEGER("i", Integer.class, ExtraInt.class),
|
||||
/** Type of float/double data. */
|
||||
DOUBLE("d", Double.class, ExtraDouble.class),
|
||||
/** Type of object data. */
|
||||
OBJECT("o", Map.class, ExtraObject.class),
|
||||
/** Type of array data. */
|
||||
ARRAY("a", List.class, ExtraArray.class),
|
||||
/** Type of null data. */
|
||||
NULL("n", null, ExtraNull.class);
|
||||
|
||||
/** See {@link getTypeCode()}. */
|
||||
private final String typeCode;
|
||||
/** See {@link getTypeClass()}. */
|
||||
private final Class<?> type;
|
||||
/** See {@link getTypeExtraClass()}. */
|
||||
private final Class<? extends ExtraData> extraType;
|
||||
|
||||
/**
|
||||
* Get a type from its type code.
|
||||
* @param code The code value.
|
||||
* @return The according enumeration value.
|
||||
* @throws IllegalArgumentException When code is not found
|
||||
* within the enumerated values
|
||||
*/
|
||||
public static final ExtraType fromCode(String code) throws IllegalArgumentException {
|
||||
for (ExtraType v : ExtraType.values()) {
|
||||
if (v.getTypeCode().equals(code)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of an extra data.
|
||||
* @param data The extra data to check.
|
||||
* @return The type of that extra data.
|
||||
*/
|
||||
public static final ExtraType fromExtra(ExtraData data) {
|
||||
for (ExtraType v : ExtraType.values()) {
|
||||
if (v.checkExtraType(data)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
throw new Error(String.format("Unknown ExtraData type %s", data.getClass().toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal constructor.
|
||||
* @param typeCode The code to identify the type.
|
||||
* @param type The expected java class.
|
||||
* @param extraType The expected {@link ExtraData} implementation class.
|
||||
*/
|
||||
private ExtraType(String typeCode, Class<?> type, Class<? extends ExtraData> extraType) {
|
||||
this.typeCode = typeCode;
|
||||
this.type = type;
|
||||
this.extraType = extraType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the associated constant.
|
||||
* @return The code for DTO.
|
||||
*/
|
||||
public String getTypeCode() {
|
||||
return this.typeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expected java class of this type.
|
||||
* @return A java class, like String.class.
|
||||
*/
|
||||
public Class<?> getTypeClass() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expected {@link ExtraData} implementation class.
|
||||
* @return An {@link ExtraData} implementation, like {@link ExtraString}.
|
||||
*/
|
||||
public Class<? extends ExtraData> getTypeExtraClass() {
|
||||
return this.extraType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an object is the same java type as this type expects.
|
||||
* @param o The object to check.
|
||||
* @return True if the object is acceptable for this type.
|
||||
*/
|
||||
public boolean checkRawType(Object o) {
|
||||
return this.type.isInstance(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an extra object is the same type as this type expects.
|
||||
* @param o The extra object.
|
||||
* @return True if the object is the same extra type or an {@link ExtraNull}.
|
||||
*/
|
||||
public boolean checkExtraType(ExtraData o) {
|
||||
return (this.extraType.isInstance(o)) || (o instanceof ExtraNull);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
/**
|
||||
* <p>Non-mandatory data to pass to the major version. Use an
|
||||
* {@link org.pasteque.coreutil.extra.ExtraBuilder} to
|
||||
* remove the semantic from model classes to pass them to major data
|
||||
* that don't care about their meaning.</p>
|
||||
* <p>An {@link org.pasteque.coreutil.extra.ExtraObject} is composed of
|
||||
* types of {@link org.pasteque.coreutil.extra.ExtraData} for typed
|
||||
* values. All values of {@link org.pasteque.coreutil.extra.ExtraData}
|
||||
* implementations are non-null. When the value is null, use an explicit
|
||||
* {@link org.pasteque.coreutil.extra.ExtraNull}.</p>
|
||||
* <p>Extra objects will be found only in the major classes and their
|
||||
* associated DTO from coreutil. Other packages will have the semantic values
|
||||
* instead and convert them to extra data only when creating a major version
|
||||
* of itself through transition interfaces.</p>
|
||||
*/
|
||||
package org.pasteque.coreutil.extra;
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package org.pasteque.coreutil.transition;
|
||||
|
||||
import org.pasteque.coreutil.ImmutableList;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.price.Discount;
|
||||
import org.pasteque.coreutil.price.Price;
|
||||
import org.pasteque.coreutil.price.Quantity;
|
||||
|
|
@ -64,12 +63,4 @@ public interface LineTransition {
|
|||
* @return The full discount applied to the base price.
|
||||
*/
|
||||
public Discount getFinalDiscount();
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* Implementations should use an {@link org.pasteque.coreutil.extra.ExtraBuilder}
|
||||
* to remove the semantic of all non-mandatory fields.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package org.pasteque.coreutil.transition;
|
||||
|
||||
import org.pasteque.coreutil.ImmutableList;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.price.Discount;
|
||||
import org.pasteque.coreutil.price.FinalTaxAmount;
|
||||
import org.pasteque.coreutil.price.Price2;
|
||||
|
||||
|
|
@ -34,18 +32,4 @@ public interface OrderTransition
|
|||
* @return The content of the order.
|
||||
*/
|
||||
public ImmutableList<LineTransition> getLines();
|
||||
|
||||
/**
|
||||
* Get the discount applied to the whole order.
|
||||
* @return The discount applied to the whole order.
|
||||
*/
|
||||
public Discount getDiscount();
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* Implementations should use an {@link org.pasteque.coreutil.extra.ExtraBuilder}
|
||||
* to remove the semantic of all non-mandatory fields.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.pasteque.major.domain;
|
||||
|
||||
import org.pasteque.coreutil.datatransfer.dto.CashRegisterDTO;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Model for a cash register. Tickets are associated to a cash register
|
||||
|
|
@ -15,8 +14,6 @@ public class MajorCashRegister
|
|||
private String label;
|
||||
/** {@see getNextTicketNumber()} */
|
||||
private int nextTicketNumber;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create from all fields.
|
||||
|
|
@ -24,28 +21,24 @@ public class MajorCashRegister
|
|||
* @param label See {@link getLabel()}.
|
||||
* @param nextTicketNumber The number to assign to the next ticket
|
||||
* from this cash register.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public MajorCashRegister(
|
||||
String reference,
|
||||
String label,
|
||||
int nextTicketNumber,
|
||||
ExtraObject extra) {
|
||||
int nextTicketNumber) {
|
||||
this.reference = reference;
|
||||
this.label = label;
|
||||
this.nextTicketNumber = nextTicketNumber;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create from a DTO.
|
||||
* Create from a DTO. All data are copied to break references.
|
||||
* @param dto The DTO to convert.
|
||||
*/
|
||||
public MajorCashRegister(CashRegisterDTO dto) {
|
||||
this.reference = dto.getReference();
|
||||
this.label = dto.getLabel();
|
||||
this.reference = new String(dto.getReference());
|
||||
this.label = new String(dto.getLabel());
|
||||
this.nextTicketNumber = dto.getNextTicketNumber();
|
||||
this.extra = dto.getExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,12 +77,4 @@ public class MajorCashRegister
|
|||
/* package */ final void revertNextTicketNumber() {
|
||||
this.nextTicketNumber--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public final ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package org.pasteque.major.domain;
|
|||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.pasteque.coreutil.datatransfer.dto.CashSessionDTO;
|
||||
import org.pasteque.coreutil.datatransfer.dto.FiscalTicketDTO;
|
||||
import org.pasteque.coreutil.datatransfer.dto.MovementDTO;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
|
||||
/**
|
||||
* <p>Ongoing cash session, managing movements and payments.</p>
|
||||
|
|
@ -32,8 +32,6 @@ public final class MajorCashSession
|
|||
private List<MajorTicket> tickets;
|
||||
/** See {@link isClosed()}. */
|
||||
private boolean closed;
|
||||
/** See {@link getExtra()}. */
|
||||
private ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a cash session from all fields.
|
||||
|
|
@ -43,7 +41,6 @@ public final class MajorCashSession
|
|||
* @param openDate See {@link getOpenDate()}.
|
||||
* @param movements The list of movements registered during this session.
|
||||
* @param tickets The list of tickets already registered during this session.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public MajorCashSession(
|
||||
MajorCashRegister cashRegister,
|
||||
|
|
@ -51,8 +48,7 @@ public final class MajorCashSession
|
|||
boolean continuous,
|
||||
Date openDate,
|
||||
List<Movement> movements,
|
||||
List<MajorTicket> tickets,
|
||||
ExtraObject extra) {
|
||||
List<MajorTicket> tickets) {
|
||||
this.cashRegister = cashRegister;
|
||||
this.sequence = sequence;
|
||||
this.continuous = continuous;
|
||||
|
|
@ -60,7 +56,6 @@ public final class MajorCashSession
|
|||
this.movements = movements;
|
||||
this.tickets = tickets;
|
||||
this.closed = false;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,12 +239,4 @@ public final class MajorCashSession
|
|||
public Date getOpenDate() {
|
||||
return openDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public final ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.pasteque.major.domain;
|
||||
|
||||
import org.pasteque.coreutil.ImmutableList;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.price.Discount;
|
||||
import org.pasteque.coreutil.price.Price;
|
||||
import org.pasteque.coreutil.price.Quantity;
|
||||
|
|
@ -16,6 +15,7 @@ import org.pasteque.coreutil.transition.LineTransition;
|
|||
* @see org.pasteque.major.domain.MajorOrder
|
||||
* @see org.pasteque.major.domain.MajorTicket
|
||||
*/
|
||||
// TODO add extradata to pass to MajorTicket
|
||||
public final class MajorLine implements LineTransition
|
||||
{
|
||||
/** See {@link getProductReference()}. */
|
||||
|
|
@ -34,8 +34,6 @@ public final class MajorLine implements LineTransition
|
|||
private final Price totalPrice;
|
||||
/** See {@link getFinalDiscount()}. */
|
||||
private final Discount finalDiscount;
|
||||
/** See {@link getExtra()}. */
|
||||
private final ExtraObject extra;
|
||||
|
||||
/**
|
||||
* <p>Create a major line from outside this package.
|
||||
|
|
@ -63,7 +61,6 @@ public final class MajorLine implements LineTransition
|
|||
* @param totalTaxes See {@link getTotalTaxes()}.
|
||||
* @param totalPrice See {@link getTotalPrice()}.
|
||||
* @param finalDiscount See {@link getFinalDiscount()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
/* package */ MajorLine(
|
||||
String productReference,
|
||||
|
|
@ -73,8 +70,7 @@ public final class MajorLine implements LineTransition
|
|||
Price price,
|
||||
ImmutableList<TaxAmount> totalTaxes,
|
||||
Price totalPrice,
|
||||
Discount finalDiscount,
|
||||
ExtraObject extra) {
|
||||
Discount finalDiscount) {
|
||||
this.productReference = productReference;
|
||||
this.productLabel = productLabel;
|
||||
this.unitPrice = unitPrice;
|
||||
|
|
@ -83,7 +79,6 @@ public final class MajorLine implements LineTransition
|
|||
this.totalTaxes = totalTaxes;
|
||||
this.totalPrice = totalPrice;
|
||||
this.finalDiscount = finalDiscount;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,7 +94,6 @@ public final class MajorLine implements LineTransition
|
|||
this.totalTaxes = source.getTotalTaxes();
|
||||
this.totalPrice = source.getTotalPrice();
|
||||
this.finalDiscount = source.getFinalDiscount();
|
||||
this.extra = source.getExtra();
|
||||
}
|
||||
|
||||
@Override // from LineTransition
|
||||
|
|
@ -141,9 +135,4 @@ public final class MajorLine implements LineTransition
|
|||
public Discount getFinalDiscount() {
|
||||
return this.finalDiscount;
|
||||
}
|
||||
|
||||
@Override // from LineTransition
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package org.pasteque.major.domain;
|
||||
|
||||
import org.pasteque.coreutil.ImmutableList;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.price.Discount;
|
||||
import org.pasteque.coreutil.price.FinalTaxAmount;
|
||||
import org.pasteque.coreutil.price.Price2;
|
||||
import org.pasteque.coreutil.transition.LineTransition;
|
||||
|
|
@ -15,15 +13,13 @@ import org.pasteque.coreutil.transition.OrderTransition;
|
|||
* for ease of use, but instances are not expected to be generated from
|
||||
* themselves.</p>
|
||||
*/
|
||||
// TODO add extradata to pass to MajorTicket
|
||||
public final class MajorOrder implements OrderTransition
|
||||
{
|
||||
private final Price2 finalPrice;
|
||||
private final ImmutableList<FinalTaxAmount> taxAmounts;
|
||||
private final Price2 finalTaxedPrice;
|
||||
private final ImmutableList<MajorLine> lines;
|
||||
private final Discount discount;
|
||||
/** See {@link getExtra()}. */
|
||||
private final ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a major order from all data.
|
||||
|
|
@ -31,22 +27,16 @@ public final class MajorOrder implements OrderTransition
|
|||
* @param taxAmounts See {@link getTaxAmounts()}.
|
||||
* @param finalTaxedPrice See {@link getFinalTaxedPrice()}.
|
||||
* @param lines See {@link getLines()}.
|
||||
* @param discount See {@link getDiscount()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public MajorOrder(
|
||||
Price2 finalPrice,
|
||||
ImmutableList<FinalTaxAmount> taxAmounts,
|
||||
Price2 finalTaxedPrice,
|
||||
ImmutableList<MajorLine> lines,
|
||||
Discount discount,
|
||||
ExtraObject extra) {
|
||||
ImmutableList<MajorLine> lines) {
|
||||
this.finalPrice = finalPrice;
|
||||
this.taxAmounts = taxAmounts;
|
||||
this.finalTaxedPrice = finalTaxedPrice;
|
||||
this.lines = lines;
|
||||
this.discount = discount;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -70,13 +60,10 @@ public final class MajorOrder implements OrderTransition
|
|||
trans.getPrice(),
|
||||
trans.getTotalTaxes(),
|
||||
trans.getTotalPrice(),
|
||||
trans.getFinalDiscount(),
|
||||
trans.getExtra());
|
||||
trans.getFinalDiscount());
|
||||
|
||||
}
|
||||
this.lines = MajorLine.fromTransition(order.getLines());
|
||||
this.discount = order.getDiscount();
|
||||
this.extra = order.getExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,20 +110,4 @@ public final class MajorOrder implements OrderTransition
|
|||
public ImmutableList<MajorLine> getMajorLines() {
|
||||
return this.lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the discount applied to the whole order.
|
||||
* @return The discount applied to the whole order.
|
||||
*/
|
||||
public Discount getDiscount() {
|
||||
return this.discount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package org.pasteque.major.domain;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.pasteque.coreutil.constants.FiscalTicketType;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.price.Price2;
|
||||
import org.pasteque.coreutil.price.TaxAmount;
|
||||
import org.pasteque.coreutil.ImmutableList;
|
||||
|
|
@ -39,8 +38,7 @@ public final class MajorTicket
|
|||
private Price2 finalTaxedPrice;
|
||||
/** See {@link getFinalPrice(). */
|
||||
private Price2 finalPrice;
|
||||
/** See {@link getExtra(). */
|
||||
private ExtraObject extra;
|
||||
// TODO: add extra data
|
||||
|
||||
/**
|
||||
* Create by linking an order and payments. It will create the associated
|
||||
|
|
@ -117,7 +115,7 @@ public final class MajorTicket
|
|||
* @return The payment date, when the ticket was created..
|
||||
*/
|
||||
public Date getDate() {
|
||||
return this.date;
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -125,7 +123,7 @@ public final class MajorTicket
|
|||
* @return The content of the ticket.
|
||||
*/
|
||||
public ImmutableList<MajorLine> getLines() {
|
||||
return this.lines;
|
||||
return lines;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,7 +131,7 @@ public final class MajorTicket
|
|||
* @return The list of payments used to pay the ticket.
|
||||
*/
|
||||
public ImmutableList<Payment> getPayments() {
|
||||
return this.payments;
|
||||
return payments;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -141,7 +139,7 @@ public final class MajorTicket
|
|||
* @return The list of tax amounts.
|
||||
*/
|
||||
public ImmutableList<TaxAmount> getTaxAmounts() {
|
||||
return this.taxAmounts;
|
||||
return taxAmounts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -149,7 +147,7 @@ public final class MajorTicket
|
|||
* @return The total price.
|
||||
*/
|
||||
public Price2 getFinalTaxedPrice() {
|
||||
return this.finalTaxedPrice;
|
||||
return finalTaxedPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -157,14 +155,6 @@ public final class MajorTicket
|
|||
* @return The total price without taxes.
|
||||
*/
|
||||
public Price2 getFinalPrice() {
|
||||
return this.finalPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the non mandatory extra data.
|
||||
* @return The root object containing all the extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
return finalPrice;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package org.pasteque.major.domain;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.constants.FiscalTicketType;
|
||||
import org.pasteque.coreutil.datatransfer.dto.FiscalTicketDTO;
|
||||
|
||||
|
|
@ -24,8 +23,7 @@ public final class MajorZTicket
|
|||
MajorCashSession session,
|
||||
Date closeDate,
|
||||
int closeType,
|
||||
List<Movement> endAmounts,
|
||||
ExtraObject extra) {
|
||||
List<Movement> endAmounts) {
|
||||
// TODO: not implemented
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.pasteque.major.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.datatransfer.dto.MovementDTO;
|
||||
import org.pasteque.coreutil.datatransfer.dto.WeakAssociationDTO;
|
||||
import org.pasteque.coreutil.price.Price2;
|
||||
|
|
@ -26,8 +25,6 @@ public class Movement
|
|||
private final Price2 currencyAmount;
|
||||
/** See {@link getDate()}. */
|
||||
private Date date;
|
||||
/** See {@link getExtra()}. */
|
||||
private final ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a payment from all fields.
|
||||
|
|
@ -37,7 +34,6 @@ public class Movement
|
|||
* @param currencyLabel See {@link getCurrencyLabel()}.
|
||||
* @param currencyAmount See {@link getCurrencyAmount()}.
|
||||
* @param date See {@link getDate()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public Movement(
|
||||
String paymentModeReference,
|
||||
|
|
@ -45,15 +41,13 @@ public class Movement
|
|||
String currencyReference,
|
||||
String currencyLabel,
|
||||
Price2 currencyAmount,
|
||||
Date date,
|
||||
ExtraObject extra) {
|
||||
Date date) {
|
||||
this.paymentModeReference = paymentModeReference;
|
||||
this.paymentModeLabel = paymentModeLabel;
|
||||
this.currencyReference = currencyReference;
|
||||
this.currencyLabel = currencyLabel;
|
||||
this.currencyAmount = currencyAmount;
|
||||
this.date = date;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -67,7 +61,6 @@ public class Movement
|
|||
this.currencyLabel = dto.getCurrency().getLabel();
|
||||
this.currencyAmount = new Price2(dto.getCurrencyAmount());
|
||||
this.date = new Date(dto.getDate().getTime());
|
||||
this.extra = dto.getExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,14 +116,6 @@ public class Movement
|
|||
return this.date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public final ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DTO from this object.
|
||||
* @return The content of this object as a DTO.
|
||||
|
|
@ -144,7 +129,6 @@ public class Movement
|
|||
this.currencyReference,
|
||||
this.currencyLabel),
|
||||
this.currencyAmount.toDouble(),
|
||||
this.date,
|
||||
this.extra);
|
||||
this.date);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.pasteque.major.domain;
|
||||
|
||||
import org.pasteque.coreutil.datatransfer.dto.WeakAssociationDTO;
|
||||
import org.pasteque.coreutil.extra.ExtraObject;
|
||||
import org.pasteque.coreutil.price.Price2;
|
||||
import org.pasteque.coreutil.datatransfer.dto.PaymentDTO;
|
||||
|
||||
|
|
@ -25,8 +24,6 @@ public final class Payment
|
|||
private final String currencyLabel;
|
||||
/** See {@link getCurrencyAmount()}. */
|
||||
private final Price2 currencyAmount;
|
||||
/** See {@link getExtra()}. */
|
||||
private final ExtraObject extra;
|
||||
|
||||
/**
|
||||
* Create a payment from all fields.
|
||||
|
|
@ -36,7 +33,6 @@ public final class Payment
|
|||
* @param currencyReference See {@link getCurrencyReference()}.
|
||||
* @param currencyLabel See {@link getCurrencyLabel()}.
|
||||
* @param currencyAmount See {@link getCurrencyAmount()}.
|
||||
* @param extra See {@link getExtra()}.
|
||||
*/
|
||||
public Payment(
|
||||
String paymentModeReference,
|
||||
|
|
@ -44,15 +40,13 @@ public final class Payment
|
|||
String currencyReference,
|
||||
String currencyLabel,
|
||||
Price2 amount,
|
||||
Price2 currencyAmount,
|
||||
ExtraObject extra) {
|
||||
Price2 currencyAmount) {
|
||||
this.paymentModeReference = paymentModeReference;
|
||||
this.paymentModeLabel = paymentModeLabel;
|
||||
this.currencyReference = currencyReference;
|
||||
this.currencyLabel = currencyLabel;
|
||||
this.amount = amount;
|
||||
this.currencyAmount = currencyAmount;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,7 +60,6 @@ public final class Payment
|
|||
this.currencyReference = dto.getCurrency().getReference();
|
||||
this.currencyLabel = dto.getCurrency().getLabel();
|
||||
this.currencyAmount = new Price2(dto.getCurrencyAmount());
|
||||
this.extra = dto.getExtra();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,14 +116,6 @@ public final class Payment
|
|||
return currencyAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all other data.
|
||||
* @return The root object of extra data.
|
||||
*/
|
||||
public ExtraObject getExtra() {
|
||||
return this.extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DTO from this object.
|
||||
* @return The content of this object as a DTO.
|
||||
|
|
@ -144,7 +129,6 @@ public final class Payment
|
|||
new WeakAssociationDTO(
|
||||
this.currencyReference,
|
||||
this.currencyLabel),
|
||||
this.currencyAmount.toDouble(),
|
||||
this.extra);
|
||||
this.currencyAmount.toDouble());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@
|
|||
* but not modified. All properties and methods are then final but the class
|
||||
* may be extended to include more data.</p>
|
||||
*/
|
||||
// TODO: add a way to propagate extra data to the DTO
|
||||
package org.pasteque.major.domain;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue