From f24856124d94ec255aabc01164cbb321dbaeeabb Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Thu, 10 Dec 2015 09:35:36 +0100
Subject: [PATCH] Reallocation by "copyOf" Renaiming variable to
 initialCapacity for the sake of better comprehension

---
 .../de/hdm_stuttgart/mi/sd1/store/IntegerStore.java  | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java b/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java
index a22874cc7..c862a482b 100644
--- a/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java
+++ b/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java
@@ -1,5 +1,7 @@
 package de.hdm_stuttgart.mi.sd1.store;
 
+import java.util.Arrays;
+
 /**
  * A container holding a fixed
  *  number of integer values.
@@ -7,7 +9,7 @@ package de.hdm_stuttgart.mi.sd1.store;
  */
 public class IntegerStore {
   
-  final static int defaultCapacity = 4;
+  final static int initialCapacity = 4;
   long[] values ;         // Array containing our values
   int numValues = 0;     // Number of values present in the container so far.
   
@@ -17,7 +19,7 @@ public class IntegerStore {
    * 
    */
   public IntegerStore() {
-    values = new long[defaultCapacity];
+    values = new long[initialCapacity];
   }
   /**
    * Create a new store being able to
@@ -56,11 +58,7 @@ public class IntegerStore {
    */
   public void addValue(long value) {
     if (values.length <= numValues) { // Sufficient capacity available to add a new value?
-      final long[] currentArray = values;
-      values = new long[2 * currentArray.length]; // Double the current array's size.
-      for (int i = 0; i < currentArray.length; i++) {
-        values[i] = currentArray[i];
-      }
+      values = Arrays.copyOf(values, 2 * values.length); // Double the current array's size.
     } 
     values[numValues++] = value; 
   }
-- 
GitLab