Skip to content

Commit

Permalink
Merge pull request #386 from apache/refactoring/379-Clean-up-code
Browse files Browse the repository at this point in the history
Issue #379: Clean up code
  • Loading branch information
reckart authored Sep 16, 2024
2 parents 5fc9ec9 + 2cb2faf commit f3ced30
Show file tree
Hide file tree
Showing 34 changed files with 151 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private static boolean b64validDigit(byte a) {
}

private static void b64encodeOctet(byte[] to, int to_offset, byte[] from, int from_offset,
int count) {
int count) {
int A = 0;
int B = 0;
int C = 0;
Expand Down
70 changes: 5 additions & 65 deletions uimaj-core/src/main/java/org/apache/uima/List_of_ints.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,24 @@

/**
* a List API that returns ints instead of T
*
* @deprecated To become package private in {@code org.apache.uima.jcas.cas} or possibly removed.
* Should also be renamed.
* @forRemoval 4.0.0
*/
@Deprecated(since = "3.6.0")
public interface List_of_ints extends Iterable<Integer> {

/*
* (non-Javadoc)
*
* @see java.util.List#size()
*/
int size();

/*
* (non-Javadoc)
*
* @see java.util.List#isEmpty()
*/
default boolean isEmpty() {
return size() == 0;
};

/*
* (non-Javadoc)
*
* @see java.util.List#contains(java.lang.Object)
*/
default boolean contains(int i) {
return indexOf(i) != -1;
}

/*
* (non-Javadoc)
*
* @see java.util.List#toArray()
*/
int[] toArray();

/**
Expand All @@ -69,67 +54,22 @@ default boolean contains(int i) {
*/
int[] toArrayMinCopy();

/*
* (non-Javadoc)
*
* @see java.util.List#add(java.lang.Object)
*/
boolean add(int i);

/*
* (non-Javadoc)
*
* @see java.util.List#remove(java.lang.Object)
*/
boolean remove(int i);

/*
* (non-Javadoc)
*
* @see java.util.List#clear()
*/
void clear();

/*
* (non-Javadoc)
*
* @see java.util.List#get(int)
*/
int get(int index);

/*
* (non-Javadoc)
*
* @see java.util.List#set(int, java.lang.Object)
*/
int set(int index, int element);

/*
* (non-Javadoc)
*
* @see java.util.List#add(int, java.lang.Object)
*/
void add(int index, int element);

/*
* (non-Javadoc)
*
* @see java.util.List#remove(int)
*/
int removeAtIndex(int index);

/*
* (non-Javadoc)
*
* @see java.util.List#indexOf(java.lang.Object)
*/
int indexOf(int i);

/*
* (non-Javadoc)
*
* @see java.util.List#lastIndexOf(java.lang.Object)
*/
int lastIndexOf(int i);

List_of_ints subList(int fromIndex, int toIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class LLUnambiguousIteratorImpl<T extends FeatureStructure>
extends FsIterator_subtypes_snapshot<T> {

public LLUnambiguousIteratorImpl(LowLevelIterator<T> it) {
super((T[]) createItemsArray((LowLevelIterator<FeatureStructure>) it), it.ll_getIndex(),
IS_ORDERED, it.getComparator());
super((T[]) createItemsArray((LowLevelIterator<FeatureStructure>) it),
(LowLevelIndex<T>) it.ll_getIndex(), IS_ORDERED, it.getComparator());
}

// this is static because can't have instance method call before super call in constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ void testSetUsesType() throws Exception {
// values
FeatureStructure testprobe2 = createFs(type1, 1, 1);

assertThat(sortedType1.size()).isEqualTo(2);
assertThat(setType1.size()).isEqualTo(2);
assertThat(sortedType1).hasSize(2);
assertThat(setType1).hasSize(2);

FSIterator<FeatureStructure> it = setType1.iterator();
it.moveTo(testprobe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ void setUp() throws Exception {
.parseTypeSystemDescription(new XMLInputSource(typeSystemFile));
}

@AfterEach
void tearDown() throws Exception {
if ((outputFile != null) && outputFile.exists()) {
outputFile.delete();
}
}

@Test
void testInvalidCharsInDocumentText() throws Exception {
CAS cas = CasCreationUtils.createCas(typeSystemDesc, null, null);
Expand Down Expand Up @@ -138,16 +145,4 @@ void testInvalidCharsInFeatureValue() throws Exception {
}
}
}

/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#tearDown()
*/
@AfterEach
public void tearDown() throws Exception {
if ((outputFile != null) && outputFile.exists()) {
outputFile.delete();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class GetAllIndexedTest {
public void setUp() throws Exception {
File descriptorFile = JUnitExtension
.getFile("CASTests/desc/typePriorityTestCaseDescriptor.xml");
assertThat(descriptorFile.exists())
.as("Descriptor must exist: " + descriptorFile.getAbsolutePath()).isTrue();
assertThat(descriptorFile).as("Descriptor must exist: " + descriptorFile.getAbsolutePath())
.exists();

XMLParser parser = UIMAFramework.getXMLParser();
ResourceSpecifier spec = (ResourceSpecifier) parser.parse(new XMLInputSource(descriptorFile));
Expand All @@ -109,7 +109,7 @@ public void setUp() throws Exception {
}

@AfterEach
public void tearDown() {
void tearDown() {
cas = null;
// this.tokenType = null;
// this.sentenceType = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class GrowingTheCasNoJcasCacheTest {
@BeforeEach
void setUp() throws Exception {
File descriptorFile = JUnitExtension.getFile("CASTests/desc/TokensAndSentences.xml");
assertThat(descriptorFile.exists())
.as("Descriptor must exist: " + descriptorFile.getAbsolutePath()).isTrue();
assertThat(descriptorFile).as("Descriptor must exist: " + descriptorFile.getAbsolutePath())
.exists();

XMLParser parser = UIMAFramework.getXMLParser();
ResourceSpecifier spec = parser.parseResourceSpecifier(new XMLInputSource(descriptorFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;

import org.apache.uima.UIMAFramework;
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.metadata.FsIndexCollection;
import org.apache.uima.resource.metadata.FsIndexDescription;
import org.apache.uima.resource.metadata.Import;
import org.apache.uima.test.junit_extension.JUnitExtension;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLInputSource;
Expand All @@ -48,37 +42,31 @@ void tearDown() throws Exception {

@Test
void testBuildFromXmlElement() throws Exception {
try {
File descriptor = JUnitExtension
.getFile("FsIndexCollectionImplTest/TestFsIndexCollection.xml");
FsIndexCollection indexColl = UIMAFramework.getXMLParser()
.parseFsIndexCollection(new XMLInputSource(descriptor));
var descriptor = JUnitExtension.getFile("FsIndexCollectionImplTest/TestFsIndexCollection.xml");
var indexColl = UIMAFramework.getXMLParser()
.parseFsIndexCollection(new XMLInputSource(descriptor));

assertThat(indexColl.getName()).isEqualTo("TestFsIndexCollection");
assertThat(indexColl.getDescription()).isEqualTo("This is a test.");
assertThat(indexColl.getVendor()).isEqualTo("The Apache Software Foundation");
assertThat(indexColl.getVersion()).isEqualTo("0.1");
Import[] imports = indexColl.getImports();
assertThat(imports).hasSize(2);
assertThat(imports[0].getName()).isEqualTo("FsIndexCollectionImportedFromDataPath");
assertThat(imports[0].getLocation()).isNull();
assertThat(imports[1].getName()).isNull();
assertThat(imports[1].getLocation()).isEqualTo("FsIndexCollectionImportedByLocation.xml");
assertThat(indexColl.getName()).isEqualTo("TestFsIndexCollection");
assertThat(indexColl.getDescription()).isEqualTo("This is a test.");
assertThat(indexColl.getVendor()).isEqualTo("The Apache Software Foundation");
assertThat(indexColl.getVersion()).isEqualTo("0.1");
var imports = indexColl.getImports();
assertThat(imports).hasSize(2);
assertThat(imports[0].getName()).isEqualTo("FsIndexCollectionImportedFromDataPath");
assertThat(imports[0].getLocation()).isNull();
assertThat(imports[1].getName()).isNull();
assertThat(imports[1].getLocation()).isEqualTo("FsIndexCollectionImportedByLocation.xml");

FsIndexDescription[] indexes = indexColl.getFsIndexes();
assertThat(indexes).hasSize(2);
} catch (Exception e) {
JUnitExtension.handleException(e);
}
var indexes = indexColl.getFsIndexes();
assertThat(indexes).hasSize(2);
}

@Test
void testResolveImports() throws Exception {
File descriptor = JUnitExtension.getFile("FsIndexCollectionImplTest/TestFsIndexCollection.xml");
FsIndexCollection ic = UIMAFramework.getXMLParser()
.parseFsIndexCollection(new XMLInputSource(descriptor));
var descriptor = JUnitExtension.getFile("FsIndexCollectionImplTest/TestFsIndexCollection.xml");
var ic = UIMAFramework.getXMLParser().parseFsIndexCollection(new XMLInputSource(descriptor));

FsIndexDescription[] indexes = ic.getFsIndexes();
var indexes = ic.getFsIndexes();
assertThat(indexes).hasSize(2);

// resolving imports without setting data path should fail
Expand All @@ -93,7 +81,7 @@ void testResolveImports() throws Exception {
// thrown

// set data path correctly and it should work
ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
var resMgr = UIMAFramework.newDefaultResourceManager();
resMgr.setDataPathElements(
JUnitExtension.getFile("FsIndexCollectionImplTest/dataPathDir").getAbsoluteFile());
ic.resolveImports(resMgr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void tearDown() throws Exception {
if (oldHoldOntoFss != null) {
System.setProperty(CASImpl.ALWAYS_HOLD_ONTO_FSS, oldHoldOntoFss);
} else {
System.getProperties().remove(CASImpl.ALWAYS_HOLD_ONTO_FSS);
System.clearProperty(CASImpl.ALWAYS_HOLD_ONTO_FSS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.uima.util.Logger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -123,9 +124,9 @@ void thatTwoParametersAndThrowableAreLogged() throws Exception {

assertThat(capture.getAndClearLatestEvents()) //
.extracting( //
logEvent1 -> logEvent1.getLevel(), //
LogEvent::getLevel, //
e -> e.getMessage().getFormattedMessage(), //
logEvent -> logEvent.getThrown()) //
LogEvent::getThrown) //
.containsExactly( //
tuple(Level.TRACE, "1 2", ex), //
tuple(Level.DEBUG, "1 2", ex), //
Expand All @@ -146,9 +147,9 @@ void thatThreeParametersAndThrowableAreLogged() throws Exception {

assertThat(capture.getAndClearLatestEvents()) //
.extracting( //
logEvent1 -> logEvent1.getLevel(), //
LogEvent::getLevel, //
e -> e.getMessage().getFormattedMessage(), //
logEvent -> logEvent.getThrown()) //
LogEvent::getThrown) //
.containsExactly( //
tuple(Level.TRACE, "1 2 3", ex), //
tuple(Level.DEBUG, "1 2 3", ex), //
Expand Down Expand Up @@ -177,7 +178,7 @@ void thatMultipleParametersAndThrowableAreLogged() throws Exception {
assertThat(capture.getAndClearLatestEvents()) //
.extracting( //
e -> e.getMessage().getFormattedMessage(), //
logEvent -> logEvent.getThrown()) //
LogEvent::getThrown) //
.containsExactly( //
tuple(String.join(" ", values), ex));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ public void run() {
// while the CPM is in normal shutdown state.
// (Moved this code inside if (casObjectList != null)
// block to avoid NullPointerException. -Adam
if (cpm.isRunning()
|| (!cpm.isRunning() && !cpm.isHardKilled())) {
if (cpm.isRunning() || (!cpm.isRunning() && !cpm.isHardKilled())) {
threadState = 1005; // Entering enqueue
workQueue.enqueue(casObjectList);
// synchronized (workQueue) { // redundant, enqueue does this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ private void postAnalysis(Object[] aCasObjectList, boolean isCasObject, Object[]
}
}
// enqueue CASes. If the CPM is in shutdown mode due to hard kill dont allow enqueue of CASes
if (outputQueue != null && (cpm.isRunning()
|| (!cpm.isRunning() && !cpm.isHardKilled()))) {
if (outputQueue != null && (cpm.isRunning() || (!cpm.isRunning() && !cpm.isHardKilled()))) {
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_add_cas_to_queue__FINEST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,7 @@ private void postAnalysis(Object[] aCasObjectList, boolean isCasObject, Object[]
maybeLogFinest("UIMA_CPM_done_notify_listeners__FINEST");
}
// enqueue CASes. If the CPM is in shutdown mode due to hard kill dont allow enqueue of CASes
if (outputQueue != null && (cpm.isRunning()
|| (!cpm.isRunning() && !cpm.isHardKilled()))) {
if (outputQueue != null && (cpm.isRunning() || (!cpm.isRunning() && !cpm.isHardKilled()))) {
maybeLogFinestWorkQueue("UIMA_CPM_add_cas_to_queue__FINEST", outputQueue);
WorkUnit workUnit = new WorkUnit(aCasObjectList);
if (casCache != null && casCache[0] != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/
/**
* <p>This package contains the wizards classes.</p>
* <p>
* This package contains the wizards classes.
* </p>
*/
package org.apache.uima.caseditor.ide.wizards;
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,7 @@ public String getTitleToolTip() {
* @return an adapter or null
*/
@Override
public Object getAdapter(@SuppressWarnings("rawtypes")
Class adapter) {
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {

if (IContentOutlinePage.class.equals(adapter) && getDocument() != null) {
return mOutlinePage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ public Object get() {
}

@Override
public Object getAdapter(@SuppressWarnings("rawtypes")
Class adapter) {
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {

if (FeatureStructure.class.equals(adapter)) {
if (arrayFS instanceof ArrayFS) {
Expand Down
Loading

0 comments on commit f3ced30

Please sign in to comment.