Skip to contentMethod: useDefault()
      1: package de.fhdw.gaming.ipspiel23.memory;
2: 
3: 
4: /**
5:  * Implements {@link IGameMemoryCapacity}.
6:  */
7: public final class GameMemoryCapacity implements IGameMemoryCapacity {
8: 
9:     /**
10:      * True when the default capacity is used. Currently 5.
11:      * Have to call it "v" because of pmd.
12:      */
13:     private final boolean vDefault;
14:     
15:     /**
16:      * True when the capacity is unlimited.
17:      * Have to call it "v" because of pmd.
18:      */
19:     private final boolean vUnlimited;
20:     
21:     /**
22:      * Capacity of the memory. -1 if it's unlimited.
23:      */
24:     private final int capacity;
25:     
26:     /**
27:      * private Constructor.
28:      * @param isDefault default.
29:      * @param isUnlimited unlimited capacity.
30:      * @param capacity Custom capacity.
31:      */
32:     private GameMemoryCapacity(final boolean isDefault, final boolean isUnlimited, final int capacity) {
33:         this.vDefault = isDefault;
34:         this.vUnlimited = isUnlimited;
35:         this.capacity = capacity;
36:     }
37: 
38:     /**
39:      * unlimited memory capacity.
40:      */
41:     public static IGameMemoryCapacity unlimited() {
42:         return new GameMemoryCapacity(false, true, -1);
43:     }
44: 
45:     /**
46:      * use the specified capacity.
47:      * @param capacity t.
48:      */
49:     public static IGameMemoryCapacity of(final Integer capacity) {
50:         if (capacity < 0) {
51:             throw new IllegalArgumentException("Capacity must be greater than or equal to 0");
52:         }
53:         return new GameMemoryCapacity(false, false, capacity);
54:     }
55: 
56:     /**
57:      * Uses a default capacity. Default is capacity of 5.
58:      */
59:     public static IGameMemoryCapacity useDefault() {
60:         return new GameMemoryCapacity(true, false, 5);
61:     }
62: 
63:     @Override
64:     public boolean isUnlimited() {
65:         return this.vUnlimited;
66:     }
67: 
68:     @Override
69:     public boolean isDefault() {
70:         return this.vDefault;
71:     }
72: 
73:     @Override
74:     public int getCapacity() {
75:         return this.capacity;
76:     }
77: }