a214677f3acbf7041090f9cb5a79832498caba64
[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
19         @Override
20         public SoneBuilder from(Identity identity) {
21                 this.identity = identity;
22                 return this;
23         }
24
25         @Override
26         public SoneBuilder local() {
27                 this.local = true;
28                 return this;
29         }
30
31         protected void validate() throws IllegalStateException {
32                 checkState(identity != null, "identity must not be null");
33                 checkState(!local || (identity instanceof OwnIdentity),
34                                 "can not create local Sone from remote identity");
35         }
36
37 }