From: Fabian Stemmler Date: Mon, 20 May 2019 12:03:38 +0000 (+0200) Subject: Merge logic of origin into logic X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=b1e7855af2dfc15b4d6c1253dd77db02925162f3;p=Mograsim.git Merge logic of origin into logic Conflicts: era.mi/src/era/mi/logic/components/BitDisplay.java era.mi/src/era/mi/logic/components/Clock.java era.mi/src/era/mi/logic/components/Demux.java era.mi/src/era/mi/logic/components/Merger.java era.mi/src/era/mi/logic/components/Mux.java era.mi/src/era/mi/logic/components/TriStateBuffer.java era.mi/src/era/mi/logic/components/gates/NotGate.java era.mi/src/era/mi/logic/tests/Connector.java era.mi/src/era/mi/logic/tests/GUITest.java era.mi/src/era/mi/logic/wires/WireArray.java --- diff --git a/era.mi/.settings/org.eclipse.jdt.core.prefs b/era.mi/.settings/org.eclipse.jdt.core.prefs index fd071d58..82c6671b 100644 --- a/era.mi/.settings/org.eclipse.jdt.core.prefs +++ b/era.mi/.settings/org.eclipse.jdt.core.prefs @@ -15,6 +15,7 @@ org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false org.eclipse.jdt.core.formatter.align_with_spaces=false +org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 @@ -23,20 +24,27 @@ org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16 org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 +org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16 org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0 org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0 +org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 @@ -81,6 +89,7 @@ org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false org.eclipse.jdt.core.formatter.comment.indent_root_tags=false +org.eclipse.jdt.core.formatter.comment.indent_tag_description=false org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert org.eclipse.jdt.core.formatter.comment.line_length=140 @@ -128,11 +137,13 @@ org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert @@ -163,6 +174,8 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert @@ -187,13 +200,18 @@ org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert @@ -241,6 +259,8 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do no org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert @@ -277,9 +297,12 @@ org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not inser org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert @@ -291,13 +314,24 @@ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_decla org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.join_lines_in_comments=true org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false +org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never org.eclipse.jdt.core.formatter.lineSplit=140 org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false @@ -318,9 +352,16 @@ org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.use_on_off_tags=true org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true +org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true +org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true +org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true +org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter diff --git a/era.mi/.settings/org.eclipse.jdt.ui.prefs b/era.mi/.settings/org.eclipse.jdt.ui.prefs index f5705df7..07b37c11 100644 --- a/era.mi/.settings/org.eclipse.jdt.ui.prefs +++ b/era.mi/.settings/org.eclipse.jdt.ui.prefs @@ -1,3 +1,63 @@ eclipse.preferences.version=1 -formatter_profile=_MyPrefrence -formatter_settings_version=14 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_ERA-MI +formatter_settings_version=16 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=false +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=true +sp_cleanup.convert_to_enhanced_for_loop=true +sp_cleanup.correct_indentation=true +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.make_local_variable_final=true +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=true +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=false +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=true +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_modifiers=true +sp_cleanup.remove_redundant_semicolons=true +sp_cleanup.remove_redundant_type_arguments=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=true +sp_cleanup.remove_unused_imports=true +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=true +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=true +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=true +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/era.mi/src/era/mi/logic/Simulation.java b/era.mi/src/era/mi/logic/Simulation.java index f4b25d2d..0468ec1e 100644 --- a/era.mi/src/era/mi/logic/Simulation.java +++ b/era.mi/src/era/mi/logic/Simulation.java @@ -6,7 +6,4 @@ public class Simulation { public final static Timeline TIMELINE = new Timeline(11); - public static void main(String[] args) - { - } } \ No newline at end of file diff --git a/era.mi/src/era/mi/logic/components/BasicComponent.java b/era.mi/src/era/mi/logic/components/BasicComponent.java index 510765c4..7cebc606 100644 --- a/era.mi/src/era/mi/logic/components/BasicComponent.java +++ b/era.mi/src/era/mi/logic/components/BasicComponent.java @@ -3,14 +3,14 @@ package era.mi.logic.components; import era.mi.logic.Bit; import era.mi.logic.Simulation; import era.mi.logic.wires.Wire; -import era.mi.logic.wires.WireArrayObserver; +import era.mi.logic.wires.WireObserver; /** * A basic component that recomputes all outputs (with a delay), when it is updated. * * @author Fabian Stemmler */ -public abstract class BasicComponent implements WireArrayObserver, Component +public abstract class BasicComponent implements WireObserver, Component { private int processTime; @@ -28,10 +28,7 @@ public abstract class BasicComponent implements WireArrayObserver, Component @Override public void update(Wire initiator, Bit[] oldValues) { - Simulation.TIMELINE.addEvent((e) -> - { - compute(); - }, processTime); + Simulation.TIMELINE.addEvent(e -> compute(), processTime); } protected abstract void compute(); diff --git a/era.mi/src/era/mi/logic/components/BitDisplay.java b/era.mi/src/era/mi/logic/components/BitDisplay.java index 5ddae967..88a10531 100644 --- a/era.mi/src/era/mi/logic/components/BitDisplay.java +++ b/era.mi/src/era/mi/logic/components/BitDisplay.java @@ -1,8 +1,6 @@ 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; @@ -40,12 +38,12 @@ public class BitDisplay extends BasicComponent @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(in)); + return List.of(in); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(new ArrayList()); + return List.of(); } } diff --git a/era.mi/src/era/mi/logic/components/Clock.java b/era.mi/src/era/mi/logic/components/Clock.java index 34f49374..d6386172 100644 --- a/era.mi/src/era/mi/logic/components/Clock.java +++ b/era.mi/src/era/mi/logic/components/Clock.java @@ -1,7 +1,5 @@ package era.mi.logic.components; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import era.mi.logic.Bit; @@ -33,7 +31,7 @@ public class Clock implements TimelineEventHandler, Component public void handle(TimelineEvent e) { addToTimeline(); - out.feedSignals(new Bit[] { toggle ? Bit.ONE : Bit.ZERO }); + out.feedSignals(toggle ? Bit.ONE : Bit.ZERO); toggle = !toggle; } @@ -50,12 +48,12 @@ public class Clock implements TimelineEventHandler, Component @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList()); + return List.of(); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } } diff --git a/era.mi/src/era/mi/logic/components/Connector.java b/era.mi/src/era/mi/logic/components/Connector.java new file mode 100644 index 00000000..47cf901f --- /dev/null +++ b/era.mi/src/era/mi/logic/components/Connector.java @@ -0,0 +1,75 @@ +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 getAllInputs() + { + return List.of(a, b); + } + + @Override + public List getAllOutputs() + { + return List.of(a, b); + } +} diff --git a/era.mi/src/era/mi/logic/components/Demux.java b/era.mi/src/era/mi/logic/components/Demux.java index 4f06728a..147dd7fe 100644 --- a/era.mi/src/era/mi/logic/components/Demux.java +++ b/era.mi/src/era/mi/logic/components/Demux.java @@ -1,7 +1,5 @@ package era.mi.logic.components; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import era.mi.logic.wires.Wire; @@ -22,11 +20,11 @@ public class Demux extends BasicComponent private int selected = -1; /** - * Input {@link Wire}s and out must be of uniform length + * Output {@link Wire}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, WireEnd in, WireEnd select, WireEnd... outputs) { @@ -71,12 +69,12 @@ public class Demux extends BasicComponent @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(in, select)); + return List.of(in, select); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(outputs)); + return List.of(outputs); } } diff --git a/era.mi/src/era/mi/logic/components/Merger.java b/era.mi/src/era/mi/logic/components/Merger.java index 225a35a9..613d5239 100644 --- a/era.mi/src/era/mi/logic/components/Merger.java +++ b/era.mi/src/era/mi/logic/components/Merger.java @@ -1,15 +1,13 @@ package era.mi.logic.components; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import era.mi.logic.Bit; 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 Merger implements WireArrayObserver, Component +public class Merger implements WireObserver, Component { private WireEnd out; private WireEnd[] inputs; @@ -73,12 +71,12 @@ public class Merger implements WireArrayObserver, Component @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(inputs)); + return List.of(inputs); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } } diff --git a/era.mi/src/era/mi/logic/components/Mux.java b/era.mi/src/era/mi/logic/components/Mux.java index 0cb4e383..aea71166 100644 --- a/era.mi/src/era/mi/logic/components/Mux.java +++ b/era.mi/src/era/mi/logic/components/Mux.java @@ -88,6 +88,6 @@ public class Mux extends BasicComponent @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } } diff --git a/era.mi/src/era/mi/logic/components/Splitter.java b/era.mi/src/era/mi/logic/components/Splitter.java index 127f70d1..be8be820 100644 --- a/era.mi/src/era/mi/logic/components/Splitter.java +++ b/era.mi/src/era/mi/logic/components/Splitter.java @@ -3,9 +3,9 @@ package era.mi.logic.components; import era.mi.logic.Bit; 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 Splitter implements WireArrayObserver +public class Splitter implements WireObserver { private WireEnd input; private WireEnd[] outputs; diff --git a/era.mi/src/era/mi/logic/components/TriStateBuffer.java b/era.mi/src/era/mi/logic/components/TriStateBuffer.java index 2b72bad4..920c2ec0 100644 --- a/era.mi/src/era/mi/logic/components/TriStateBuffer.java +++ b/era.mi/src/era/mi/logic/components/TriStateBuffer.java @@ -1,11 +1,8 @@ package era.mi.logic.components; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import era.mi.logic.Bit; -import era.mi.logic.wires.Wire; import era.mi.logic.wires.Wire.WireEnd; public class TriStateBuffer extends BasicComponent @@ -40,13 +37,13 @@ public class TriStateBuffer extends BasicComponent @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(in, enable)); + return List.of(in, enable); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } } diff --git a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java index 7a6d4388..0a9340c8 100644 --- a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java +++ b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java @@ -1,7 +1,5 @@ package era.mi.logic.components.gates; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import era.mi.logic.Bit; @@ -35,15 +33,16 @@ public abstract class MultiInputGate extends BasicComponent @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(in)); + return List.of(in); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } + @Override protected void compute() { Bit[] result = in[0].getValues(); diff --git a/era.mi/src/era/mi/logic/components/gates/NotGate.java b/era.mi/src/era/mi/logic/components/gates/NotGate.java index f65a174c..6829dc3a 100644 --- a/era.mi/src/era/mi/logic/components/gates/NotGate.java +++ b/era.mi/src/era/mi/logic/components/gates/NotGate.java @@ -1,7 +1,5 @@ package era.mi.logic.components.gates; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import era.mi.logic.Util; @@ -40,12 +38,12 @@ public class NotGate extends BasicComponent @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(in)); + return List.of(in); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } } diff --git a/era.mi/src/era/mi/logic/tests/ComponentTest.java b/era.mi/src/era/mi/logic/tests/ComponentTest.java index 398c18fe..c14fd01d 100644 --- a/era.mi/src/era/mi/logic/tests/ComponentTest.java +++ b/era.mi/src/era/mi/logic/tests/ComponentTest.java @@ -1,6 +1,9 @@ package era.mi.logic.tests; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; import java.util.function.LongConsumer; @@ -9,6 +12,7 @@ import org.junit.jupiter.api.Test; import era.mi.logic.Bit; import era.mi.logic.Simulation; +import era.mi.logic.components.Connector; import era.mi.logic.components.Demux; import era.mi.logic.components.Merger; import era.mi.logic.components.Mux; @@ -21,6 +25,7 @@ import era.mi.logic.components.gates.XorGate; import era.mi.logic.wires.Wire; import era.mi.logic.wires.Wire.WireEnd; +@SuppressWarnings("unused") class ComponentTest { @@ -28,9 +33,8 @@ class ComponentTest void circuitExampleTest() { Simulation.TIMELINE.reset(); - 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), 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); + 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), + 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); new AndGate(1, f.createEnd(), a.createEnd(), b.createEnd()); new NotGate(1, f.createEnd(), g.createEnd()); new Merger(h.createEnd(), c.createEnd(), g.createEnd()); @@ -92,6 +96,7 @@ class ComponentTest WireEnd enI = en.createEnd(), aI = a.createEnd(), bI = b.createEnd(); enI.feedSignals(Bit.ONE); aI.feedSignals(Bit.ONE); + bI.feedSignals(Bit.Z); Simulation.TIMELINE.executeAll(); @@ -117,8 +122,7 @@ class ComponentTest void muxTest() { Simulation.TIMELINE.reset(); - 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); + 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); WireEnd selectIn = select.createEnd(); selectIn.feedSignals(Bit.ZERO, Bit.ZERO); @@ -145,8 +149,7 @@ class ComponentTest void demuxTest() { Simulation.TIMELINE.reset(); - 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); + 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); WireEnd selectIn = select.createEnd(); selectIn.feedSignals(Bit.ZERO, Bit.ZERO); @@ -216,7 +219,7 @@ class ComponentTest assertBitArrayEquals(d.getValues(), Bit.ZERO, Bit.ONE, Bit.ONE); } - + @Test void notTest() { @@ -234,8 +237,7 @@ class ComponentTest void rsLatchCircuitTest() { Simulation.TIMELINE.reset(); - 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); + 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); new OrGate(1, t2.createEnd(), r.createEnd(), nq.createEnd()); new OrGate(1, t1.createEnd(), s.createEnd(), q.createEnd()); @@ -305,7 +307,7 @@ class ComponentTest assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z); } -// @Test + @Test void wireConnections() { // Nur ein Experiment, was über mehrere 'passive' Bausteine hinweg passieren würde @@ -333,7 +335,7 @@ class ComponentTest cI.feedSignals(Bit.Z); test.assertAfterSimulationIs(print, Bit.Z); - new Connector(b, c); + new Connector(b.createEnd(), c.createEnd()).connect(); test.assertAfterSimulationIs(print, Bit.Z); System.err.println("ONE"); bI.feedSignals(Bit.ONE); @@ -345,7 +347,7 @@ class ComponentTest bI.feedSignals(Bit.Z); test.assertAfterSimulationIs(print, Bit.Z); - new Connector(a, b); + new Connector(a.createEnd(), b.createEnd()).connect(); System.err.println("Z 2"); aI.feedSignals(Bit.Z); test.assertAfterSimulationIs(print, Bit.Z); diff --git a/era.mi/src/era/mi/logic/tests/Connector.java b/era.mi/src/era/mi/logic/tests/Connector.java index 12c407a5..39645bfc 100644 --- a/era.mi/src/era/mi/logic/tests/Connector.java +++ b/era.mi/src/era/mi/logic/tests/Connector.java @@ -4,9 +4,9 @@ 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.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; diff --git a/era.mi/src/era/mi/logic/tests/GUITest.java b/era.mi/src/era/mi/logic/tests/GUITest.java index 2599b542..b8c4937d 100644 --- a/era.mi/src/era/mi/logic/tests/GUITest.java +++ b/era.mi/src/era/mi/logic/tests/GUITest.java @@ -241,7 +241,7 @@ public class GUITest extends JPanel g.setColor(Color.BLACK); break; case U: - g.setColor(Color.BLUE); + g.setColor(Color.MAGENTA); break; default: throw new IllegalArgumentException(); diff --git a/era.mi/src/era/mi/logic/timeline/Timeline.java b/era.mi/src/era/mi/logic/timeline/Timeline.java index 63d73950..8107db96 100644 --- a/era.mi/src/era/mi/logic/timeline/Timeline.java +++ b/era.mi/src/era/mi/logic/timeline/Timeline.java @@ -90,8 +90,7 @@ public class Timeline { if (!hasNext()) return -1; - else - return events.peek().timing; + return events.peek().timing; } public void reset() @@ -127,7 +126,7 @@ public class Timeline private class InnerEvent { - private final long timing; + final long timing; private final TimelineEventHandler function; private final TimelineEvent event; diff --git a/era.mi/src/era/mi/logic/timeline/TimelineEvent.java b/era.mi/src/era/mi/logic/timeline/TimelineEvent.java index b3eec8ca..46decf5f 100644 --- a/era.mi/src/era/mi/logic/timeline/TimelineEvent.java +++ b/era.mi/src/era/mi/logic/timeline/TimelineEvent.java @@ -22,6 +22,7 @@ public class TimelineEvent return timing; } + @Override public String toString() { return "timestamp: " + timing; diff --git a/era.mi/src/era/mi/logic/wires/Wire.java b/era.mi/src/era/mi/logic/wires/Wire.java index 5eac8894..d85fc206 100644 --- a/era.mi/src/era/mi/logic/wires/Wire.java +++ b/era.mi/src/era/mi/logic/wires/Wire.java @@ -19,7 +19,7 @@ public class Wire { private Bit[] values; public final int travelTime; - private List observers = new ArrayList(); + private List observers = new ArrayList(); public final int length; private List inputs = new ArrayList(); @@ -182,21 +182,21 @@ public class Wire } /** - * 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); } @@ -215,8 +215,8 @@ public class Wire /** * 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 */ @@ -299,16 +299,15 @@ public class Wire { 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; @@ -359,7 +358,7 @@ public class Wire { return Wire.this.getValue(index); } - + /** * @param index Index of the requested bit. * @return The value of the indexed bit. @@ -373,8 +372,8 @@ public class Wire /** * @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 */ @@ -382,13 +381,12 @@ public class Wire { return Wire.this.getValues(start, end); } - /** * The {@link Wire} is interpreted as an unsigned integer with n bits. * - * @return true if all bits are either Bit.ONE or Bit.ZERO (they do not all have to have the same - * value), not Bit.X or Bit.Z. false is returned otherwise. + * @return true if all bits are either Bit.ONE or Bit.ZERO (they do not all have to have the + * same value), not Bit.X or Bit.Z. false is returned otherwise. * * @author Fabian Stemmler */ @@ -420,12 +418,12 @@ public class Wire { 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() @@ -439,22 +437,22 @@ public class Wire 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) diff --git a/era.mi/src/era/mi/logic/wires/WireArrayObserver.java b/era.mi/src/era/mi/logic/wires/WireArrayObserver.java deleted file mode 100644 index 7d915f6a..00000000 --- a/era.mi/src/era/mi/logic/wires/WireArrayObserver.java +++ /dev/null @@ -1,8 +0,0 @@ -package era.mi.logic.wires; - -import era.mi.logic.Bit; - -public interface WireArrayObserver -{ - public void update(Wire initiator, Bit[] oldValues); -} diff --git a/era.mi/src/era/mi/logic/wires/WireObserver.java b/era.mi/src/era/mi/logic/wires/WireObserver.java new file mode 100644 index 00000000..65769565 --- /dev/null +++ b/era.mi/src/era/mi/logic/wires/WireObserver.java @@ -0,0 +1,8 @@ +package era.mi.logic.wires; + +import era.mi.logic.Bit; + +public interface WireObserver +{ + public void update(Wire initiator, Bit[] oldValues); +}