aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java
blob: ee2b74d548c62091f52f630ca0f3f481e24e67ab (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
package uk.ac.ox.cs.pagoda.util.tuples;

/**
 * Allows to create an immutable <tt>Tuple</tt> in a non-atomic way.
 * It can create only one <tt>Tuple</tt>.
 * */
public class TupleBuilder<T> {

    private Tuple tuple = new Tuple();

    private boolean building = true;

    public boolean append(T t) {
        if(building) tuple.elements.add(t);
        return building;
    }

    public Tuple<T> build() {
        if(building) {
            building = false;
            return tuple;
        }
        return null;
    }
}