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
e1dfa870
Commit
e1dfa870
authored
Jun 04, 2025
by
Riegel
Browse files
Feat: Add cache for CityObjects
parent
ef413298
Changes
1
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/CityObjectCache.java
0 → 100644
View file @
e1dfa870
package
de.hft.stuttgart.citydoctor2.database
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityObject
;
import
de.hft.stuttgart.citydoctor2.datastructure.GmlId
;
import
java.util.List
;
import
java.util.Map
;
import
java.lang.ref.SoftReference
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* Soft-reference cache for
*/
public
class
CityObjectCache
{
private
final
Map
<
GmlId
,
SoftReference
<
CityObject
>>
cache
=
new
ConcurrentHashMap
<>();
public
void
put
(
GmlId
id
,
CityObject
cityObject
)
{
cache
.
put
(
id
,
new
SoftReference
<>(
cityObject
));
}
public
void
cache
(
List
<?
extends
CityObject
>
objects
)
{
}
public
CityObject
get
(
GmlId
id
)
{
SoftReference
<
CityObject
>
ref
=
cache
.
get
(
id
);
if
(
ref
==
null
)
{
return
null
;
}
CityObject
cityObject
=
ref
.
get
();
if
(
cityObject
==
null
)
{
cityObject
=
DatabaseHandler
.
unmarshallCityObject
(
id
);
if
(
cityObject
==
null
)
{
cache
.
remove
(
id
);
}
else
{
this
.
put
(
id
,
cityObject
);
}
}
return
cityObject
;
}
public
void
remove
(
GmlId
id
)
{
cache
.
remove
(
id
);
}
public
void
clear
()
{
cache
.
clear
();
}
public
int
size
()
{
return
cache
.
size
();
}
}
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