Skip to content

Commit

Permalink
Optimized the usage of the map with the already processed entities
Browse files Browse the repository at this point in the history
  • Loading branch information
UO289845 committed Apr 1, 2024
1 parent 3e278c1 commit 8607b0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public abstract class AbstractGenerator {
private Locale localization = Locale.getDefault();
private ResourceBundle messages;

public static Map<String, ItemDocumentImpl> alreadyProcessedEntities = new HashMap<>();
private static Map<String, ItemDocumentImpl> alreadyProcessedEntities = new HashMap<>();

private String propertyId = "";
private QuestionType type;

private static final String MESSAGES_PATH = "messages";

public AbstractGenerator(String propertyId, QuestionType type) {
this.propertyId = propertyId;
this.type = type;
Expand Down Expand Up @@ -90,11 +91,11 @@ public String getPropertyId() {
return propertyId;
}

public static Map<String, ItemDocumentImpl> getAlreadyProcessedEntities() {
return new HashMap<>(alreadyProcessedEntities);
public static ItemDocumentImpl getAlreadyProcessedEntity(String id) {
return alreadyProcessedEntities.get(id);
}

public static void addItem(String entity, ItemDocumentImpl item) {
public static void addProcessedEntity(String entity, ItemDocumentImpl item) {
alreadyProcessedEntities.put(entity, item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ protected String processRightAnswer(Statement st) {
String entity = getRightAnswerEntity(st.getValue().toString());
String answer = "";
try {
ItemDocumentImpl idi = getAlreadyProcessedEntities().get(entity);
ItemDocumentImpl idi = getAlreadyProcessedEntity(entity);
if(idi==null) {
idi = (ItemDocumentImpl) wbdf.getEntityDocument(entity);
answer = getName(idi.getLabels());
addItem(entity, idi);
addProcessedEntity(entity, idi);
}
else
answer = getName(idi.getLabels());
Expand All @@ -46,12 +46,12 @@ protected String processRightAnswer(Statement st) {
}

protected String getAnswer(String id){
ItemDocumentImpl idi = alreadyProcessedEntities.get(id);
ItemDocumentImpl idi = getAlreadyProcessedEntity(id);

if(idi==null) {
try {
idi = (ItemDocumentImpl) wbdf.getEntityDocument(id);
alreadyProcessedEntities.put(id, idi);
addProcessedEntity(id, idi);
} catch (MediaWikiApiErrorException | IOException e) {
/*
* * @throws MediaWikiApiErrorException
Expand Down

0 comments on commit 8607b0a

Please sign in to comment.