• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/admin/DirInfo.java
1
/*
2
 * Copyright (c) 2021 The University of Manchester
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
 *     https://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 uk.ac.manchester.spinnaker.alloc.admin;
17

18
import static java.util.Objects.requireNonNull;
19
import static org.slf4j.LoggerFactory.getLogger;
20

21
import java.util.EnumMap;
22
import java.util.HashMap;
23
import java.util.Map;
24

25
import org.slf4j.Logger;
26

27
import uk.ac.manchester.spinnaker.alloc.db.DatabaseAPI.Connection;
28
import uk.ac.manchester.spinnaker.alloc.db.SQLQueries;
29
import uk.ac.manchester.spinnaker.alloc.model.Direction;
30
import uk.ac.manchester.spinnaker.machine.board.ValidTriadZ;
31

32
/**
33
 * A mapping that says how to go from one board's coordinates (only the Z
34
 * coordinate matters for this) to another when you move in a particular
35
 * direction. Comes from the {@code movement_directions} table in the database.
36
 * <p>
37
 * Consider this board layout (a classic 24 board machine, with wrap-arounds not
38
 * shown):
39
 * <p>
40
 * <img src="doc-files/DirInfo1.png" width="450" alt="24-board layout">
41
 * <p>
42
 * Bear in mind that 0,1,0 is <em>actually</em> 12 chips vertically and 0 chips
43
 * horizontally offset from 0,0,0. (Also, the real boards are slightly offset
44
 * from this layout.)
45
 *
46
 * @author Donal Fellows
47
 * @see Direction
48
 * @see MachineDefinitionLoader
49
 */
50
public final class DirInfo extends SQLQueries {
51
        private static final Logger log = getLogger(DirInfo.class);
1✔
52

53
        private static final Map<Integer, EnumMap<Direction, DirInfo>> MAP =
1✔
54
                        new HashMap<>();
55

56
        /**
57
         * When your Z coordinate is this.
58
         */
59
        @ValidTriadZ
60
        public final int z;
61

62
        /** When you are moving in this direction. */
63
        public final Direction dir;
64

65
        /** Change your X coordinate by this. */
66
        public final int dx;
67

68
        /** Change your Y coordinate by this. */
69
        public final int dy;
70

71
        /** Change your Z coordinate by this. */
72
        public final int dz;
73

74
        private DirInfo(int z, Direction d, int dx, int dy, int dz) {
1✔
75
                this.z = z;
1✔
76
                this.dir = requireNonNull(d);
1✔
77
                this.dx = dx;
1✔
78
                this.dy = dy;
1✔
79
                this.dz = dz;
1✔
80

81
                MAP.computeIfAbsent(z, __ -> new EnumMap<>(Direction.class)).put(d,
1✔
82
                                this);
83
        }
1✔
84

85
        /**
86
         * Obtain the correct motion information given a starting point and a
87
         * direction.
88
         *
89
         * @param z
90
         *            The starting Z coordinate. (Motions are independent of X and
91
         *            Y.) Must be in range {@code 0..2}.
92
         * @param direction
93
         *            The direction to move in.
94
         * @return How to move.
95
         */
96
        public static DirInfo get(int z, Direction direction) {
97
                return MAP.get(z).get(direction);
1✔
98
        }
99

100
        @Override
101
        public boolean equals(Object o) {
102
                return (o instanceof DirInfo di) && (z == di.z) && (dir == di.dir);
×
103
        }
104

105
        @Override
106
        public int hashCode() {
107
                return z ^ dir.hashCode();
×
108
        }
109

110
        static void load(Connection conn) {
111
                if (MAP.isEmpty()) {
1✔
112
                        conn.transaction(false, () -> {
1✔
113
                                try (var di = conn.query(LOAD_DIR_INFO)) {
1✔
114
                                        di.call(row -> new DirInfo(row.getInt("z"),
1✔
115
                                                        row.getEnum("direction", Direction.class),
1✔
116
                                                        row.getInt("dx"), row.getInt("dy"),
1✔
117
                                                        row.getInt("dz")));
1✔
118
                                }
119
                        });
1✔
120
                        log.debug("created {} DirInfo instances",
1✔
121
                                        MAP.values().stream().mapToInt(Map::size).sum());
1✔
122
                }
123
        }
1✔
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc