Make the update time of a Sone final, set it in the Sone builder.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / AbstractSoneBuilder.java
1 package net.pterodactylus.sone.data.impl;
2
3 import static com.google.common.base.Preconditions.checkState;
4
5 import net.pterodactylus.sone.database.SoneBuilder;
6 import net.pterodactylus.sone.freenet.wot.Identity;
7 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
8
9 /**
10  * Abstract {@link SoneBuilder} implementation.
11  *
12  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
13  */
14 public abstract class AbstractSoneBuilder implements SoneBuilder {
15
16         protected Identity identity;
17         protected boolean local;
18         protected long lastUpdated;
19
20         @Override
21         public SoneBuilder from(Identity identity) {
22                 this.identity = identity;
23                 return this;
24         }
25
26         @Override
27         public SoneBuilder local() {
28                 this.local = true;
29                 return this;
30         }
31
32         @Override
33         public SoneBuilder lastUpdated(long lastUpdated) {
34                 this.lastUpdated = lastUpdated;
35                 return this;
36         }
37
38         protected void validate() throws IllegalStateException {
39                 checkState(identity != null, "identity must not be null");
40                 checkState(!local || (identity instanceof OwnIdentity),
41                                 "can not create local Sone from remote identity");
42                 checkState(lastUpdated > 0, "last update time must be set");
43         }
44
45 }