Skip to content

Commit

Permalink
refactor: replace trove4j by eclipse collections
Browse files Browse the repository at this point in the history
  • Loading branch information
stempler committed Dec 5, 2024
1 parent f0d3823 commit 2f2c916
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ dependencies {
implementation libs.groovy.core

implementation libs.guava
api libs.trove
api libs.eclipse.collections.api
implementation libs.eclipse.collections.core
implementation libs.commons.codec
implementation libs.spring.core

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

import javax.xml.namespace.QName;

import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.factory.primitive.ObjectIntMaps;
import org.eclipse.collections.api.map.primitive.MutableObjectIntMap;
import org.eclipse.collections.api.map.primitive.ObjectIntMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -53,8 +57,6 @@
import eu.esdihumboldt.hale.common.instance.processing.InstanceProcessingExtension;
import eu.esdihumboldt.hale.common.instance.processing.InstanceProcessor;
import eu.esdihumboldt.hale.common.schema.model.TypeDefinition;
import gnu.trove.TObjectIntHashMap;
import gnu.trove.TObjectIntProcedure;

/**
* Store instances in a database
Expand Down Expand Up @@ -155,7 +157,7 @@ public IStatus run(IProgressMonitor monitor) {
(exactProgress) ? (instances.size()) : (IProgressMonitor.UNKNOWN));

AtomicInteger count = new AtomicInteger(0);
TObjectIntHashMap<QName> typeCount = new TObjectIntHashMap<>();
MutableObjectIntMap<QName> typeCount = ObjectIntMaps.mutable.of();

if (report != null) {
// set the correct start time
Expand Down Expand Up @@ -255,7 +257,7 @@ public IStatus run(IProgressMonitor monitor) {

TypeDefinition type = instance.getDefinition();
if (type != null) {
typeCount.adjustOrPutValue(type.getName(), 1, 1);
typeCount.addToValue(type.getName(), 1);
}

if (exactProgress) {
Expand Down Expand Up @@ -343,29 +345,23 @@ public IStatus run(IProgressMonitor monitor) {
"eu.esdihumboldt.hale.common.instance.orient", message);
}

private void reportTypeCount(Reporter<Message> report, TObjectIntHashMap<QName> typeCount) {
typeCount.forEachEntry(new TObjectIntProcedure<QName>() {

@Override
public boolean execute(QName typeName, int count) {
StringBuilder msg = new StringBuilder("Stored ");
msg.append(count);
msg.append(" instances of type ");
msg.append(typeName.getLocalPart());
String ns = typeName.getNamespaceURI();
if (ns != null && !ns.isEmpty()) {
msg.append(" (");
msg.append(ns);
msg.append(")");
}

report.info(new MessageImpl(msg.toString(), null));
private void reportTypeCount(Reporter<Message> report, ObjectIntMap<QName> typeCount) {
typeCount.forEachKeyValue((ObjectIntProcedure<QName>) (typeName, count) -> {
StringBuilder msg = new StringBuilder("Stored ");
msg.append(count);
msg.append(" instances of type ");
msg.append(typeName.getLocalPart());
String ns = typeName.getNamespaceURI();
if (ns != null && !ns.isEmpty()) {
msg.append(" (");
msg.append(ns);
msg.append(")");
}

// store info in statistics
report.stats().at("countPerType").at(typeName.toString()).set(count);
report.info(new MessageImpl(msg.toString(), null));

return true;
}
// store info in statistics
report.stats().at("countPerType").at(typeName.toString()).set(count);
});
}

Expand Down
3 changes: 2 additions & 1 deletion cst/plugins/eu.esdihumboldt.cst/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ dependencies {
implementation libs.groovy.core

implementation libs.guava
implementation libs.trove
implementation libs.eclipse.collections.api
implementation libs.eclipse.collections.core
implementation libs.spring.core

implementation libs.igd.osgi.util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.factory.primitive.ObjectIntMaps;
import org.eclipse.collections.api.map.primitive.MutableObjectIntMap;

import eu.esdihumboldt.cst.extension.hooks.HooksUtil;
import eu.esdihumboldt.cst.extension.hooks.TransformationTreeHook.TreeState;
import eu.esdihumboldt.cst.extension.hooks.TransformationTreeHooks;
Expand All @@ -46,8 +50,6 @@
import eu.esdihumboldt.hale.common.instance.model.InstanceMetadata;
import eu.esdihumboldt.hale.common.instance.model.InstanceUtil;
import eu.esdihumboldt.hale.common.instance.model.MutableInstance;
import gnu.trove.TObjectIntHashMap;
import gnu.trove.TObjectIntProcedure;

/**
* Property transformer based on a {@link TransformationTree}.
Expand Down Expand Up @@ -84,7 +86,7 @@ protected MetadataWorker initialValue() {

private final TransformationTreeHooks treeHooks;

private final TObjectIntHashMap<Cell> instanceCounter = new TObjectIntHashMap<>();
private final MutableObjectIntMap<Cell> instanceCounter = ObjectIntMaps.mutable.of();

private final TransformationReporter reporter;

Expand Down Expand Up @@ -162,7 +164,7 @@ public boolean offer(Runnable e) {
@Override
public void publish(final FamilyInstance source, final MutableInstance target,
final TransformationLog typeLog, final Cell typeCell) {
instanceCounter.adjustOrPutValue(typeCell, 1, 1);
instanceCounter.addToValue(typeCell, 1);

// increase output type counter
reporter.stats().at("createdPerType").at(target.getDefinition().getName().toString())
Expand Down Expand Up @@ -284,19 +286,13 @@ public void join(boolean cancel) {
}

// report instance counts
instanceCounter.forEachEntry(new TObjectIntProcedure<Cell>() {

@Override
public boolean execute(Cell cell, int count) {
reporter.info(new TransformationMessageImpl(cell,
MessageFormat.format("Created {0} instances during transformation", count),
null));
instanceCounter.forEachKeyValue((ObjectIntProcedure<Cell>) (cell, count) -> {
reporter.info(new TransformationMessageImpl(cell,
MessageFormat.format("Created {0} instances during transformation", count),
null));

// also store as statistics
reporter.stats().at("createdPerCell").at(cell.getId()).set(count);

return true;
}
// also store as statistics
reporter.stats().at("createdPerCell").at(cell.getId()).set(count);
});
}

Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ deegree = "3.5.8"
jackson = "2.18.0"
poi = "5.3.0"
protobuf = "4.28.2"
eclipse-collections = "11.1.0"

[libraries]
# TODO add project builds?
Expand Down Expand Up @@ -128,7 +129,8 @@ joda-time = {module = "joda-time:joda-time", version = "2.13.0"}

jmep = {module = "com.iabcinc:jmep", version = "0.1.0"}

trove = {module = "net.sf.trove4j:trove4j", version = "2.1.0"}
eclipse-collections-api = {module = "org.eclipse.collections:eclipse-collections-api", version.ref = "eclipse-collections"}
eclipse-collections-core = {module = "org.eclipse.collections:eclipse-collections", version.ref = "eclipse-collections"}

jakarta-xml-bind-api = {module = "jakarta.xml.bind:jakarta.xml.bind-api", version = "4.0.2"}

Expand Down
3 changes: 2 additions & 1 deletion io/plugins/eu.esdihumboldt.hale.io.gml/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ dependencies {

testRuntimeOnly libs.geotools.epsg

testImplementation libs.trove
testImplementation libs.eclipse.collections.api
testImplementation libs.eclipse.collections.core
testImplementation libs.apache.ws.xsd

testImplementation project(':common:plugins:eu.esdihumboldt.hale.common.test')
Expand Down
3 changes: 2 additions & 1 deletion io/plugins/eu.esdihumboldt.hale.io.xsd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ dependencies {
implementation libs.eclipse.core.runtime

implementation libs.guava
implementation libs.trove
implementation libs.eclipse.collections.api
implementation libs.eclipse.collections.core
implementation libs.commons.lang

implementation libs.findbugs.annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import org.apache.ws.commons.schema.XmlSchemaType;
import org.apache.ws.commons.schema.constants.Constants;
import org.apache.ws.commons.schema.utils.NamespacePrefixList;
import org.eclipse.collections.api.factory.primitive.ObjectIntMaps;
import org.eclipse.collections.api.map.primitive.MutableObjectIntMap;
import org.w3c.dom.Node;

import com.google.common.base.Objects;
Expand Down Expand Up @@ -133,7 +135,6 @@
import eu.esdihumboldt.util.Identifiers;
import eu.esdihumboldt.util.io.InputSupplier;
import eu.esdihumboldt.util.resource.Resources;
import gnu.trove.TObjectIntHashMap;

/**
* The main functionality of this class is to load an XML schema file (XSD) and
Expand Down Expand Up @@ -247,7 +248,7 @@ public void addIdentifiers(Map<String, String> objectsAndIdentifiers) {
* Holds the number of created groups for a parent. The parent identifier is
* mapped to the number of groups.
*/
private TObjectIntHashMap<String> groupCounter;
private MutableObjectIntMap<String> groupCounter;

/**
* The current reporter
Expand Down Expand Up @@ -352,7 +353,7 @@ else if (location.getScheme().equals("bundleresource")) { //$NON-NLS-1$
index = new XmlIndex(namespace, location);

// create group counter
groupCounter = new TObjectIntHashMap<String>();
groupCounter = ObjectIntMaps.mutable.of();

// Map schema locations to target namespaces
Map<String, String> imports = new HashMap<>();
Expand Down

0 comments on commit 2f2c916

Please sign in to comment.