Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
3087a8d7
Commit
3087a8d7
authored
Jun 19, 2026
by
Matthias Betz
Browse files
Add PickRegistry mapping picking ids to model objects
parent
e03de645
Changes
2
Show whitespace changes
Inline
Side-by-side
CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/gl/PickRegistry.java
0 → 100644
View file @
3087a8d7
package
de.hft.stuttgart.citydoctor2.gui.gl
;
import
java.util.ArrayList
;
import
java.util.List
;
/** Maps picking ids (1-based) to the model objects they represent. */
public
class
PickRegistry
{
private
final
List
<
Object
>
targets
=
new
ArrayList
<>();
/** Registers a target and returns its non-zero picking id. */
public
int
register
(
Object
target
)
{
targets
.
add
(
target
);
return
targets
.
size
();
// id = index + 1
}
/** Resolves a picking id to its target, or null for background / unknown id. */
public
Object
resolve
(
int
id
)
{
if
(
id
<=
0
||
id
>
targets
.
size
())
{
return
null
;
}
return
targets
.
get
(
id
-
1
);
}
public
int
size
()
{
return
targets
.
size
();
}
}
CityDoctorParent/Extensions/CityDoctorGUI/src/test/java/de/hft/stuttgart/citydoctor2/gui/gl/PickRegistryTest.java
0 → 100644
View file @
3087a8d7
package
de.hft.stuttgart.citydoctor2.gui.gl
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
org.junit.Test
;
public
class
PickRegistryTest
{
@Test
public
void
assignsSequentialNonZeroIdsAndResolvesThem
()
{
PickRegistry
reg
=
new
PickRegistry
();
Object
a
=
"a"
;
Object
b
=
"b"
;
int
idA
=
reg
.
register
(
a
);
int
idB
=
reg
.
register
(
b
);
assertEquals
(
1
,
idA
);
assertEquals
(
2
,
idB
);
assertEquals
(
a
,
reg
.
resolve
(
idA
));
assertEquals
(
b
,
reg
.
resolve
(
idB
));
}
@Test
public
void
resolvesBackgroundAndOutOfRangeToNull
()
{
PickRegistry
reg
=
new
PickRegistry
();
reg
.
register
(
"a"
);
assertNull
(
reg
.
resolve
(
0
));
assertNull
(
reg
.
resolve
(
99
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment