Skip to content

Commit

Permalink
Issue #379: Clean up code
Browse files Browse the repository at this point in the history
- Clean up
- Auto-format
  • Loading branch information
reckart committed Aug 30, 2024
1 parent b746af2 commit 78462fb
Show file tree
Hide file tree
Showing 88 changed files with 1,089 additions and 1,388 deletions.
6 changes: 4 additions & 2 deletions uimaj-core/src/main/java/org/apache/uima/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public abstract class Constants {
*
* @deprecated SOAP protocol is no longer supported since UIMA v3.3.0. Constant to be removed in
* UIMAv4.
* @forRemoval 4.0.0
*/
@Deprecated
@Deprecated(since = "3.3.0")
public static final String PROTOCOL_SOAP = "SOAP";

/**
Expand All @@ -37,8 +38,9 @@ public abstract class Constants {
*
* @deprecated SOAP protocol is no longer supported since UIMA v3.3.0. Constant to be removed in
* UIMAv4.
* @forRemoval 4.0.0
*/
@Deprecated
@Deprecated(since = "3.3.0")
public static final String PROTOCOL_SOAP_WITH_ATTACHMENTS = "SOAPwithAttachments";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ private CAS processUntilNextOutputCas() throws AnalysisEngineProcessException {
// repeat until we reach a FinalStep
while (!(nextStep instanceof FinalStep)) {
// Simple Step
if (nextStep instanceof SimpleStep) {
String nextAeKey = ((SimpleStep) nextStep).getAnalysisEngineKey();
if (nextStep instanceof SimpleStep simpleStep) {
String nextAeKey = simpleStep.getAnalysisEngineKey();
AnalysisEngine nextAe = mComponentAnalysisEngineMap.get(nextAeKey);
if (nextAe != null) {
// check if we have to set result spec, to support capability language flow
Expand Down Expand Up @@ -717,8 +717,8 @@ else if (nextStep instanceof ParallelStep) {
flow.aborted();
}
release(); // release held CASes before throwing exception
if (e instanceof AnalysisEngineProcessException) {
throw (AnalysisEngineProcessException) e;
if (e instanceof AnalysisEngineProcessException analysisEngineProcessException) {
throw analysisEngineProcessException;
} else {
throw new AnalysisEngineProcessException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ protected void buildProcessTraceFromMBeanStats(ProcessTrace trace) {
Iterator<AnalysisEngine> aeIter = _getASB().getComponentAnalysisEngines().values().iterator();
while (aeIter.hasNext()) {
AnalysisEngine ae = aeIter.next();
if (ae instanceof AnalysisEngineImplBase) {
ProcessTrace subPT = ((AnalysisEngineImplBase) ae).buildProcessTraceFromMBeanStats();
if (subPT.getEvents().size() > 0) {
if (ae instanceof AnalysisEngineImplBase analysisEngineImplBase) {
ProcessTrace subPT = analysisEngineImplBase.buildProcessTraceFromMBeanStats();
if (!subPT.getEvents().isEmpty()) {
procEvt.addSubEvent(subPT.getEvents().get(0));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,17 +861,15 @@ protected synchronized void resolveDelegateAnalysisEngineImports(
.entrySet()) {
String key = entry.getKey();
keys.add(key);
if (entry.getValue() instanceof Import) {
Import aeImport = ((Import) entry.getValue());
if (entry.getValue() instanceof Import aeImport) {
// see if we processed this already
if (entry.getValue().equals(mProcessedImports.get(key))) {
continue;
}
// make sure Import's relative path base is set, to allow for
// users who create
// new import objects
if (aeImport instanceof Import_impl) {
((Import_impl) aeImport).setSourceUrlIfNull(getSourceUrl());
// users who create new import objects
if (aeImport instanceof Import_impl importImpl) {
importImpl.setSourceUrlIfNull(getSourceUrl());
}
// locate import target
URL url = aeImport.findAbsoluteUrl(aResourceManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ protected void callInitializeMethod(AnalysisComponent component, UimaContext con
try {
withContexts(component, context, null, () -> component.initialize(context));
} catch (Exception e) {
throw (e instanceof ResourceInitializationException) ? ((ResourceInitializationException) e)
throw e instanceof ResourceInitializationException resourceInitializationException //
? resourceInitializationException //
: new ResourceInitializationException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public void initialize(UimaContext aContext) throws ResourceInitializationExcept
public void checkTypeSystemChange(AbstractCas aCAS) throws AnalysisEngineProcessException {
try {
TypeSystem typeSystem;
if (aCAS instanceof JCas) {
typeSystem = ((JCas) aCAS).getTypeSystem();
if (aCAS instanceof JCas jCas) {
typeSystem = jCas.getTypeSystem();
} else // CAS
{
typeSystem = ((CAS) aCAS).getTypeSystem();
Expand Down Expand Up @@ -184,9 +184,7 @@ public void reconfigure() throws ResourceInitializationException, ResourceConfig
public boolean hasNext() throws AnalysisEngineProcessException {
try {
return mCollectionReader.hasNext();
} catch (CollectionException e) {
throw new AnalysisEngineProcessException(e);
} catch (IOException e) {
} catch (CollectionException | IOException e) {
throw new AnalysisEngineProcessException(e);
}
}
Expand All @@ -213,9 +211,7 @@ public AbstractCas next() throws AnalysisEngineProcessException {

try {
mCollectionReader.getNext(view);
} catch (CollectionException e) {
throw new AnalysisEngineProcessException(e);
} catch (IOException e) {
} catch (CollectionException | IOException e) {
throw new AnalysisEngineProcessException(e);
}
return cas;
Expand Down
1 change: 1 addition & 0 deletions uimaj-core/src/main/java/org/apache/uima/cas/CAS.java
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ <T extends FeatureStructure> FSIterator<T> createFilteredIterator(FSIterator<T>
* @deprecated Use {@link #createFeaturePath()} instead.
* @forRemoval 4.0.0
*/
@Deprecated(since = "3.6.0")
FeatureValuePath createFeatureValuePath(String featureValuePath) throws CASRuntimeException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void reinit(int[] heapMetadata, int[] heapArray, String[] stringTable, int[] fsI

createFSsFromHeaps(false, 1, csds); // false means not delta

reinitIndexedFSs(fsIndex, false, i -> csds.addr2fs.get(i));
reinitIndexedFSs(fsIndex, false, csds.addr2fs::get);
}

public CASImpl setupCasFromCasMgrSerializer(CASMgrSerializer casMgrSerializer) {
Expand Down Expand Up @@ -880,8 +880,8 @@ private SerialFormat binaryDeserialization(Header h) {

// modified Byte Heap
heapsz = updateAuxArrayMods(r, byteAuxAddr2fsa, (ba, arrayIndex) -> {
if (ba instanceof ByteArray) {
((ByteArray) ba).set(arrayIndex, dis.readByte());
if (ba instanceof ByteArray byteArray) {
byteArray.set(arrayIndex, dis.readByte());
} else {
((BooleanArray) ba).set(arrayIndex, dis.readByte() == 1);
}
Expand All @@ -903,8 +903,8 @@ private SerialFormat binaryDeserialization(Header h) {

// modified Long Heap
updateAuxArrayMods(r, longAuxAddr2fsa, (la, arrayIndex) -> {
if (la instanceof LongArray) {
((LongArray) la).set(arrayIndex, r.readLong());
if (la instanceof LongArray longArray) {
longArray.set(arrayIndex, r.readLong());
} else {
((DoubleArray) la).set(arrayIndex, CASImpl.long2double(r.readLong()));
}
Expand Down Expand Up @@ -957,7 +957,7 @@ private SerialFormat binaryDeserialization(Header h) {
}

// update the indexes
IntFunction<TOP> getFsFromAddr = i -> csds.addr2fs.get(i);
IntFunction<TOP> getFsFromAddr = csds.addr2fs::get;
reinitIndexedFSs(fsindexes, delta, getFsFromAddr);

if (!delta) {
Expand Down Expand Up @@ -1155,7 +1155,7 @@ void reinitIndexedFSs(int[] fsIndex, boolean isDeltaMods, IntFunction<TOP> getFs
// next line the getView as a side effect
// checks for dupl sofa name, and if not,
// adds the name to the sofaNameSet
((CASImpl) baseCas.getView(sofa)).registerView(sofa);
baseCas.getView(sofa).registerView(sofa);
});

baseCas.getInitialView(); // done for side effect of creating the initial view if not present
Expand Down Expand Up @@ -1579,8 +1579,8 @@ private void extractFsToV2Heaps(TOP fs, boolean isMarkSet, Obj2IntIdentityHashMa
Misc.internalError();
} // end of switch
} else { // end of is-array
if (fs instanceof UimaSerializable) {
((UimaSerializable) fs)._save_to_cas_data();
if (fs instanceof UimaSerializable uimaSerializable) {
uimaSerializable._save_to_cas_data();
}
int i = pos + 1;
for (FeatureImpl feat : type.getFeatureImpls()) {
Expand Down Expand Up @@ -1789,9 +1789,8 @@ private void createFSsFromHeaps(boolean isDelta, int startPos, CommonSerDesSeque
}
} else {
fs = view.createFS(type);
if (fs instanceof UimaSerializable) {
final UimaSerializable ufs = (UimaSerializable) fs;
fixups4UimaSerialization.add(() -> ufs._init_from_cas_data());
if (fs instanceof UimaSerializable ufs) {
fixups4UimaSerialization.add(ufs::_init_from_cas_data);
}
}
} else if (type == tsi.sofaType) {
Expand All @@ -1805,9 +1804,8 @@ private void createFSsFromHeaps(boolean isDelta, int startPos, CommonSerDesSeque
isSofa = true;
} else {
fs = initialView.createFS(type);
if (fs instanceof UimaSerializable) {
final UimaSerializable ufs = (UimaSerializable) fs;
fixups4UimaSerialization.add(() -> ufs._init_from_cas_data());
if (fs instanceof UimaSerializable ufs) {
fixups4UimaSerialization.add(ufs::_init_from_cas_data);
}
}
if (!isSofa) { // if it was a sofa, other code added or pended it
Expand Down Expand Up @@ -2019,11 +2017,11 @@ private boolean updateStringFeature(TOP fs, FeatureImpl feat, String s,
if (null == s) {
return false; // null is the default value, no need to set it
}
if (fs instanceof Sofa) {
if (fs instanceof Sofa sofa) {
if (feat == tsi.sofaId) {
return false; // do nothing, this value was already used
}
Sofa sofa = (Sofa) fs;

if (feat == tsi.sofaMime) {
sofa.setMimeType(s);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class BinaryCasSerDes4 implements SlotKindsConstants {
// may add more later - to specify differing trade-offs between speed and compression
public enum Compression {
None, Compress
};
}

public static final boolean IS_DIFF_ENCODE = true;
public static final boolean CAN_BE_NEGATIVE = true;
Expand Down Expand Up @@ -1808,7 +1808,7 @@ private void deserialize(CommonSerDes.Header h) throws IOException {
arraySize = ((CommonArrayFS<?>) currentFs).size();
} else {
if (!ts.annotBaseType.subsumes(type) && // defer subtypes of AnnotationBase
!(ts.sofaType == type)) { // defer sofa types
ts.sofaType != type) { // defer sofa types
createCurrentFs(type, ivCas);
} else {
currentFs = null;
Expand Down Expand Up @@ -1977,7 +1977,6 @@ private TOP readArray(int iHeap, TypeImpl type) throws IOException {

case Slot_DoubleRef:
readIntoDoubleArray(((DoubleArray) fs)._getTheArray());
;
break;

case Slot_HeapRef: {
Expand Down Expand Up @@ -2141,7 +2140,7 @@ private void readIndexedFeatureStructures() throws IOException {
}
}

bcsd.reinitIndexedFSs(fsIndexes.getArray(), isDelta, i -> seq2fs.get(i),
bcsd.reinitIndexedFSs(fsIndexes.getArray(), isDelta, seq2fs::get,
// written on separate line for Eclipse breakpoint control
i -> csds.addr2fs.get(i) // https://issues.apache.org/jira/browse/UIMA-5593
);
Expand Down
Loading

0 comments on commit 78462fb

Please sign in to comment.