}
// @formatter:off
- private static Bit[][] JOIN_TABLE =
+ private static final Bit[][] JOIN_TABLE =
{ { U, U, U, U, U },
{ U, X, X, X, X },
{ U, X, ZERO, X, ZERO },
{ U, X, X, ONE, ONE },
{ U, X, ZERO, ONE, Z } };
- private static Bit[][] AND_TABLE =
+ private static final Bit[][] AND_TABLE =
{ { U, U, ZERO, U, U },
{ U, X, ZERO, X, X },
{ ZERO, ZERO, ZERO, ZERO, ZERO },
{ U, X, ZERO, ONE, X },
{ U, X, ZERO, X, X } };
- private static Bit[][] OR_TABLE =
+ private static final Bit[][] OR_TABLE =
{ { U, U, U, ONE, U },
{ U, X, X, ONE, X },
{ U, X, ZERO, ONE, X },
{ ONE, ONE, ONE, ONE, ONE },
{ U, X, X, ONE, X } };
- private static Bit[][] XOR_TABLE =
+ private static final Bit[][] XOR_TABLE =
{ { U, U, U, U, U },
{ U, X, X, X, X },
{ U, X, ZERO, ONE, X },
{
public final static Timeline TIMELINE = new Timeline(11);
- public static void main(String[] args)
- {
- }
}
\ No newline at end of file
@Override
public void update(WireArray initiator, Bit[] oldValues)
{
- Simulation.TIMELINE.addEvent((e) ->
- {
- compute();
- }, processTime);
+ Simulation.TIMELINE.addEvent(e -> compute(), processTime);
}
protected abstract void compute();
package era.mi.logic.components;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
@Override
public List<WireArray> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in));
+ return List.of(in);
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(new ArrayList<WireArray>());
+ return List.of();
}
}
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
{
this.delta = delta;
this.outI = out.createInput();
- Simulation.TIMELINE.addEvent(this, 50);
+ Simulation.TIMELINE.addEvent(this, delta);
}
@Override
public void handle(TimelineEvent e)
{
addToTimeline();
- outI.feedSignals(new Bit[] { toggle ? Bit.ONE : Bit.ZERO });
+ outI.feedSignals(toggle ? Bit.ONE : Bit.ZERO);
toggle = !toggle;
}
@Override
public List<WireArray> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList());
+ return List.of();
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(outI.owner));
+ return List.of(outI.owner);
}
}
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.wires.WireArray;
import era.mi.logic.wires.WireArray.WireArrayEnd;
/**
- * Models a multiplexer. Takes an arbitrary amount of input {@link WireArray}s, one of which, as determined by select, is put through to the
- * output.
+ * Models a multiplexer. Takes an arbitrary amount of outputs {@link WireArray}s, one of which, as determined by select, receives the input
+ * signal.
*
* @author Fabian Stemmler
*
private int selected = -1;
/**
- * Input {@link WireArray}s and out must be of uniform length
+ * Output {@link WireArray}s and in must be of uniform length
*
- * @param out Must be of uniform length with all inputs.
- * @param select Indexes the input array which is to be mapped to the output. Must have enough bits to index all inputs.
- * @param outputs One of these inputs is mapped to the output, depending on the select bits
+ * @param in Must be of uniform length with all outputs.
+ * @param select Indexes the output array to which the input is mapped. Must have enough bits to index all outputs.
+ * @param outputs One of these outputs receives the input signal, depending on the select bits
*/
public Demux(int processTime, WireArray in, WireArray select, WireArray... outputs)
{
@Override
public List<WireArray> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in, select));
+ return List.of(in, select);
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(outputs));
+ return List.of(outputs);
}
}
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
@Override
public List<WireArray> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(inputs));
+ return List.of(inputs);
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(outI.owner));
+ return List.of(outI.owner);
}
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(outI.owner));
+ return List.of(outI.owner);
}
}
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
@Override
public List<WireArray> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in, enable));
+ return List.of(in, enable);
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(outI.owner));
+ return List.of(outI.owner);
}
}
package era.mi.logic.components.gates;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
@Override
public List<WireArray> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in));
+ return List.of(in);
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
+ @Override
protected void compute()
{
Bit[] result = in[0].getValues();
package era.mi.logic.components.gates;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Util;
outI = out.createInput();
}
+ @Override
public void compute()
{
outI.feedSignals(Util.not(in.getValues()));
@Override
public List<WireArray> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in));
+ return List.of(in);
}
@Override
public List<WireArray> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
}
+++ /dev/null
-package era.mi.logic.tests;
-
-import era.mi.logic.Bit;
-import era.mi.logic.Simulation;
-import era.mi.logic.wires.WireArray;
-import era.mi.logic.wires.WireArray.WireArrayEnd;
-import era.mi.logic.wires.WireArrayObserver;
-
-public class Connector implements WireArrayObserver
-{
- private final WireArray a;
-// private final WireArray b;
- private final WireArrayEnd aI;
- private final WireArrayEnd bI;
-
- public Connector(WireArray a, WireArray b)
- {
- if (a.length != b.length)
- throw new IllegalArgumentException(String.format("WireArray width does not match: %d, %d", a.length, b.length));
- this.a = a;
-// this.b = b;
- a.addObserver(this);
- b.addObserver(this);
- aI = a.createInput();
- bI = b.createInput();
- }
-
- @Override
- public void update(WireArray initiator, Bit[] oldValues)
- {
- Simulation.TIMELINE.addEvent((e) ->
- {
- if (initiator == a)
- bI.feedSignals(aI.wireValuesExcludingMe());
- else
- aI.feedSignals(bI.wireValuesExcludingMe());
- }, 1);
- }
-}
g.setFont(g.getFont().deriveFont(Math.min(height, width) / 40f));
}
- private void drawString(Graphics g, String s, int x, int y, double anchorX, double anchorY)
+ private static void drawString(Graphics g, String s, int x, int y, double anchorX, double anchorY)
{
int h = g.getFontMetrics().getAscent();
int w = g.getFontMetrics().stringWidth(s);
{
if (!hasNext())
return -1;
- else
- return events.peek().timing;
+ return events.peek().timing;
}
public void reset()
private class InnerEvent
{
- private final long timing;
+ final long timing;
private final TimelineEventHandler function;
private final TimelineEvent event;
return timing;
}
+ @Override
public String toString()
{
return "timestamp: " + timing;
public final int travelTime;
private List<WireArrayObserver> observers = new ArrayList<WireArrayObserver>();
public final int length;
- private List<WireArrayEnd> inputs = new ArrayList<WireArrayEnd>();
+ List<WireArrayEnd> inputs = new ArrayList<WireArrayEnd>();
public WireArray(int length, int travelTime)
{
}
}
- private void recalculate()
+ void recalculate()
{
switch (inputs.size())
{
return new WireArrayEnd(this);
}
- private void registerInput(WireArrayEnd toRegister)
+ void registerInput(WireArrayEnd toRegister)
{
inputs.add(toRegister);
}
{
public final WireArray owner;
private boolean open;
- private Bit[] inputValues;
+ Bit[] inputValues;
- private WireArrayEnd(WireArray owner)
+ WireArrayEnd(WireArray owner)
{
super();
this.owner = owner;
*/
public void feedSignals(Bit... newValues)
{
- if (newValues.length == length)
- {
- feedSignals(0, newValues);
- } else
+ if (newValues.length != length)
throw new IllegalArgumentException(
String.format("Attempted to input %d bits instead of %d bits.", newValues.length, length));
+ feedSignals(0, newValues);
+
}
/**