Skip to content

Commit

Permalink
chore: convert to using instanceof pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
kunstmusik committed Sep 24, 2024
1 parent 36e9ab0 commit 6b2bf02
Show file tree
Hide file tree
Showing 94 changed files with 433 additions and 534 deletions.
16 changes: 8 additions & 8 deletions blue-core/src/main/java/blue/Arrangement.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public int addInstrument(String instrumentId, Instrument instrument) {

fireTableDataChanged();

if (instrument instanceof Automatable) {
fireAutomatableAdded((Automatable) instrument);
if (instrument instanceof Automatable automatable) {
fireAutomatableAdded(automatable);
}

return retVal;
Expand All @@ -190,8 +190,8 @@ public void addInstrumentWithId(Instrument instr, String instrId, boolean sort)
Collections.sort(arrangement);
}

if (instr instanceof Automatable) {
fireAutomatableAdded((Automatable) instr);
if (instr instanceof Automatable automatable) {
fireAutomatableAdded(automatable);
}

fireTableDataChanged();
Expand Down Expand Up @@ -229,8 +229,8 @@ public void replaceInstrument(String instrumentId, Instrument instr) {
}
fireTableDataChanged();

if (instr instanceof Automatable) {
fireAutomatableAdded((Automatable) instr);
if (instr instanceof Automatable automatable) {
fireAutomatableAdded(automatable);
}
}

Expand Down Expand Up @@ -804,8 +804,8 @@ public Instrument removeInstrument(int index) {

fireTableDataChanged();

if (ia.instr instanceof Automatable) {
fireAutomatableRemoved((Automatable) ia.instr);
if (ia.instr instanceof Automatable automatable) {
fireAutomatableRemoved(automatable);
}

return ia.instr;
Expand Down
3 changes: 1 addition & 2 deletions blue-core/src/main/java/blue/CompileData.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public void setHandleParametersAndChannels(boolean handleParametersAndChannels)

public int addInstrument(Instrument instrument) {
if(handleParametersAndChannels && stringChannels != null && originalParameters != null) {
if(instrument instanceof Automatable) {
Automatable auto = (Automatable) instrument;
if(instrument instanceof Automatable auto) {
ArrayList<StringChannel> tempStringChannels = auto.getStringChannels();
if(tempStringChannels != null) {
stringChannels.addAll(tempStringChannels);
Expand Down
11 changes: 5 additions & 6 deletions blue-core/src/main/java/blue/InstrumentLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ public Object getRoot() {
public int getChildCount(Object parent) {
if (parent instanceof Instrument) {
return 0;
} else if (parent instanceof InstrumentCategory) {
InstrumentCategory cat = (InstrumentCategory) parent;
} else if (parent instanceof InstrumentCategory cat) {
return cat.getSubCategories().size() + cat.getInstruments().size();
}

Expand Down Expand Up @@ -272,10 +271,10 @@ public void removeTreeModelListener(TreeModelListener l) {
public void valueForPathChanged(TreePath path, Object newValue) {
Object obj = path.getLastPathComponent();

if (obj instanceof InstrumentCategory) {
((InstrumentCategory) obj).setCategoryName(newValue.toString());
} else if (obj instanceof Instrument) {
((Instrument) obj).setName(newValue.toString());
if (obj instanceof InstrumentCategory instrumentCategory) {
instrumentCategory.setCategoryName(newValue.toString());
} else if (obj instanceof Instrument instrument) {
instrument.setName(newValue.toString());
}

TreeModelEvent e = new TreeModelEvent(this, path);
Expand Down
8 changes: 4 additions & 4 deletions blue-core/src/main/java/blue/mixer/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,16 @@ public Send[] getSends() {
for (int i = 0; i < preEffects.size(); i++) {
Object obj = preEffects.getElementAt(i);

if (obj instanceof Send) {
temp.add((Send)obj);
if (obj instanceof Send send) {
temp.add(send);
}
}

for (int i = 0; i < postEffects.size(); i++) {
Object obj = postEffects.getElementAt(i);

if (obj instanceof Send) {
temp.add((Send)obj);
if (obj instanceof Send send) {
temp.add(send);
}
}

Expand Down
22 changes: 10 additions & 12 deletions blue-core/src/main/java/blue/mixer/EffectsChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public EffectsChain() {

public EffectsChain(EffectsChain chain) {
for(Object item : chain.effects) {
if(item instanceof Effect) {
addEffect(new Effect((Effect)item));
} else if (item instanceof Send){
addSend(new Send((Send)item));
if(item instanceof Effect effect) {
addEffect(new Effect(effect));
} else if (item instanceof Send send){
addSend(new Send(send));
}
}
}
Expand All @@ -62,11 +62,9 @@ public Element saveAsXML() {
for (Iterator it = effects.iterator(); it.hasNext();) {
Object obj = it.next();

if (obj instanceof Effect) {
Effect elem = (Effect) obj;
if (obj instanceof Effect elem) {
retVal.addElement(elem.saveAsXML());
} else if (obj instanceof Send) {
Send send = (Send) obj;
} else if (obj instanceof Send send) {
retVal.addElement(send.saveAsXML());
}
}
Expand Down Expand Up @@ -124,8 +122,8 @@ public void addSend(Send send) {
public Object removeElementAt(int index) {
Object obj = effects.remove(index);

if (obj instanceof Send) {
((Send) obj).removePropertyChangeListener(this);
if (obj instanceof Send send) {
send.removePropertyChangeListener(this);
}

ListDataEvent lde = new ListDataEvent(this,
Expand Down Expand Up @@ -172,8 +170,8 @@ public Send[] getSends() {
for (int i = 0; i < this.size(); i++) {
Object obj = this.getElementAt(i);

if (obj instanceof Send) {
temp.add((Send) obj);
if (obj instanceof Send send) {
temp.add(send);
}
}

Expand Down
9 changes: 3 additions & 6 deletions blue-core/src/main/java/blue/mixer/MixerNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ protected static int indexOfLastValidSend(EffectsChain chain,
for (int i = 0; i < chain.getSize(); i++) {
Object obj = chain.getElementAt(i);

if (obj instanceof Send) {
Send send = (Send) obj;
if (obj instanceof Send send) {

if (send.getSendChannel().equals(Channel.MASTER)) {
index = i;
Expand Down Expand Up @@ -365,8 +364,7 @@ private static void applyEffects(EffectsChain chain, OpcodeList udos,
for (int i = 0; i <= lastIndex; i++) {
Object obj = chain.getElementAt(i);

if (obj instanceof Effect) {
Effect effect = (Effect) obj;
if (obj instanceof Effect effect) {

if (effect.isEnabled()) {

Expand All @@ -387,8 +385,7 @@ private static void applyEffects(EffectsChain chain, OpcodeList udos,
buffer.append(effectName).append("\t");
buffer.append(signalChannels).append("\n");
}
} else if (obj instanceof Send) {
Send send = (Send) obj;
} else if (obj instanceof Send send) {

if (send.isEnabled()) {
String[] parts = signalChannels.split(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ public static BSBGraphicInterface loadFromXML(Element data)
switch (name) {
case "bsbObject":
BSBObject obj = (BSBObject) ObjectUtilities.loadFromXML(node);
if (obj instanceof BSBGroup) {
graphicInterface.setRootGroup((BSBGroup) obj);
if (obj instanceof BSBGroup bSBGroup) {
graphicInterface.setRootGroup(bSBGroup);
} else {
// legacy reading of BSBObjects stored here pre-2.7.0
graphicInterface.getRootGroup().addBSBObject(obj);
}
break;

case "gridSettings":
gridSettings = GridSettings.loadFromXML(node);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean add(BSBObject bsbObj) {
}
}

if (bsbObj instanceof BSBGroup) {
if (bsbObj instanceof BSBGroup bSBGroup) {
if (unm != null) {
UniqueNameManager tempUNM = new UniqueNameManager();
Set<String> additionalNames = new HashSet<>();
Expand All @@ -90,9 +90,9 @@ public boolean add(BSBObject bsbObj) {
}
return temp;
});
((BSBGroup) bsbObj).makeNamesUnique(tempUNM, additionalNames);
bSBGroup.makeNamesUnique(tempUNM, additionalNames);
}
((BSBGroup) bsbObj).setParameterList(parameterList);
bSBGroup.setParameterList(parameterList);
}

bsbObj.setUniqueNameManager(unm);
Expand All @@ -111,23 +111,23 @@ public boolean add(BSBObject bsbObj) {
bsbObj = change.getElementAdded();
allSet.add(bsbObj);

if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).setAllSet(allSet);
((BSBGroup) bsbObj).setParameterList(parameterList);
if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.setAllSet(allSet);
bSBGroup.setParameterList(parameterList);
}
if (bsbObj instanceof AutomatableBSBObject) {
((AutomatableBSBObject) bsbObj).setParameterList(
if (bsbObj instanceof AutomatableBSBObject automatableBSBObject) {
automatableBSBObject.setParameterList(
parameterList);
}
bsbObj.setUniqueNameManager(unm);
} else if (change.wasRemoved()) {
bsbObj = change.getElementRemoved();
allSet.remove(bsbObj);
if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).setAllSet(null);
((BSBGroup) bsbObj).removeParameters();
} else if (bsbObj instanceof AutomatableBSBObject) {
((AutomatableBSBObject) bsbObj).setAutomationAllowed(false);
if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.setAllSet(null);
bSBGroup.removeParameters();
} else if (bsbObj instanceof AutomatableBSBObject automatableBSBObject) {
automatableBSBObject.setAutomationAllowed(false);
}
}
}
Expand Down Expand Up @@ -252,8 +252,8 @@ public Set<String> getNames() {
Set<String> names = new HashSet<>();

for (BSBObject bsbObj : interfaceItems) {
if (bsbObj instanceof BSBGroup) {
names.addAll(((BSBGroup) bsbObj).getNames());
if (bsbObj instanceof BSBGroup bSBGroup) {
names.addAll(bSBGroup.getNames());
} else {
String[] replacementKeys = bsbObj.getReplacementKeys();

Expand Down Expand Up @@ -357,8 +357,7 @@ public BSBObject deepCopy() {

public void randomize() {
for (BSBObject bsbObj : interfaceItems) {
if (bsbObj instanceof Randomizable) {
Randomizable randomizable = (Randomizable) bsbObj;
if (bsbObj instanceof Randomizable randomizable) {
if (randomizable.isRandomizable()) {
randomizable.randomize();
}
Expand Down Expand Up @@ -389,22 +388,21 @@ public void setUniqueNameManager(UniqueNameManager unm) {

public void resetSubChannels() {
for (BSBObject bsbObj : interfaceItems) {
if (bsbObj instanceof BSBSubChannelDropdown) {
((BSBSubChannelDropdown) bsbObj)
if (bsbObj instanceof BSBSubChannelDropdown bSBSubChannelDropdown) {
bSBSubChannelDropdown
.setChannelOutput(Channel.MASTER);
} else if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).resetSubChannels();
} else if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.resetSubChannels();
}
}
}

public void getStringChannels(ArrayList<StringChannel> stringChannels) {

for (BSBObject bsbObj : interfaceItems) {
if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).getStringChannels(stringChannels);
} else if (bsbObj instanceof StringChannelProvider) {
StringChannelProvider provider = (StringChannelProvider) bsbObj;
if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.getStringChannels(stringChannels);
} else if (bsbObj instanceof StringChannelProvider provider) {
if (provider.isStringChannelEnabled()) {
stringChannels.add(provider.getStringChannel());
}
Expand All @@ -416,10 +414,10 @@ public void setParameterList(ParameterList paramList) {
this.parameterList = paramList;

for (BSBObject bsbObj : interfaceItems) {
if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).setParameterList(paramList);
} else if (bsbObj instanceof AutomatableBSBObject) {
((AutomatableBSBObject) bsbObj).setParameterList(paramList);
if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.setParameterList(paramList);
} else if (bsbObj instanceof AutomatableBSBObject automatableBSBObject) {
automatableBSBObject.setParameterList(paramList);
}
}

Expand Down Expand Up @@ -453,18 +451,18 @@ public void setAllSet(ObservableSet<BSBObject> allSet) {
}

for (BSBObject bsbObj : interfaceItems) {
if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).setAllSet(allSet);
if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.setAllSet(allSet);
}
}
}

protected void removeParameters() {
for (BSBObject bsbObj : interfaceItemsProperty()) {
if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).removeParameters();
} else if (bsbObj instanceof AutomatableBSBObject) {
((AutomatableBSBObject) bsbObj).setAutomationAllowed(false);
if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.removeParameters();
} else if (bsbObj instanceof AutomatableBSBObject automatableBSBObject) {
automatableBSBObject.setAutomationAllowed(false);
}
}

Expand Down Expand Up @@ -521,8 +519,8 @@ private void makeNamesUnique(UniqueNameManager unm,

for (BSBObject bsbObj : interfaceItems) {
// guarantee unique names for objects
if (bsbObj instanceof BSBGroup) {
((BSBGroup) bsbObj).makeNamesUnique(unm, additionalNames);
if (bsbObj instanceof BSBGroup bSBGroup) {
bSBGroup.makeNamesUnique(unm, additionalNames);
} else {
String objName = bsbObj.getObjectName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ private boolean isUnique(String name, Set<String> names) {

@Override
public boolean equals(Object obj) {
if (obj instanceof UniqueNameManager) {
UniqueNameManager unm = (UniqueNameManager) obj;
if (obj instanceof UniqueNameManager unm) {

return defaultPrefix.equals(unm.defaultPrefix);
}
Expand Down
8 changes: 4 additions & 4 deletions blue-core/src/main/java/blue/score/Score.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ public static Score loadFromXML(Element data, Map<String, Object> objRefMap) thr
"Unable to load Score LayerGroup of type: " + node.getName());
}
score.add(layerGroup);
if(layerGroup instanceof PolyObject) {
((PolyObject)layerGroup).setTimeBehavior(TimeBehavior.NONE);
if(layerGroup instanceof PolyObject polyObject) {
polyObject.setTimeBehavior(TimeBehavior.NONE);
}
break;

}
}

Expand Down Expand Up @@ -195,8 +196,7 @@ public List<LayerGroup> getLayerGroupsForScoreObjects(Collection<? extends Score
for (LayerGroup<? extends Layer> layerGroup : this) {
for (Layer layer : layerGroup) {
boolean found = false;
if (layer instanceof ScoreObjectLayer) {
ScoreObjectLayer scoreLayer = (ScoreObjectLayer) layer;
if (layer instanceof ScoreObjectLayer scoreLayer) {
if (!Collections.disjoint(scoreLayer, scoreObjects)) {
retVal.add(layerGroup);
found = true;
Expand Down
Loading

0 comments on commit 6b2bf02

Please sign in to comment.