View Javadoc
1   package de.japrost.jabudget.domain.account;
2   
3   import java.util.Optional;
4   
5   /**
6    * Builder for {@link Entry}.
7    */
8   public class EntryBuilder {
9   
10  	private String accountId;
11  	private String code;
12  	private String subject;
13  
14  	/**
15  	 * Create an empty builder.
16  	 */
17  	public EntryBuilder() {
18  	}
19  
20  	/**
21  	 * Create a builder by example.
22  	 *
23  	 * @param example the example to use. MAY BE {@code null}.
24  	 */
25  	public EntryBuilder(final Entry example) {
26  		if (example != null) {
27  			this.accountId = example.getAccountId();
28  			this.code = example.getCode();
29  			this.subject = example.getSubject();
30  		}
31  	}
32  
33  	/**
34  	 * Factory for a an empty builder.
35  	 *
36  	 * @return a new builder.
37  	 */
38  	public static EntryBuilder builder() {
39  		return new EntryBuilder();
40  	}
41  
42  	/**
43  	 * Factory for a builder by example.
44  	 *
45  	 * @param example the example to use. MAY BE {@code null}.
46  	 * @return a builder filled with value of example.
47  	 */
48  	public static EntryBuilder builder(Entry example) {
49  		return new EntryBuilder(example);
50  	}
51  	/**
52  	 * Build the result.
53  	 *
54  	 * @return a new instance.
55  	 */
56  	public Entry build() {
57  		final Entryin/account/Entry.html#Entry">Entry result = new Entry(accountId,code,subject);
58  		return result;
59  	}
60  
61  
62  	/**
63  	 * Build if the result would be valid.
64  	 *
65  	 * @return a instance or an empty optional.
66  	 */
67  	public Optional<Entry> buildOptional() {
68  		// TODO where to put this validation?
69  		if (accountId == null || code == null || subject == null) {
70  			return Optional.empty();
71  		}
72  		final Entryin/account/Entry.html#Entry">Entry result = new Entry(accountId,code,subject);
73  		return Optional.of(result);
74  	}
75  
76  	/**
77  	 * @see Entry#getAccountId()
78  	 */
79  	public void setAccountId(String accountId) {
80  		this.accountId = accountId;
81  	}
82  
83  	/**
84  	 * @see Entry#getCode()
85  	 */
86  	public void setCode(String code) {
87  		this.code = code;
88  	}
89  
90  	/**
91  	 * @see Entry#getSubject()
92  	 */
93  	public void setSubject(String subject) {
94  		this.subject = subject;
95  	}
96  }