Skip to content

Commit

Permalink
Issue #379: Clean up code
Browse files Browse the repository at this point in the history
- Clean up
  • Loading branch information
reckart committed Sep 4, 2024
1 parent 1994048 commit 90d2dee
Show file tree
Hide file tree
Showing 33 changed files with 150 additions and 158 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
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 All @@ -562,10 +562,9 @@ void testSetUsesType() throws Exception {
// note: this test is here because the setup is done
@Test
void testProtectIndex() throws Exception {
var fs = sortedType1.iterator().get();

var oldIsReportFsUpdatesCorrputs = CASImpl.IS_REPORT_FS_UPDATE_CORRUPTS_INDEX;
var oldIsThrowExceptionCorruptIndes = CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX;
FSIterator<FeatureStructure> it = sortedType1.iterator();
FeatureStructure fs = it.get();
boolean ok = false;
try {
CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX = true;
CASImpl.IS_REPORT_FS_UPDATE_CORRUPTS_INDEX = true;
Expand All @@ -575,5 +574,6 @@ void testProtectIndex() throws Exception {
CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX = oldIsThrowExceptionCorruptIndes;
CASImpl.IS_REPORT_FS_UPDATE_CORRUPTS_INDEX = oldIsReportFsUpdatesCorrputs;
}
assertThat(CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX ? ok : !ok).isTrue();
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public Object getValue() {
}

@Override
public Object getAdapter(@SuppressWarnings("rawtypes")
Class adapter) {
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
if (AnnotationFS.class.equals(adapter)) {
if (getValue() instanceof AnnotationFS) {
return getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public static List<ModelFeatureStructure> create(ICasDocument document,
}

@Override
public Object getAdapter(@SuppressWarnings("rawtypes")
Class adapter) {
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
if (FeatureStructure.class.equals(adapter)) {
return getStructre();
} else if (AnnotationFS.class.equals(adapter) && getStructre() instanceof AnnotationFS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,17 @@ public SubPageSite(IPageSite site) {
}

@Override
public boolean hasService(@SuppressWarnings("rawtypes")
Class api) {
public boolean hasService(@SuppressWarnings("rawtypes") Class api) {
return site.hasService(api);
}

@Override
public Object getService(@SuppressWarnings("rawtypes")
Class api) {
public Object getService(@SuppressWarnings("rawtypes") Class api) {
return site.getService(api);
}

@Override
public Object getAdapter(@SuppressWarnings("rawtypes")
Class adapter) {
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
return site.getAdapter(adapter);
}

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 feature structure view classes.</p>
* <p>
* This package contains the feature structure view classes.
* </p>
*/
package org.apache.uima.caseditor.editor.fsview;
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void addChild(AnnotationTreeNode node) {
}

@Override
public Object getAdapter(@SuppressWarnings("rawtypes")
Class adapter) {
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
// TODO:
// use ModelFeatureStructure
// create a AdapterFactory which just calls the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public void remove(AnnotationTreeNode annotation) {
}

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

if (Type.class.equals(adapter)) {
return type;
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 outline classes.</p>
* <p>
* This package contains the outline classes.
* </p>
*/
package org.apache.uima.caseditor.editor.outline;
Loading

0 comments on commit 90d2dee

Please sign in to comment.