aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/InvoiceUpdate.java
blob: 6ca3cf6ebb1e8c30499c032e0ae8f92ebe545b5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);
        }
    }

}