View Javadoc

1   /*
2    * Copyright 2006-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sourceforge.domian.test.benchmark;
17  
18  
19  import java.text.SimpleDateFormat;
20  import java.util.Date;
21  import java.util.concurrent.atomic.AtomicLong;
22  
23  import net.sourceforge.domian.entity.AbstractUUIDEntity;
24  
25  
26  /** A simple entity class for holding a complete queen puzzle constellation consisting of eight queen pieces. */
27  final class QueenPuzzleConstellation extends AbstractUUIDEntity {
28  
29      private static final AtomicLong constellationNumberGenerator = new AtomicLong(1);
30  
31      public static void resetConstellationNumber() {
32          constellationNumberGenerator.set(1);
33      }
34  
35      private final long constellationNumber;
36      private final long timeOfCreation;
37  
38      private Boolean solvesQueenPuzzle;
39  
40      private final ChessPiecePlacing queen1Placing;
41      private final ChessPiecePlacing queen2Placing;
42      private final ChessPiecePlacing queen3Placing;
43      private final ChessPiecePlacing queen4Placing;
44      private final ChessPiecePlacing queen5Placing;
45      private final ChessPiecePlacing queen6Placing;
46      private final ChessPiecePlacing queen7Placing;
47      private final ChessPiecePlacing queen8Placing;
48  
49  
50      /**
51       * @param queen1Placing the first queen piece
52       * @param queen2Placing the second queen piece
53       * @param queen3Placing the third queen piece
54       * @param queen4Placing the forth queen piece
55       * @param queen5Placing the fifth queen piece
56       * @param queen6Placing the sixth queen piece
57       * @param queen7Placing the seventh queen piece
58       * @param queen8Placing the eighth queen piece
59       */
60      QueenPuzzleConstellation(final ChessPiecePlacing queen1Placing,
61                               final ChessPiecePlacing queen2Placing,
62                               final ChessPiecePlacing queen3Placing,
63                               final ChessPiecePlacing queen4Placing,
64                               final ChessPiecePlacing queen5Placing,
65                               final ChessPiecePlacing queen6Placing,
66                               final ChessPiecePlacing queen7Placing,
67                               final ChessPiecePlacing queen8Placing) {
68          this.constellationNumber = constellationNumberGenerator.getAndIncrement();
69  
70          this.queen1Placing = queen1Placing;
71          this.queen2Placing = queen2Placing;
72          this.queen3Placing = queen3Placing;
73          this.queen4Placing = queen4Placing;
74          this.queen5Placing = queen5Placing;
75          this.queen6Placing = queen6Placing;
76          this.queen7Placing = queen7Placing;
77          this.queen8Placing = queen8Placing;
78  
79          this.timeOfCreation = System.currentTimeMillis();
80      }
81  
82      ChessPiecePlacing getQueen1Placing() {
83          return this.queen1Placing;
84      }
85  
86      ChessPiecePlacing getQueen2Placing() {
87          return this.queen2Placing;
88      }
89  
90      ChessPiecePlacing getQueen3Placing() {
91          return this.queen3Placing;
92      }
93  
94      ChessPiecePlacing getQueen4Placing() {
95          return this.queen4Placing;
96      }
97  
98      ChessPiecePlacing getQueen5Placing() {
99          return this.queen5Placing;
100     }
101 
102     ChessPiecePlacing getQueen6Placing() {
103         return this.queen6Placing;
104     }
105 
106     ChessPiecePlacing getQueen7Placing() {
107         return this.queen7Placing;
108     }
109 
110     ChessPiecePlacing getQueen8Placing() {
111         return this.queen8Placing;
112     }
113 
114     void setSolvesQueenPuzzle(final Boolean doSolveTheQueenPuzzle) {
115         this.solvesQueenPuzzle = doSolveTheQueenPuzzle;
116     }
117 
118     Boolean isProcessed() {
119         return this.solvesQueenPuzzle != null;
120     }
121 
122     Boolean solvesQueenPuzzle() {
123         return this.isProcessed() && this.solvesQueenPuzzle;
124     }
125 
126     @Override
127     public String toString() {
128         StringBuilder builder = new StringBuilder();
129         builder.append("[");
130         builder.append(this.queen1Placing);
131         builder.append(", ");
132         builder.append(this.queen2Placing);
133         builder.append(", ");
134         builder.append(this.queen3Placing);
135         builder.append(", ");
136         builder.append(this.queen4Placing);
137         builder.append(", ");
138         builder.append(this.queen5Placing);
139         builder.append(", ");
140         builder.append(this.queen6Placing);
141         builder.append(", ");
142         builder.append(this.queen7Placing);
143         builder.append(", ");
144         builder.append(this.queen8Placing);
145         builder.append("]");
146         builder.append(" [#");
147         builder.append(this.constellationNumber);
148         builder.append(", created ");
149         builder.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS").format(new Date(this.timeOfCreation)));
150         builder.append("]");
151         return builder.toString();
152     }
153 }