Skip to content

Commit

Permalink
Created new class CastingUtils, and moved appropriate calls from Bean…
Browse files Browse the repository at this point in the history
…Utils to CastingUtils.

Additionally, small changes to some remaining functions in BeanUtils.
  • Loading branch information
CodeByDrescher committed Nov 8, 2023
1 parent 3c12cb2 commit 035dc9b
Show file tree
Hide file tree
Showing 33 changed files with 872 additions and 1,023 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
import java.util.Objects;
import java.util.Set;

import org.vcell.util.BeanUtils;
import org.vcell.util.Issue;
import org.vcell.util.*;
import org.vcell.util.Issue.IssueCategory;
import org.vcell.util.IssueContext;
import org.vcell.util.ProgrammingException;
import org.vcell.util.document.VCDocument;

import cbit.vcell.biomodel.BioModel;
Expand Down Expand Up @@ -277,7 +274,7 @@ void setSolverDescription(SolverDescription sd) {

@Override
public void activateView(SelectionManager selectionManager) {
SimulationContext sc = BeanUtils.downcast(SimulationContext.class, simulation.getSimulationOwner());
SimulationContext sc = CastingUtils.downcast(SimulationContext.class, simulation.getSimulationOwner());
Window activated = null;
if (sc != null ) {
ActiveView av = new ActiveView(sc, DocumentEditorTreeFolderClass.SIMULATIONS_NODE, ActiveViewID.simulations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
import org.vcell.model.rbm.MolecularComponent;
import org.vcell.model.rbm.MolecularType;
import org.vcell.model.rbm.SpeciesPattern;
import org.vcell.util.BeanUtils;
import org.vcell.util.Issue;
import org.vcell.util.*;
import org.vcell.util.Issue.IssueCategory;
import org.vcell.util.Issue.IssueOrigin;
import org.vcell.util.Issue.Severity;
import org.vcell.util.ObjectNotFoundException;
import org.vcell.util.VCAssert;
import org.vcell.util.document.VCDocument;
import org.vcell.util.gui.GuiUtils;
import org.vcell.util.gui.ScrollTable;
Expand Down Expand Up @@ -210,7 +207,7 @@ private String getSourceObjectPathDescription(VCDocument vcDocument, Issue issue
VCAssert.assertValid(issue);
Object source = issue.getSource();
{
IssueOrigin io = BeanUtils.downcast(IssueOrigin.class, source);
IssueOrigin io = CastingUtils.downcast(IssueOrigin.class, source);
if (io != null) {
return io.getDescription();
}
Expand Down Expand Up @@ -358,7 +355,7 @@ private String getSourceObjectDescription(VCDocument vcDocument, Issue issue) {
if (vcDocument instanceof BioModel){
Object object = issue.getSource();
{
DecoratedIssueSource dis = BeanUtils.downcast(DecoratedIssueSource.class, object);
DecoratedIssueSource dis = CastingUtils.downcast(DecoratedIssueSource.class, object);
if (dis != null) {
return dis.getSourcePath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,6 @@ public void propertyChange(java.beans.PropertyChangeEvent evt) {
}
}


/**
* Insert the method's description here.
* Creation date: (5/10/2004 6:32:09 PM)
* @param newSimContext cbit.vcell.mapping.SimulationContext
*/
public void setSimulationWorkspace(SimulationWorkspace newSimulationWorkspace) {
SimulationWorkspace oldValue = this.simulationWorkspace;
simulationWorkspace = newSimulationWorkspace;
Expand Down Expand Up @@ -282,7 +276,7 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
suggestedInterval = timeStep;
bValid = false;
} else {
if (!BeanUtils.isIntegerMultiple(outputTime, timeStep)) {
if (BeanUtils.isNotAnIntegerMultiple(outputTime, timeStep)) {
double n = outputTime/timeStep;
int intn = (int)Math.round(n);
suggestedInterval = (intn * timeStep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void finished() {
}
if (lg.isInfoEnabled()) {
Object obj = hash.get(STACK_TRACE_ARRAY);
StackTraceElement ste[] = BeanUtils.downcast(StackTraceElement[].class, obj);
StackTraceElement ste[] = CastingUtils.downcast(StackTraceElement[].class, obj);
if (ste != null) {
String stackTraceString = StringUtils.join(ste,'\n');
lg.info(stackTraceString,(Throwable)hash.get(TASK_ABORTED_BY_ERROR));
Expand Down Expand Up @@ -641,7 +641,7 @@ private static void runTask(AsynchClientTask currentTask, Hashtable<String, Obje
String msg = "Thread " + Thread.currentThread().getName() + " calling task " + currentTask.getTaskName();
if (lg.isDebugEnabled()) {
Object obj = hash.get(STACK_TRACE_ARRAY);
StackTraceElement ste[] = BeanUtils.downcast(StackTraceElement[].class, obj);
StackTraceElement ste[] = CastingUtils.downcast(StackTraceElement[].class, obj);
if (ste != null) {
msg += '\n' + StringUtils.join(ste,'\n');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ public boolean shouldYieldFocus(JComponent input) {
if (outputTime < timeStep) {
suggestedInterval = timeStep;
bValid = false;
} else if (!BeanUtils.isIntegerMultiple(outputTime, timeStep)) {
} else if (BeanUtils.isNotAnIntegerMultiple(outputTime, timeStep)) {
double n = outputTime/timeStep;
int intn = (int)Math.round(n);
if (intn != n) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void correctUniformOutputTimeStep() {
if (outputTime < timeStep) {
suggestedInterval = timeStep;
bValid = false;
} else if (!BeanUtils.isIntegerMultiple(outputTime, timeStep)){
} else if (BeanUtils.isNotAnIntegerMultiple(outputTime, timeStep)){
double n = outputTime/timeStep;
int intn = (int)Math.round(n);
if (intn != n) {
Expand All @@ -120,9 +120,9 @@ public void correctUniformOutputTimeStep() {
public void setNewTimeStep() {
try {
TimeStep oldTimeStep = solverTaskDescription.getTimeStep();
double defaultTimeStep = !getDefaultTimeStepTextField().isEnabled() ? oldTimeStep.getDefaultTimeStep() : new Double(getDefaultTimeStepTextField().getText()).doubleValue();
double minTimeStep = !getMinimumTimeStepTextField().isEnabled() ? oldTimeStep.getMinimumTimeStep() : new Double(getMinimumTimeStepTextField().getText()).doubleValue();
double maxTimeStep = !getMaximumTimeStepTextField().isEnabled() ? oldTimeStep.getMaximumTimeStep() : new Double(getMaximumTimeStepTextField().getText()).doubleValue();
double defaultTimeStep = !getDefaultTimeStepTextField().isEnabled() ? oldTimeStep.getDefaultTimeStep() : Double.parseDouble(getDefaultTimeStepTextField().getText());
double minTimeStep = !getMinimumTimeStepTextField().isEnabled() ? oldTimeStep.getMinimumTimeStep() : Double.parseDouble(getMinimumTimeStepTextField().getText());
double maxTimeStep = !getMaximumTimeStepTextField().isEnabled() ? oldTimeStep.getMaximumTimeStep() : Double.parseDouble(getMaximumTimeStepTextField().getText());
TimeStep newTimeStep = new TimeStep(minTimeStep, defaultTimeStep, maxTimeStep);
solverTaskDescription.setTimeStep(newTimeStep);
} catch (java.lang.Throwable ivjExc) {
Expand Down Expand Up @@ -383,12 +383,6 @@ public void windowClosing(java.awt.event.WindowEvent e) {
}
}

/**
* Sets the timeStep property (cbit.vcell.solver.TimeStep) value.
* @param timeStep The new value for the property.
* @exception java.beans.PropertyVetoException The exception description.
* @see #getTimeStep
*/
public void setSolverTaskDescription(SolverTaskDescription newValue) throws java.beans.PropertyVetoException {
SolverTaskDescription oldValue = solverTaskDescription;
/* Stop listening for events from the current object */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.vcell.client.logicalwindow.LWHandle.LWModality;
import org.vcell.util.BeanUtils;

import edu.uchc.connjur.wb.ExecutionTrace;
import org.vcell.util.CastingUtils;

/**
* utility methods for package
Expand Down Expand Up @@ -111,7 +111,7 @@ public static void stagger(Container reference, Window positioned) {
*/
public static <T> T findOwnerOfType(Class<? extends T> clzz,Component swingParent) {
final Logger lg = LGHolder.LG;
T t = BeanUtils.downcast(clzz, swingParent);
T t = CastingUtils.downcast(clzz, swingParent);
if (t != null) {
return t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ public static Dimension getScreenSize( ) {
private static void setInternalNotCancelEnabled(final JOptionPane jop,final boolean bEnabled, boolean bClickOK) {
VCAssert.assertTrue(!bClickOK || bEnabled, "bEnabled must be true if bClickOK is true");
for(Component topLevel : jop.getComponents() ) {
Container cntr = BeanUtils.downcast(Container.class, topLevel);
Container cntr = CastingUtils.downcast(Container.class, topLevel);
if (cntr != null) {
for (Component cmpt : cntr.getComponents()) {
JButton btn = BeanUtils.downcast(JButton.class, cmpt);
JButton btn = CastingUtils.downcast(JButton.class, cmpt);
if (btn != null && !btn.getText().equalsIgnoreCase(getCancelText())) {
btn.setEnabled(bEnabled);
if(bEnabled && bClickOK) {
Expand Down Expand Up @@ -757,7 +757,7 @@ public static void showErrorDialog(final Component requester, final String messa
dialog.setVisible(true);
if (goingToEmail ) {
Object ro = pane.getValue( );
Integer reply = BeanUtils.downcast(Integer.class, ro);
Integer reply = CastingUtils.downcast(Integer.class, ro);
boolean userSaidYes = reply != null ? reply == JOptionPane.YES_OPTION : false;
if (userSaidYes) {
Throwable throwableToSend = exception;
Expand Down
8 changes: 4 additions & 4 deletions vcell-client/src/main/java/org/vcell/util/gui/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import javax.swing.tree.TreePath;

import org.apache.commons.lang3.StringUtils;
import org.vcell.util.BeanUtils;
import org.vcell.util.CastingUtils;
import org.vcell.util.ISize;

import cbit.vcell.desktop.BioModelNode;
Expand Down Expand Up @@ -219,7 +219,7 @@ private static void prefSize(StringBuilder destination, int level, Component cmp
Dimension dim = cmpnt.getPreferredSize();
destination.append(StringUtils.repeat(' ', level) + ExecutionTrace.justClassName(cmpnt) + " prefers " + dim);
destination.append('\n');
Container container = BeanUtils.downcast(Container.class, cmpnt);
Container container = CastingUtils.downcast(Container.class, cmpnt);
if (container != null) {
for ( Component c : container.getComponents()) {
prefSize(destination, level + 1, c);
Expand All @@ -246,11 +246,11 @@ public static String getPreferredSizes(Component container) {
public static String describe(Window w) {
if (w != null) {
String className = ExecutionTrace.justClassName(w) + " ";
Frame f = BeanUtils.downcast(Frame.class, w);
Frame f = CastingUtils.downcast(Frame.class, w);
if (f != null) {
return className + f.getTitle();
}
Dialog d = BeanUtils.downcast(Dialog.class, w);
Dialog d = CastingUtils.downcast(Dialog.class, w);
if (d != null) {
return className + d.getTitle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import javax.swing.Timer;

import org.vcell.client.logicalwindow.LWContainerHandle;
import org.vcell.util.BeanUtils;
import org.vcell.util.CastingUtils;

@SuppressWarnings("serial")

Expand Down Expand Up @@ -219,7 +219,7 @@ public void actionPerformed(ActionEvent arg0) {
private boolean isModelDialogPresent( ) {
for (Window w: Window.getWindows()) {
if (w.isShowing()) {
Dialog d = BeanUtils.downcast(Dialog.class, w);
Dialog d = CastingUtils.downcast(Dialog.class, w);
if (d != null && d != IndefiniteProgressDialog.this) {
switch (d.getModalityType()) {
case MODELESS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import javax.swing.Timer;

import org.vcell.client.logicalwindow.LWContainerHandle;
import org.vcell.util.BeanUtils;
import org.vcell.util.CastingUtils;

@SuppressWarnings("serial")

Expand Down Expand Up @@ -251,7 +251,7 @@ public void actionPerformed(ActionEvent arg0) {
private boolean isModelDialogPresent( ) {
for (Window w: Window.getWindows()) {
if (w.isShowing()) {
Dialog d = BeanUtils.downcast(Dialog.class, w);
Dialog d = CastingUtils.downcast(Dialog.class, w);
if (d != null && d != LinearDefiniteProgressDialog.this) {
switch (d.getModalityType()) {
case MODELESS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.vcell.util.BeanUtils;
import org.vcell.util.CastingUtils;
import org.vcell.util.gui.DialogUtils;

@SuppressWarnings("serial")
Expand Down Expand Up @@ -95,7 +95,7 @@ private void optionPaneDialogs( ) {
// int r = JOptionPane.showConfirmDialog(this, "What say ye?","A question", JOptionPane.YES_NO_OPTION);
Object v = jop.getValue();
System.out.println(v);
Integer rval = BeanUtils.downcast(Integer.class, v);
Integer rval = CastingUtils.downcast(Integer.class, v);
if (rval != null) {
int r = rval;
switch (r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
import org.apache.logging.log4j.Logger;
import org.vcell.solver.smoldyn.SmoldynVCellMapper;
import org.vcell.solver.smoldyn.SmoldynVCellMapper.SmoldynKeyword;
import org.vcell.util.BeanUtils;
import org.vcell.util.Coordinate;
import org.vcell.util.DataAccessException;
import org.vcell.util.NumberUtils;
import org.vcell.util.VCAssert;
import org.vcell.util.*;
import org.vcell.util.document.TSJobResultsNoStats;
import org.vcell.util.document.TimeSeriesJobSpec;
import org.vcell.util.document.User;
Expand Down Expand Up @@ -1248,7 +1244,7 @@ private FileDataContainerID getSlice(SliceHelper sliceHelper, CartesianMesh mesh
public Collection<ExportOutput >makeASCIIData(OutputContext outputContext,JobRequest jobRequest, User user, DataServerImpl dataServerImpl, ExportSpecs exportSpecs,FileDataContainerManager fileDataContainerManager)
throws DataAccessException, IOException {
FormatSpecificSpecs formatSpecs = exportSpecs.getFormatSpecificSpecs( );
ASCIISpecs asciiSpecs = BeanUtils.downcast(ASCIISpecs.class, formatSpecs);
ASCIISpecs asciiSpecs = CastingUtils.downcast(ASCIISpecs.class, formatSpecs);
if (asciiSpecs != null) {
switch (asciiSpecs.getDataType()) {
case PDE_VARIABLE_DATA:
Expand Down
Loading

0 comments on commit 035dc9b

Please sign in to comment.