Skip to content

Commit

Permalink
refactor: get rid of Guava
Browse files Browse the repository at this point in the history
  • Loading branch information
berezovskyi committed Dec 18, 2024
1 parent f568b95 commit b6e1307
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 81 deletions.
4 changes: 0 additions & 4 deletions core/lyo-core-settings/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@
<artifactId>jersey-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import com.google.common.base.Strings;
import org.apache.jena.datatypes.DatatypeFormatException;
import org.apache.jena.datatypes.RDFDatatype;
import org.apache.jena.datatypes.TypeMapper;
Expand Down Expand Up @@ -550,7 +549,7 @@ private static Boolean parseBooleanPropertyOrDefault(final String key,
final boolean defaultValue) {
Boolean value;
final String property = System.getProperty(key);
if (Strings.isNullOrEmpty(property)) {
if (StringUtils.isNullOrEmpty(property)) {
value = defaultValue;
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.eclipse.lyo.oslc4j.core;

import java.util.regex.Pattern;

public class StringUtils {
private static final Pattern CONTROL_CHAR_PATTERN = Pattern.compile("^\\p{Cc}&&[^\\r\\n\\t]+$");

/**
* Trim and strip control chars
*/
public static String clean(String str) {
if (str == null) return null;

return CONTROL_CHAR_PATTERN.matcher(str).replaceAll("").trim();
}

/**
* Trim and strip control chars; return an empty string if a null is encountered
*/
public static String cleanNonNull(String str) {
if (str == null) return "";

return CONTROL_CHAR_PATTERN.matcher(str).replaceAll("").trim();
}

public static boolean isNullOrWhitespace(String str) {
return str == null || str.isBlank();
}


public static boolean isNullOrEmpty(String str) {
return str == null || str.isEmpty();
}
}
5 changes: 0 additions & 5 deletions core/oslc4j-jena-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@
<version>${v.jersey}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.List;
import javax.xml.datatype.DatatypeConfigurationException;

import com.google.common.collect.ImmutableList;
import org.apache.jena.datatypes.DatatypeFormatException;
import org.apache.jena.rdf.model.Model;
import org.eclipse.lyo.oslc4j.core.exception.LyoModelException;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void testSeqMarshalling()
final Model expectedModel = RDFHelper.loadResourceModel("container-element.ttl");
final Container container = new Container();
container.setAbout(URI.create("urn:containerA"));
final ImmutableList<Element> children = ImmutableList.of(element("A"), element("B"));
final List<Element> children = List.of(element("A"), element("B"));
container.setChildrenL(children);
container.setChildrenB(children);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.common.collect.ImmutableList;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
import org.eclipse.lyo.oslc4j.core.model.ServiceProvider;
import org.eclipse.lyo.oslc4j.provider.jena.OslcJsonLdArrayProvider;
Expand Down Expand Up @@ -72,7 +73,7 @@ public void testWrite() throws Exception {
.getAnnotations(), OslcMediaType.APPLICATION_JSON_LD_TYPE, new
MultivaluedHashMap<>(), outputStream);

final String jsonLD = outputStream.toString("UTF-8");
final String jsonLD = outputStream.toString(StandardCharsets.UTF_8);

assertTrue("Provider was not read", jsonLD.contains("Hello world"));

Expand All @@ -94,7 +95,7 @@ public void testWriteArray() throws Exception {
new MultivaluedHashMap<>(),
outputStream);

final String jsonLD = outputStream.toString("UTF-8");
final String jsonLD = outputStream.toString(StandardCharsets.UTF_8);

assertTrue("Provider was not read", jsonLD.contains("Hello world"));
}
Expand All @@ -107,7 +108,7 @@ public void testWriteCollection() throws Exception {

ServiceProvider sp = new ServiceProvider();
sp.setDescription("Hello world");
final Collection<ServiceProvider> objects = ImmutableList.of(sp);
final Collection<ServiceProvider> objects = List.of(sp);
provider.writeTo(
new ArrayList<>(objects),
objects.getClass(),
Expand All @@ -117,7 +118,7 @@ public void testWriteCollection() throws Exception {
new MultivaluedHashMap<>(),
outputStream);

final String jsonLD = outputStream.toString("UTF-8");
final String jsonLD = outputStream.toString(StandardCharsets.UTF_8);

assertTrue("Provider was not read", jsonLD.contains("Hello world"));
}
Expand Down
4 changes: 0 additions & 4 deletions core/shacl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<artifactId>oslc4j-jena-provider</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 1 addition & 4 deletions core/shacl/src/main/java/org/eclipse/lyo/shacl/Shape.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package org.eclipse.lyo.shacl;

import com.google.common.collect.ImmutableList;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
Expand All @@ -26,7 +25,6 @@

/**
* @author Yash Khatri
* @version $version-stub$
* @since 2.3.0
*/
@OslcNamespace(ShaclConstants.SHACL_CORE_NAMESPACE)
Expand Down Expand Up @@ -133,8 +131,7 @@ public void setTargetObjectsOf(final URI targetObjectsOf) {
@OslcTitle("Properties")
@OslcValueType(ValueType.LocalResource)
public List<Property> getShaclProperties() {
return ImmutableList.copyOf(
properties.values().toArray(new Property[properties.size()]));
return List.of(properties.values().toArray(new Property[0]));
}

public void setShaclProperties(final List<Property> properties) {
Expand Down
8 changes: 0 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<v.jackson>2.18.2</v.jackson>
<v.httpclient>4.5.14</v.httpclient>
<v.slf4j>2.0.16</v.slf4j>

<v.guava>33.3.1-jre</v.guava>
</properties>


Expand Down Expand Up @@ -393,11 +391,6 @@
<artifactId>commons-codec</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${v.guava}</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
Expand Down Expand Up @@ -476,7 +469,6 @@
<link>https://jakarta.ee/specifications/platform/9/apidocs/</link>
<link>https://jena.apache.org/documentation/javadoc/jena/</link>
<link>https://jena.apache.org/documentation/javadoc/arq/</link>
<link>https://guava.dev/releases/${v.guava}/api/docs/</link>
</links>
</configuration>
<executions>
Expand Down
4 changes: 0 additions & 4 deletions store/store-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<!-- Test -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -34,8 +36,6 @@
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

import com.google.common.base.Stopwatch;

public class SparqlStoreImplTest extends StoreTestBase<SparqlStoreImpl> {

private Store manager;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void storeBasicOps() {
@Test
public void testInsertionPerf() {
final List<ServiceProvider> providers = genProviders();
final Stopwatch stopwatch = Stopwatch.createStarted();
var start = Instant.now();
for (int i = 0; i < 10; i++) {
final URI testNg = URI.create("urn:test:" + i);
try {
Expand All @@ -77,20 +77,20 @@ public void testInsertionPerf() {
fail("Store failed", e);
}
}
System.out.printf("10 named graphs persisted (resources) in %s ms", stopwatch.stop().elapsed().toMillis());
System.out.printf("10 named graphs persisted (resources) in %s ms", Duration.between(start, Instant.now()).toMillis());
}

@Test
public void testInsertionPerfRaw() throws InvocationTargetException, DatatypeConfigurationException,
OslcCoreApplicationException, IllegalAccessException {
final List<ServiceProvider> providers = genProviders();
final Model jenaModel = JenaModelHelper.createJenaModel(providers.toArray());
final Stopwatch stopwatch = Stopwatch.createStarted();
var start = Instant.now();
for (int i = 0; i < 10; i++) {
final URI testNg = URI.create("urn:test:" + i);
manager.insertJenaModel(testNg, jenaModel);
}
System.out.printf("10 named graphs persisted (raw Model) in %s ms", stopwatch.stop().elapsed().toMillis());
System.out.printf("10 named graphs persisted (raw Model) in %s ms", Duration.between(start, Instant.now()).toMillis());
}

private List<ServiceProvider> genProviders() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;


/**
* StoreTestBase allows same tests to be run on differently set up triplestores
Expand Down Expand Up @@ -143,7 +140,7 @@ public void testStoreSuccessiveAddCombines()
ServiceProviderCatalog.class);

Assertions.assertThat(catalogs).hasSize(2);
Assertions.assertThat(Lists.newArrayList(catalogs)
Assertions.assertThat(catalogs
.stream()
.map((serviceProviderCatalog) -> serviceProviderCatalog.getAbout().toASCIIString()))
.contains(resource.getAbout().toASCIIString(),
Expand Down Expand Up @@ -190,7 +187,7 @@ public void testSingleResourceRetrieved()
resource2.getAbout(), ServiceProviderCatalog.class);

Assertions.assertThat(resourceUnderKey).isNotNull();
Assertions.assertThat(resourceUnderKey.getAbout().equals(resource2.getAbout()));
Assertions.assertThat(resourceUnderKey.getAbout()).isEqualTo(resource2.getAbout());
}

@Test
Expand Down Expand Up @@ -228,7 +225,7 @@ public void testBlankNodeRetrieval()
final Store manager = buildStore();

final URI namedGraphUri = new URI("urn:test");
manager.putResources(namedGraphUri, ImmutableList.of(r1WithBlankResource));
manager.putResources(namedGraphUri, List.of(r1WithBlankResource));

final WithBlankResource resource = manager.getResource(
namedGraphUri,
Expand Down Expand Up @@ -259,7 +256,7 @@ public void testBlankNodeRetrievalDouble()
final Store manager = buildStore();

final URI namedGraphUri = new URI("urn:test");
manager.putResources(namedGraphUri, ImmutableList.of(aWithTwoDepthBlankResource));
manager.putResources(namedGraphUri, List.of(aWithTwoDepthBlankResource));

final WithTwoDepthBlankResource resource = manager.getResource(namedGraphUri,
blankResourceURI,
Expand Down
4 changes: 0 additions & 4 deletions trs/client/trs-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@
<artifactId>oslc-client</artifactId>
<version>${v.lyo}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-repository-sparql</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions trs/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,5 @@
<version>${v.slf4j}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import jakarta.inject.Inject;

import com.google.common.base.Strings;
import org.eclipse.lyo.core.trs.Base;
import org.eclipse.lyo.core.trs.ChangeLog;
import org.eclipse.lyo.core.trs.Page;
import org.eclipse.lyo.core.trs.TRSConstants;
import org.eclipse.lyo.core.trs.TrackedResourceSet;
import org.eclipse.lyo.oslc4j.core.OSLC4JUtils;
import org.eclipse.lyo.oslc4j.core.StringUtils;
import org.eclipse.lyo.oslc4j.core.annotation.OslcService;
import org.eclipse.lyo.oslc4j.core.model.Error;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
Expand Down Expand Up @@ -197,7 +197,7 @@ public Response getChangeLogPage(@PathParam("page") int page) {
}

private UriBuilder uriBuilder() {
if(Strings.isNullOrEmpty(base)) {
if(StringUtils.isNullOrEmpty(base)) {
return UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path(RESOURCE_PATH);
} else {
return UriBuilder.fromUri(base);
Expand Down
Loading

0 comments on commit b6e1307

Please sign in to comment.