From afb265ffd6f34e1a374fdac1acf6a47bed3dae26 Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Fri, 17 Nov 2023 22:29:11 +0100
Subject: [PATCH] Cosmetics

---
 Doc/Sd1/Arrays/arrays.xml                     | 104 ++++++++----------
 .../hdm_stuttgart/mi/sd1/task1/_4_Filter.java |   1 -
 Klausuren/Sd1/2021winter/Exam/pom.xml         |   2 +-
 .../mi/sd1/task1/A_TrafficLight.java          |   2 +-
 .../mi/sd1/task1/A_TrafficLight.java          |   5 +-
 5 files changed, 46 insertions(+), 68 deletions(-)

diff --git a/Doc/Sd1/Arrays/arrays.xml b/Doc/Sd1/Arrays/arrays.xml
index dea7baf82..757c12c47 100644
--- a/Doc/Sd1/Arrays/arrays.xml
+++ b/Doc/Sd1/Arrays/arrays.xml
@@ -3269,7 +3269,7 @@ public static boolean isPrime(final long candidate) {
 
             <para>Obtaining the median requires ordering these values:</para>
 
-            <screen>-3, 0, 2, 4, 7</screen>
+            <screen>-3, 0, <emphasis role="red">2</emphasis>, 4, 7</screen>
 
             <para>Thus the given sample's median is 2. Solve this exercise in
             the following order:</para>
@@ -3297,7 +3297,8 @@ public int[] getValues() {
                   <para>You may either construct a suitable copy containing
                   the current elements yourself or get enlightened by reading
                   the <xref linkend="glo_API"/> documentation of <link
-                  xlink:href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Arrays.html#copyOfRange(int%5B%5D,int,int)">copyOfRange(...)</link>.</para>
+                  xlink:href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Arrays.html#copyOfRange(int%5B%5D,int,int)">copyOfRange(...)</link>
+                  doing your job instead.</para>
                 </caution>
               </listitem>
 
@@ -3335,63 +3336,45 @@ for (final int i: unsortedValues) {
                 xlink:href="P/Sd1/Array/integerStoreStat/target/site/apidocs/de/hdm_stuttgart/mi/sd1/store/IntegerStore.html#addValue(int)">
                 addValue(...)</methodname> method's implementation. Though
                 there are more elaborate sorting methods available in Java
-                we'll do it the hard way ourselves in this exercise. Consider
-                the following example:</para>
-
-                <programlisting language="java">store.addValue(1);
-store.addValue(2);
-store.addValue(7);
-store.addValue(9);
-store.addValue(3);</programlisting>
-
-                <para>Prior to inserting a new value our <methodname
+                we'll do it the hard way ourselves here. We intend to insert
+                new values at the »right« position to always keep the array
+                sorted. Consider the following sequence:</para>
+
+                <informaltable border="1">
+                  <tr>
+                    <th>Code</th>
+
+                    <th>Internal array of values</th>
+                  </tr>
+
+                  <tr>
+                    <td valign="top"><programlisting language="none">store.addValue(<emphasis
+                          role="red">1</emphasis>);
+store.addValue(<emphasis role="red">3</emphasis>);
+store.addValue(<emphasis role="red">9</emphasis>);
+store.addValue(<emphasis role="red">7</emphasis>);
+store.addValue(<emphasis role="red">2</emphasis>);</programlisting></td>
+
+                    <td valign="top"><screen>{<emphasis role="red">1</emphasis>}
+{1, <emphasis role="red">3</emphasis>}
+{1, 3, <emphasis role="red">9</emphasis>}
+{1, 3, <emphasis role="red">7</emphasis>, 9}
+{1, <emphasis role="red">2</emphasis>, 3, 7, 9}</screen></td>
+                  </tr>
+                </informaltable>
+
+                <para>The <methodname
                 xlink:href="P/Sd1/Array/integerStoreStat/target/site/apidocs/de/hdm_stuttgart/mi/sd1/store/IntegerStore.html#addValue(int)">addValue(...)</methodname>
-                method shall find a suitable position inside the array of
-                already added values to insert the new value. When adding the
-                last value 3 in the above example the internal array already
-                contains the values (1, 2, 7, 9). Traversing this array shows
-                that the new value of 3 should be inserted between 2 and
-                7.</para>
-
-                <para>Thus a general strategy inserting a new value candidate
-                might be:</para>
-
-                <orderedlist>
-                  <listitem>
-                    <para>Find the first index pointing to an existing value
-                    being larger or equal to the given candidate. In the above
-                    example this index value is 2 pointing to value 7.</para>
-
-                    <para>If there is no such existing value just add the new
-                    value at the array's top end like you did before when not
-                    yet bothering about sorting.</para>
-                  </listitem>
-
-                  <listitem>
-                    <para>Shift the <quote>right</quote> part of the array
-                    starting at index 2 in our example one position to the
-                    right thus creating a free (denoted by <quote>F</quote>)
-                    insert position:</para>
-
-                    <screen>Index values     | 0| 1| 2| 3| 4| 5| ...
------------------+--+--+--+--+-----+ ...
-values oldArray  | 1| 2| 7| 9|  |  |
------------------+--+--+--+--+-----+ ...
-values newArray  | 1| 2| F| 7| 9|  | ...</screen>
-
-                    <para>You may now insert your latest value 3 at the free
-                    index position 2 ending up with a well sorted array (1, 2,
-                    3, 7, 9).</para>
-
-                    <para>This example just illustrates a (very simple!)
-                    sorting algorithm.</para>
-
-                    <para>Hint: On implementation be very careful with respect
-                    to <quote>off by one</quote> errors you are likely to
-                    encounter. The tests you have written beforehand will
-                    guide you.</para>
-                  </listitem>
-                </orderedlist>
+                method now provides a sorting compatible position for
+                inserting. When adding the last value 2 the internal array
+                already contains the sorted values (1, 3, 7, 9). Traversing
+                this array shows that the new value of 2 should be inserted
+                between 1 and 3 and thus at array index 1. The remaining three
+                values 3,7 and 9 each have to be shifted one position to the
+                right.</para>
+
+                <para>This way our sequence of values always remains
+                sorted.</para>
               </listitem>
 
               <listitem>
@@ -3416,9 +3399,8 @@ values newArray  | 1| 2| F| 7| 9|  | ...</screen>
               <listitem>
                 <para>Finally complete the desired <code
                 language="java">double getMedian()</code> method's
-                implementation and actually test it. There must be at least
-                one element in order to be able returning a meaningful
-                result:</para>
+                implementation and actually test it. Returning a meaningful
+                result requires at least one element:</para>
 
                 <programlisting language="java">/**
  * &lt;dl&gt;
diff --git a/Klausuren/Sd1/2021summer/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Filter.java b/Klausuren/Sd1/2021summer/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Filter.java
index 617899a1c..4c458cc4c 100644
--- a/Klausuren/Sd1/2021summer/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Filter.java
+++ b/Klausuren/Sd1/2021summer/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Filter.java
@@ -49,7 +49,6 @@ public class _4_Filter {
      * @param values An array of strings
      * @param filter A string intended to filter the given array of values.
      * @return An array of just those values containing the filter value as a substring.
-     *
      */
     static public String[] filter(final String[] values, final String filter) {
 
diff --git a/Klausuren/Sd1/2021winter/Exam/pom.xml b/Klausuren/Sd1/2021winter/Exam/pom.xml
index 82d6a05bd..5a6874912 100644
--- a/Klausuren/Sd1/2021winter/Exam/pom.xml
+++ b/Klausuren/Sd1/2021winter/Exam/pom.xml
@@ -7,7 +7,7 @@
     <version>0.9</version>
     <packaging>jar</packaging>
 
-    <name>sd1_2021winter_solve</name>
+    <name>sd1_2021winter_exam</name>
 
     <url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url>
 
diff --git a/Klausuren/Sd1/2021winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java b/Klausuren/Sd1/2021winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java
index c94ac78bd..eb4c393dc 100644
--- a/Klausuren/Sd1/2021winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java
+++ b/Klausuren/Sd1/2021winter/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java
@@ -1,7 +1,7 @@
 package de.hdm_stuttgart.mi.sd1.task1;
 
 /**
- * <p>Stop and go at trafficlights.</p>
+ * <p>Stop and go at german traffic lights.</p>
  */
 public class A_TrafficLight {
     /**
diff --git a/Klausuren/Sd1/2021winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java b/Klausuren/Sd1/2021winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java
index fff60a3b2..56712f0c0 100644
--- a/Klausuren/Sd1/2021winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java
+++ b/Klausuren/Sd1/2021winter/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/A_TrafficLight.java
@@ -48,7 +48,6 @@ public class A_TrafficLight {
      *         <td>Go</td>
      *         <td>Stop</td>
      *     </tr>
-     *
      * </table>
      *
      * @param red <code>true</code> represents »on«, <code>false</code> represents »off«.
@@ -58,9 +57,7 @@ public class A_TrafficLight {
      * @return <code>true</code> represents »you must stop«, <code>false</code> represents »go«.
      */
     static public boolean mustStop(boolean red, boolean yellow, boolean green) {
-        return (red && !yellow) || (yellow && !red);
+        return red ^ yellow; // red ^ yellow is equivalent to (red & !yellow) || (yellow & !red)
     }
-
     private A_TrafficLight(){/* Ignore me: My sole purpose is suppressing default constructor javadoc generation */}
-
 }
-- 
GitLab