All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.hosted.controller.api.integration.billing.InvoiceUpdate Maven / Gradle / Ivy

There is a newer version: 8.253.3
Show newest version
package com.yahoo.vespa.hosted.controller.api.integration.billing;

/**
 * Helper to track changes to an invoice.
 *
 * @author gjoranv
 */
public record InvoiceUpdate(int itemsAdded, int itemsRemoved, int itemsModified) {
    public boolean isEmpty() {
        return itemsAdded == 0 && itemsRemoved == 0 && itemsModified == 0;
    }

    public static InvoiceUpdate empty() {
        return new InvoiceUpdate(0, 0, 0);
    }

    public static class Counter {
        private int itemsAdded = 0;
        private int itemsRemoved = 0;
        private int itemsModified = 0;

        public void addedItem() {
            itemsAdded++;
        }

        public void removedItem() {
            itemsRemoved++;
        }

        public void modifiedItem() {
            itemsModified++;
        }

        public void add(InvoiceUpdate other) {
            itemsAdded += other.itemsAdded;
            itemsRemoved += other.itemsRemoved;
            itemsModified += other.itemsModified;
        }

        public InvoiceUpdate finish() {
            return new InvoiceUpdate(itemsAdded, itemsRemoved, itemsModified);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy