From Hot Wolf, 1 Year ago, written in Plain Text.
Embed
Hits: 52
1. import java.util.ArrayList;
2.
3. /**
4.  * Created by Glizda on 10.05.2017.
5.  */
6. public class Node
7. {
8.     Coordinates myCoor;
9.     private Integer color;
10.     private int[] domain;
11.     private ArrayList<Coordinates> neighbourhood = new ArrayList<>();
12.
13.     Node(int sideOfSquare, Coordinates coor)
14.     {
15.         color = null;
16.         myCoor = new Coordinates(coor.x, coor.y);
17.         setDomain(sideOfSquare);
18.         findNeighbours(sideOfSquare, coor);
19.     }
20.
21.     public void setDomain(int sideOfSquare)
22.     {
23.         if(sideOfSquare % 2 == 0)
24.             domain = new int[2 * sideOfSquare];
25.         else domain = new int[(2 * sideOfSquare) + 1];
26.         for(int i : domain)
27.         {
28.             domain[i] = i;
29.         }
30.     }
31.
32.     public void findNeighbours(int sideOfSquare, Coordinates coor)//uwaga, zapewniÄ‡ idiotoodpornoĹ›Ä‡ na rozmiar tablicy!
33.     {
34.         int x = coor.x;
35.         int y = coor.y;
36.         if(x == 0)
37.         {
38.             if(y == 0)
39.             {
40.                 //left upper corner
41.                 neighbourhood.add(new Coordinates(1, 0));
42.                 neighbourhood.add(new Coordinates(0, 1));
43.
44.             }
45.             if(y == sideOfSquare - 1)
46.             {
47.                 //left lower corner
48.                 neighbourhood.add(new Coordinates(0, sideOfSquare - 2));
49.                 neighbourhood.add(new Coordinates(1, sideOfSquare - 1));
50.             }
51.             else
52.             {
53.                 //left edge without corners
54.                 neighbourhood.add(new Coordinates(x, y - 1));
55.                 neighbourhood.add(new Coordinates(x + 1, y));
56.                 neighbourhood.add(new Coordinates(x, y + 1));
57.             }
58.         }
59.         else if(x == sideOfSquare - 1)
60.         {
61.             if(y == sideOfSquare - 1)
62.             {
63.                 //right upper corner
64.                 neighbourhood.add(new Coordinates(sideOfSquare - 2, 0));
65.                 neighbourhood.add(new Coordinates(sideOfSquare - 1, 1));
66.             }
67.             if(y == sideOfSquare - 1)
68.             {
69.                 //right lower corner
70.                 neighbourhood.add(new Coordinates(sideOfSquare - 1, sideOfSquare - 2));
71.                 neighbourhood.add(new Coordinates(sideOfSquare - 2, sideOfSquare - 1));
72.             }
73.             else
74.             {
75.                 //right edge without corners
76.                 neighbourhood.add(new Coordinates(x, y - 1));
77.                 neighbourhood.add(new Coordinates(x - 1, y));
78.                 neighbourhood.add(new Coordinates(x, y + 1));
79.             }
80.         }
81.         else if(y == 0)
82.         {
83.             //upper edge without corners
84.
85.             neighbourhood.add(new Coordinates(x, y + 1));
86.             neighbourhood.add(new Coordinates(x - 1, y));
87.             neighbourhood.add(new Coordinates(x, y + 1));
88.         }
89.         else if(y == sideOfSquare - 1)
90.         {
91.             //lower edge without corners
92.
93.             neighbourhood.add(new Coordinates(x, y - 1));
94.             neighbourhood.add(new Coordinates(x - 1, y));
95.             neighbourhood.add(new Coordinates(x + 1, y));
96.         }
97.         else
98.         {
99.             //common nodes
100.
101.             neighbourhood.add(new Coordinates(x, y - 1));
102.             neighbourhood.add(new Coordinates(x - 1, y));
103.             neighbourhood.add(new Coordinates(x + 1, y));
104.             neighbourhood.add(new Coordinates(x, y + 1));
105.         }
106.
107.     }
108.
109.     public Integer getColor()
110.     {
111.         return color;
112.     }
113.
114.     public void setColor(Integer color)
115.     {
116.         this.color = color;
117.     }
118.
119.     public int[] getDomain()
120.     {
121.         return domain;
122.     }
123.
124.     public void setDomain(int[] domain)
125.     {
126.         this.domain = domain;
127.     }
128.
129.     public ArrayList<Coordinates> getNeighbourhood()
130.     {
131.         return neighbourhood;
132.     }
133.
134.     public void setNeighbourhood(ArrayList<Coordinates> neighbourhood)
135.     {
136.         this.neighbourhood = neighbourhood;
137.     }
138. }
139.