org.eclipse.jdt.core.formatter.align_type_members_on_columns=false\r
org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false\r
org.eclipse.jdt.core.formatter.align_with_spaces=false\r
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16\r
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16\r
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0\r
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16\r
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16\r
org.eclipse.jdt.core.formatter.alignment_for_assignment=0\r
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16\r
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16\r
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16\r
org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16\r
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80\r
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0\r
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16\r
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16\r
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0\r
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16\r
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0\r
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16\r
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16\r
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16\r
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0\r
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16\r
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16\r
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0\r
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80\r
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16\r
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0\r
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16\r
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16\r
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16\r
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16\r
org.eclipse.jdt.core.formatter.comment.format_source_code=true\r
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false\r
org.eclipse.jdt.core.formatter.comment.indent_root_tags=false\r
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false\r
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert\r
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert\r
org.eclipse.jdt.core.formatter.comment.line_length=140\r
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert\r
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert\r
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert\r
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert\r
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert\r
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert\r
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert\r
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert\r
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert\r
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert\r
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert\r
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert\r
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert\r
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert\r
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert\r
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert\r
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert\r
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert\r
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert\r
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert\r
org.eclipse.jdt.core.formatter.join_lines_in_comments=true\r
org.eclipse.jdt.core.formatter.join_wrapped_lines=true\r
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never\r
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never\r
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never\r
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false\r
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false\r
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never\r
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never\r
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never\r
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false\r
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never\r
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never\r
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never\r
org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false\r
org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false\r
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false\r
org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false\r
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false\r
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never\r
org.eclipse.jdt.core.formatter.lineSplit=140\r
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false\r
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false\r
org.eclipse.jdt.core.formatter.tabulation.size=4\r
org.eclipse.jdt.core.formatter.use_on_off_tags=true\r
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false\r
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true\r
org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false\r
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true\r
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true\r
org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true\r
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true\r
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true\r
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true\r
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true\r
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true\r
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true\r
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true\r
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter\r
eclipse.preferences.version=1\r
-formatter_profile=_MyPrefrence\r
-formatter_settings_version=14\r
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true\r
+formatter_profile=_ERA-MI\r
+formatter_settings_version=16\r
+sp_cleanup.add_default_serial_version_id=true\r
+sp_cleanup.add_generated_serial_version_id=false\r
+sp_cleanup.add_missing_annotations=true\r
+sp_cleanup.add_missing_deprecated_annotations=true\r
+sp_cleanup.add_missing_methods=false\r
+sp_cleanup.add_missing_nls_tags=false\r
+sp_cleanup.add_missing_override_annotations=true\r
+sp_cleanup.add_missing_override_annotations_interface_methods=true\r
+sp_cleanup.add_serial_version_id=false\r
+sp_cleanup.always_use_blocks=false\r
+sp_cleanup.always_use_parentheses_in_expressions=false\r
+sp_cleanup.always_use_this_for_non_static_field_access=false\r
+sp_cleanup.always_use_this_for_non_static_method_access=false\r
+sp_cleanup.convert_functional_interfaces=true\r
+sp_cleanup.convert_to_enhanced_for_loop=true\r
+sp_cleanup.correct_indentation=true\r
+sp_cleanup.format_source_code=true\r
+sp_cleanup.format_source_code_changes_only=false\r
+sp_cleanup.insert_inferred_type_arguments=false\r
+sp_cleanup.make_local_variable_final=true\r
+sp_cleanup.make_parameters_final=false\r
+sp_cleanup.make_private_fields_final=true\r
+sp_cleanup.make_type_abstract_if_missing_method=false\r
+sp_cleanup.make_variable_declarations_final=true\r
+sp_cleanup.never_use_blocks=true\r
+sp_cleanup.never_use_parentheses_in_expressions=true\r
+sp_cleanup.on_save_use_additional_actions=false\r
+sp_cleanup.organize_imports=true\r
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false\r
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true\r
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true\r
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=true\r
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false\r
+sp_cleanup.remove_private_constructors=true\r
+sp_cleanup.remove_redundant_modifiers=true\r
+sp_cleanup.remove_redundant_semicolons=true\r
+sp_cleanup.remove_redundant_type_arguments=true\r
+sp_cleanup.remove_trailing_whitespaces=true\r
+sp_cleanup.remove_trailing_whitespaces_all=true\r
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false\r
+sp_cleanup.remove_unnecessary_casts=true\r
+sp_cleanup.remove_unnecessary_nls_tags=true\r
+sp_cleanup.remove_unused_imports=true\r
+sp_cleanup.remove_unused_local_variables=false\r
+sp_cleanup.remove_unused_private_fields=true\r
+sp_cleanup.remove_unused_private_members=false\r
+sp_cleanup.remove_unused_private_methods=true\r
+sp_cleanup.remove_unused_private_types=true\r
+sp_cleanup.sort_members=false\r
+sp_cleanup.sort_members_all=false\r
+sp_cleanup.use_anonymous_class_creation=false\r
+sp_cleanup.use_blocks=false\r
+sp_cleanup.use_blocks_only_for_return_and_throw=false\r
+sp_cleanup.use_lambda=true\r
+sp_cleanup.use_parentheses_in_expressions=false\r
+sp_cleanup.use_this_for_non_static_field_access=true\r
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true\r
+sp_cleanup.use_this_for_non_static_method_access=true\r
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true\r
{\r
public final static Timeline TIMELINE = new Timeline(11);\r
\r
- public static void main(String[] args)\r
- {\r
- }\r
}
\ No newline at end of file
import era.mi.logic.Bit;\r
import era.mi.logic.Simulation;\r
import era.mi.logic.wires.Wire;\r
-import era.mi.logic.wires.WireArrayObserver;\r
+import era.mi.logic.wires.WireObserver;\r
\r
/**\r
* A basic component that recomputes all outputs (with a delay), when it is updated.\r
* \r
* @author Fabian Stemmler\r
*/\r
-public abstract class BasicComponent implements WireArrayObserver, Component\r
+public abstract class BasicComponent implements WireObserver, Component\r
{\r
private int processTime;\r
\r
@Override\r
public void update(Wire initiator, Bit[] oldValues)\r
{\r
- Simulation.TIMELINE.addEvent((e) ->\r
- {\r
- compute();\r
- }, processTime);\r
+ Simulation.TIMELINE.addEvent(e -> compute(), processTime);\r
}\r
\r
protected abstract void compute();\r
package era.mi.logic.components;\r
\r
-import java.util.ArrayList;\r
import java.util.Arrays;\r
-import java.util.Collections;\r
import java.util.List;\r
\r
import era.mi.logic.Bit;\r
@Override\r
public List<WireEnd> getAllInputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(in));\r
+ return List.of(in);\r
}\r
\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(new ArrayList<WireEnd>());\r
+ return List.of();\r
}\r
}\r
package era.mi.logic.components;\r
\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
import java.util.List;\r
\r
import era.mi.logic.Bit;\r
public void handle(TimelineEvent e)\r
{\r
addToTimeline();\r
- out.feedSignals(new Bit[] { toggle ? Bit.ONE : Bit.ZERO });\r
+ out.feedSignals(toggle ? Bit.ONE : Bit.ZERO);\r
toggle = !toggle;\r
}\r
\r
@Override\r
public List<WireEnd> getAllInputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList());\r
+ return List.of();\r
}\r
\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(out));\r
+ return List.of(out);\r
}\r
}\r
--- /dev/null
+package era.mi.logic.components;
+
+import java.util.List;
+
+import era.mi.logic.Bit;
+import era.mi.logic.Simulation;
+import era.mi.logic.wires.Wire;
+import era.mi.logic.wires.Wire.WireEnd;
+import era.mi.logic.wires.WireObserver;
+
+public class Connector implements WireObserver, Component
+{
+ private boolean connected;
+ private final WireEnd a;
+ private final WireEnd b;
+
+ public Connector(WireEnd a, WireEnd 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);
+ }
+
+ public void connect()
+ {
+ connected = true;
+ update(a.getWire());
+ update(b.getWire());
+ }
+
+ public void disconnect()
+ {
+ connected = false;
+ a.clearSignals();
+ b.clearSignals();
+ }
+
+ public void setConnection(boolean connected)
+ {
+ if (connected)
+ connect();
+ else
+ disconnect();
+ }
+
+ @Override
+ public void update(Wire initiator, Bit[] oldValues)
+ {
+ if (connected)
+ Simulation.TIMELINE.addEvent(e -> update(initiator), 1);
+ }
+
+ private void update(Wire initiator)
+ {
+ if (initiator == a.getWire())
+ b.feedSignals(a.wireValuesExcludingMe());
+ else
+ a.feedSignals(b.wireValuesExcludingMe());
+ }
+
+ @Override
+ public List<WireEnd> getAllInputs()
+ {
+ return List.of(a, b);
+ }
+
+ @Override
+ public List<WireEnd> getAllOutputs()
+ {
+ return List.of(a, b);
+ }
+}
package era.mi.logic.components;\r
\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
import java.util.List;\r
\r
import era.mi.logic.wires.Wire;\r
private int selected = -1;\r
\r
/**\r
- * Input {@link Wire}s and out must be of uniform length\r
+ * Output {@link Wire}s and in must be of uniform length\r
* \r
- * @param out Must be of uniform length with all inputs.\r
- * @param select Indexes the input array which is to be mapped to the output. Must have enough bits to index all inputs.\r
- * @param outputs One of these inputs is mapped to the output, depending on the select bits\r
+ * @param in Must be of uniform length with all outputs.\r
+ * @param select Indexes the output array to which the input is mapped. Must have enough bits to index all outputs.\r
+ * @param outputs One of these outputs receives the input signal, depending on the select bits\r
*/\r
public Demux(int processTime, WireEnd in, WireEnd select, WireEnd... outputs)\r
{\r
@Override\r
public List<WireEnd> getAllInputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(in, select));\r
+ return List.of(in, select);\r
}\r
\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(outputs));\r
+ return List.of(outputs);\r
}\r
}\r
package era.mi.logic.components;\r
\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
import java.util.List;\r
\r
import era.mi.logic.Bit;\r
import era.mi.logic.wires.Wire;\r
import era.mi.logic.wires.Wire.WireEnd;\r
-import era.mi.logic.wires.WireArrayObserver;\r
+import era.mi.logic.wires.WireObserver;\r
\r
-public class Merger implements WireArrayObserver, Component\r
+public class Merger implements WireObserver, Component\r
{\r
private WireEnd out;\r
private WireEnd[] inputs;\r
@Override\r
public List<WireEnd> getAllInputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(inputs));\r
+ return List.of(inputs);\r
}\r
\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(out));\r
+ return List.of(out);\r
}\r
}\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(out));\r
+ return List.of(out);\r
}\r
}\r
import era.mi.logic.Bit;\r
import era.mi.logic.wires.Wire;\r
import era.mi.logic.wires.Wire.WireEnd;\r
-import era.mi.logic.wires.WireArrayObserver;\r
+import era.mi.logic.wires.WireObserver;\r
\r
-public class Splitter implements WireArrayObserver\r
+public class Splitter implements WireObserver\r
{\r
private WireEnd input;\r
private WireEnd[] outputs;\r
package era.mi.logic.components;\r
\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
import java.util.List;\r
\r
import era.mi.logic.Bit;\r
-import era.mi.logic.wires.Wire;\r
import era.mi.logic.wires.Wire.WireEnd;\r
\r
public class TriStateBuffer extends BasicComponent\r
@Override\r
public List<WireEnd> getAllInputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(in, enable));\r
+ return List.of(in, enable);\r
}\r
\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(out));\r
+ return List.of(out);\r
}\r
\r
}\r
package era.mi.logic.components.gates;\r
\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
import java.util.List;\r
\r
import era.mi.logic.Bit;\r
@Override\r
public List<WireEnd> getAllInputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(in));\r
+ return List.of(in);\r
}\r
\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(out));\r
+ return List.of(out);\r
}\r
\r
+ @Override\r
protected void compute()\r
{\r
Bit[] result = in[0].getValues();\r
package era.mi.logic.components.gates;\r
\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
import java.util.List;\r
\r
import era.mi.logic.Util;\r
@Override\r
public List<WireEnd> getAllInputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(in));\r
+ return List.of(in);\r
}\r
\r
@Override\r
public List<WireEnd> getAllOutputs()\r
{\r
- return Collections.unmodifiableList(Arrays.asList(out));\r
+ return List.of(out);\r
}\r
}\r
package era.mi.logic.tests;\r
\r
-import static org.junit.jupiter.api.Assertions.*;\r
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;\r
+import static org.junit.jupiter.api.Assertions.assertEquals;\r
+import static org.junit.jupiter.api.Assertions.assertTrue;\r
+import static org.junit.jupiter.api.Assertions.fail;\r
\r
import java.util.Arrays;\r
import java.util.function.LongConsumer;\r
\r
import era.mi.logic.Bit;\r
import era.mi.logic.Simulation;\r
+import era.mi.logic.components.Connector;\r
import era.mi.logic.components.Demux;\r
import era.mi.logic.components.Merger;\r
import era.mi.logic.components.Mux;\r
import era.mi.logic.wires.Wire;\r
import era.mi.logic.wires.Wire.WireEnd;\r
\r
+@SuppressWarnings("unused")\r
class ComponentTest\r
{\r
\r
void circuitExampleTest()\r
{\r
Simulation.TIMELINE.reset();\r
- Wire a = new Wire(1, 1), b = new Wire(1, 1), c = new Wire(1, 10), d = new Wire(2, 1),\r
- e = new Wire(1, 1), f = new Wire(1, 1), g = new Wire(1, 1), h = new Wire(2, 1), i = new Wire(2, 1),\r
- j = new Wire(1, 1), k = new Wire(1, 1);\r
+ Wire a = new Wire(1, 1), b = new Wire(1, 1), c = new Wire(1, 10), d = new Wire(2, 1), e = new Wire(1, 1), f = new Wire(1, 1),\r
+ g = new Wire(1, 1), h = new Wire(2, 1), i = new Wire(2, 1), j = new Wire(1, 1), k = new Wire(1, 1);\r
new AndGate(1, f.createEnd(), a.createEnd(), b.createEnd());\r
new NotGate(1, f.createEnd(), g.createEnd());\r
new Merger(h.createEnd(), c.createEnd(), g.createEnd());\r
WireEnd enI = en.createEnd(), aI = a.createEnd(), bI = b.createEnd();\r
enI.feedSignals(Bit.ONE);\r
aI.feedSignals(Bit.ONE);\r
+ bI.feedSignals(Bit.Z);\r
\r
Simulation.TIMELINE.executeAll();\r
\r
void muxTest()\r
{\r
Simulation.TIMELINE.reset();\r
- Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5),\r
- out = new Wire(4, 1);\r
+ Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), out = new Wire(4, 1);\r
WireEnd selectIn = select.createEnd();\r
\r
selectIn.feedSignals(Bit.ZERO, Bit.ZERO);\r
void demuxTest()\r
{\r
Simulation.TIMELINE.reset();\r
- Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5),\r
- in = new Wire(4, 1);\r
+ Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), in = new Wire(4, 1);\r
WireEnd selectIn = select.createEnd();\r
\r
selectIn.feedSignals(Bit.ZERO, Bit.ZERO);\r
\r
assertBitArrayEquals(d.getValues(), Bit.ZERO, Bit.ONE, Bit.ONE);\r
}\r
- \r
+\r
@Test\r
void notTest()\r
{\r
void rsLatchCircuitTest()\r
{\r
Simulation.TIMELINE.reset();\r
- Wire r = new Wire(1, 1), s = new Wire(1, 1), t1 = new Wire(1, 15), t2 = new Wire(1, 1),\r
- q = new Wire(1, 1), nq = new Wire(1, 1);\r
+ Wire r = new Wire(1, 1), s = new Wire(1, 1), t1 = new Wire(1, 15), t2 = new Wire(1, 1), q = new Wire(1, 1), nq = new Wire(1, 1);\r
\r
new OrGate(1, t2.createEnd(), r.createEnd(), nq.createEnd());\r
new OrGate(1, t1.createEnd(), s.createEnd(), q.createEnd());\r
assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z);\r
}\r
\r
-// @Test\r
+ @Test\r
void wireConnections()\r
{\r
// Nur ein Experiment, was über mehrere 'passive' Bausteine hinweg passieren würde\r
cI.feedSignals(Bit.Z);\r
test.assertAfterSimulationIs(print, Bit.Z);\r
\r
- new Connector(b, c);\r
+ new Connector(b.createEnd(), c.createEnd()).connect();\r
test.assertAfterSimulationIs(print, Bit.Z);\r
System.err.println("ONE");\r
bI.feedSignals(Bit.ONE);\r
bI.feedSignals(Bit.Z);\r
test.assertAfterSimulationIs(print, Bit.Z);\r
\r
- new Connector(a, b);\r
+ new Connector(a.createEnd(), b.createEnd()).connect();\r
System.err.println("Z 2");\r
aI.feedSignals(Bit.Z);\r
test.assertAfterSimulationIs(print, Bit.Z);\r
import era.mi.logic.Simulation;
import era.mi.logic.wires.Wire;
import era.mi.logic.wires.Wire.WireEnd;
-import era.mi.logic.wires.WireArrayObserver;
+import era.mi.logic.wires.WireObserver;
-public class Connector implements WireArrayObserver
+public class Connector implements WireObserver
{
private final Wire a;
// private final WireArray b;
g.setColor(Color.BLACK);\r
break;\r
case U:\r
- g.setColor(Color.BLUE);\r
+ g.setColor(Color.MAGENTA);\r
break;\r
default:\r
throw new IllegalArgumentException();\r
{\r
if (!hasNext())\r
return -1;\r
- else\r
- return events.peek().timing;\r
+ return events.peek().timing;\r
}\r
\r
public void reset()\r
private class InnerEvent\r
{\r
\r
- private final long timing;\r
+ final long timing;\r
private final TimelineEventHandler function;\r
private final TimelineEvent event;\r
\r
return timing;\r
}\r
\r
+ @Override\r
public String toString()\r
{\r
return "timestamp: " + timing;\r
{
private Bit[] values;
public final int travelTime;
- private List<WireArrayObserver> observers = new ArrayList<WireArrayObserver>();
+ private List<WireObserver> observers = new ArrayList<WireObserver>();
public final int length;
private List<WireEnd> inputs = new ArrayList<WireEnd>();
}
/**
- * Adds an {@link WireArrayObserver}, who will be notified when the value of the {@link Wire} is updated.
+ * Adds an {@link WireObserver}, who will be notified when the value of the {@link Wire} is updated.
*
- * @param ob The {@link WireArrayObserver} to be notified of changes.
- * @return true if the given {@link WireArrayObserver} was not already registered, false otherwise
+ * @param ob The {@link WireObserver} to be notified of changes.
+ * @return true if the given {@link WireObserver} was not already registered, false otherwise
*
* @author Fabian Stemmler
*/
- public boolean addObserver(WireArrayObserver ob)
+ public boolean addObserver(WireObserver ob)
{
return observers.add(ob);
}
private void notifyObservers(Bit[] oldValues)
{
- for (WireArrayObserver o : observers)
+ for (WireObserver o : observers)
o.update(this, oldValues);
}
/**
* A {@link WireEnd} feeds a constant signal into the {@link Wire} it is tied to. The combination of all inputs determines the
- * {@link Wire}s final value. X dominates all other inputs Z does not affect the final value, unless there are no other inputs than
- * Z 0 and 1 turn into X when they are mixed
+ * {@link Wire}s final value. X dominates all other inputs Z does not affect the final value, unless there are no other inputs than Z 0
+ * and 1 turn into X when they are mixed
*
* @author Fabian Stemmler
*/
{
return inputValues[index];
}
-
+
/**
- * @return A copy (safe to modify) of the values the {@link WireEnd} is currently feeding into the associated
- * {@link Wire}.
+ * @return A copy (safe to modify) of the values the {@link WireEnd} is currently feeding into the associated {@link Wire}.
*/
public Bit[] getInputValues()
{
return getInputValues(0, length);
}
-
+
public Bit[] getInputValues(int start, int end)
{
int length = end - start;
{
return Wire.this.getValue(index);
}
-
+
/**
* @param index Index of the requested bit.
* @return The value of the indexed bit.
/**
* @param start Start of the wanted segment. (inclusive)
- * @param end End of the wanted segment. (exclusive)
- * @return The values of the segment of {@link Bit}s indexed.
+ * @param end End of the wanted segment. (exclusive)
+ * @return The values of the segment of {@link Bit}s indexed.
*
* @author Fabian Stemmler
*/
{
return Wire.this.getValues(start, end);
}
-
/**
* The {@link Wire} is interpreted as an unsigned integer with n bits.
*
- * @return <code>true</code> if all bits are either <code>Bit.ONE</code> or <code>Bit.ZERO</code> (they do not all have to have the same
- * value), not <code>Bit.X</code> or <code>Bit.Z</code>. <code>false</code> is returned otherwise.
+ * @return <code>true</code> if all bits are either <code>Bit.ONE</code> or <code>Bit.ZERO</code> (they do not all have to have the
+ * same value), not <code>Bit.X</code> or <code>Bit.Z</code>. <code>false</code> is returned otherwise.
*
* @author Fabian Stemmler
*/
{
return Wire.this.getSignedValue();
}
-
+
@Override
public String toString()
{
return Arrays.toString(values);
- //return String.format("%s \nFeeding: %s", WireArray.this.toString(), Arrays.toString(inputValues));
+ // return String.format("%s \nFeeding: %s", WireArray.this.toString(), Arrays.toString(inputValues));
}
public void disconnect()
return length;
}
- public boolean addObserver(WireArrayObserver ob)
+ public boolean addObserver(WireObserver ob)
{
return Wire.this.addObserver(ob);
}
-
+
public Wire getWire()
{
return Wire.this;
}
}
-
+
@Override
public String toString()
{
return String.format("wire 0x%08x value: %s inputs: %s", hashCode(), Arrays.toString(values), inputs);
- //Arrays.toString(values), inputs.stream().map(i -> Arrays.toString(i.inputValues)).reduce((s1, s2) -> s1 + s2)
+ // Arrays.toString(values), inputs.stream().map(i -> Arrays.toString(i.inputValues)).reduce((s1, s2) -> s1 + s2)
}
public static WireEnd[] extractEnds(Wire[] w)
+++ /dev/null
-package era.mi.logic.wires;\r
-\r
-import era.mi.logic.Bit;\r
-\r
-public interface WireArrayObserver\r
-{\r
- public void update(Wire initiator, Bit[] oldValues);\r
-}\r
--- /dev/null
+package era.mi.logic.wires;
+
+import era.mi.logic.Bit;
+
+public interface WireObserver
+{
+ public void update(Wire initiator, Bit[] oldValues);
+}