1 | /* |
2 | * Copyright (c) 2005 The PseudoQ Project. |
3 | * |
4 | * This file is part of PseudoQ. |
5 | * |
6 | * PseudoQ is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as published by |
8 | * the Free Software Foundation; either version 2.1 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * PseudoQ is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public License |
17 | * along with PseudoQ; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | */ |
20 | |
21 | package net.sourceforge.pseudoq.solver; |
22 | |
23 | import net.sourceforge.pseudoq.model.Coordinate; |
24 | import net.sourceforge.pseudoq.model.Region; |
25 | |
26 | /** |
27 | * Counts the number of values that have been placed within a region. |
28 | * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> |
29 | */ |
30 | public class RegionValueCounter implements Counter { |
31 | private int count = 0; |
32 | private Region region; |
33 | |
34 | /** |
35 | * Creates a new instance of RegionValueCounter. |
36 | * @param region The region to monitor. |
37 | */ |
38 | public RegionValueCounter(Region region) { |
39 | if (region == null) { |
40 | throw new IllegalArgumentException("Can't create counter for null region"); |
41 | } |
42 | |
43 | this.region = region; |
44 | } |
45 | |
46 | public void increment() { |
47 | count++; |
48 | } |
49 | |
50 | public void reset() { |
51 | count = 0; |
52 | } |
53 | |
54 | public int getCount() { |
55 | return count; |
56 | } |
57 | |
58 | public void place(Coordinate coord, int value) { |
59 | if (coord == null) { |
60 | throw new IllegalArgumentException("Can't place a value with null coordinate"); |
61 | } |
62 | assert (region != null); |
63 | |
64 | if (region.contains(coord)) { |
65 | // don't care what the value is |
66 | increment(); |
67 | } |
68 | } |
69 | |
70 | /** |
71 | * Setter for property count. |
72 | * @param count New value of property count. |
73 | */ |
74 | public void setCount(int count) { |
75 | this.count = count; |
76 | } |
77 | |
78 | } |