소스 검색

first commit

Leon 6 년 전
커밋
eee72a3c97
5개의 변경된 파일468개의 추가작업 그리고 0개의 파일을 삭제
  1. 115
    0
      .gitignore
  2. 245
    0
      README.md
  3. 19
    0
      pom.xml
  4. 35
    0
      src/main/java/com/zipcodewilmington/StringArrayUtils.java
  5. 54
    0
      src/test/java/com/zipcodewilmington/StringArrayUtilsTest.java

+ 115
- 0
.gitignore 파일 보기

1
+# Created by .ignore support plugin (hsz.mobi)
2
+### Java template
3
+# Compiled class file
4
+*.class
5
+
6
+# Log file
7
+*.log
8
+
9
+# BlueJ files
10
+*.ctxt
11
+
12
+# Mobile Tools for Java (J2ME)
13
+.mtj.tmp/
14
+
15
+# Package Files #
16
+*.jar
17
+*.war
18
+*.ear
19
+*.zip
20
+*.tar.gz
21
+*.rar
22
+
23
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24
+hs_err_pid*
25
+### Eclipse template
26
+
27
+.metadata
28
+bin/
29
+tmp/
30
+*.tmp
31
+*.bak
32
+*.swp
33
+*~.nib
34
+local.properties
35
+.settings/
36
+.loadpath
37
+.recommenders
38
+
39
+# Eclipse Core
40
+.project
41
+
42
+# External tool builders
43
+.externalToolBuilders/
44
+
45
+# Locally stored "Eclipse launch configurations"
46
+*.launch
47
+
48
+# PyDev specific (Python IDE for Eclipse)
49
+*.pydevproject
50
+
51
+# CDT-specific (C/C++ Development Tooling)
52
+.cproject
53
+
54
+# JDT-specific (Eclipse Java Development Tools)
55
+.classpath
56
+
57
+# Java annotation processor (APT)
58
+.factorypath
59
+
60
+# PDT-specific (PHP Development Tools)
61
+.buildpath
62
+
63
+# sbteclipse plugin
64
+.target
65
+
66
+# Tern plugin
67
+.tern-project
68
+
69
+# TeXlipse plugin
70
+.texlipse
71
+
72
+# STS (Spring Tool Suite)
73
+.springBeans
74
+
75
+# Code Recommenders
76
+.recommenders/
77
+
78
+# Scala IDE specific (Scala & Java development for Eclipse)
79
+.cache-main
80
+.scala_dependencies
81
+.worksheet
82
+### macOS template
83
+*.DS_Store
84
+.AppleDouble
85
+.LSOverride
86
+
87
+# Icon must end with two \r
88
+Icon
89
+
90
+
91
+# Thumbnails
92
+._*
93
+
94
+# Files that might appear in the root of a volume
95
+.DocumentRevisions-V100
96
+.fseventsd
97
+.Spotlight-V100
98
+.TemporaryItems
99
+.Trashes
100
+.VolumeIcon.icns
101
+.com.apple.timemachine.donotpresent
102
+
103
+# Directories potentially created on remote AFP share
104
+.AppleDB
105
+.AppleDesktop
106
+Network Trash Folder
107
+Temporary Items
108
+.apdisk
109
+
110
+#Intellij files
111
+.idea
112
+*.iml
113
+
114
+#maven build target
115
+target/

+ 245
- 0
README.md 파일 보기

1
+## Building Utility Class for String Array Objects
2
+* **Objective**
3
+    * To complete the utility methods in the class [StringArrayUtils]()
4
+        * `int getNumberOfOccurrences(String[] stringArray, String stringToCheck)`
5
+        * `boolean contains(String[] stringArray, String stringToCheck)`
6
+        * `String[] removeValue(String[] stringArray, String stringToRemove)`
7
+        
8
+* **Purpose**
9
+    * To establish greater familiarity with loops and arrays.
10
+    * To demonstrate the implementation of a [Utility class](https://www.quora.com/What-is-a-utility-class)
11
+    
12
+    
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+<br><br><br><br>
21
+## Sample Behavior - `StringArrayUtils.removeValues(array, valueToRemove)`
22
+* **Description**
23
+    * Given an array of `String` objects named `array` and a `String` object named `valueToRemove`<br>create and return an array containing identical contents excluding objects whose value is equivalent to `valueToRemove`. Ensure that the length of the newly created array has been resized based on the removal of the undesired elements. 
24
+        
25
+### Example 1
26
+* Sample Script
27
+
28
+    ```
29
+    // : Given
30
+    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
31
+    
32
+    // : When
33
+    String[] actual = StringArrayUtils.removeValues(array, "aba");
34
+    
35
+    // : Then
36
+    System.out.println(Arrays.toString(actual));
37
+    ```
38
+
39
+
40
+
41
+* Sample Output
42
+    ```
43
+    [baa, bab, bba, bba, bba, bba, bbb, bbb};
44
+    ```
45
+    
46
+    
47
+
48
+### Example 2
49
+* Sample Script
50
+
51
+    ```
52
+    // : Given
53
+    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
54
+    
55
+    // : When
56
+    String[] actual = StringArrayUtils.removeValues(array, "bba");
57
+    
58
+    // : Then
59
+    System.out.println(Arrays.toString(actual));
60
+    ```
61
+
62
+
63
+
64
+* Sample Output
65
+    ```
66
+    [aba, aba, baa, bab, bbb, bbb];
67
+    ```
68
+    
69
+    
70
+
71
+### Example 3
72
+* Sample Script
73
+
74
+    ```
75
+    // : Given
76
+    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
77
+    
78
+    // : When
79
+    String[] actual = StringArrayUtils.removeValues(array, "bbb");
80
+    
81
+    // : Then
82
+    System.out.println(Arrays.toString(actual));
83
+    ```
84
+
85
+
86
+
87
+* Sample Output
88
+    ```
89
+    [aba, aba, baa, bab, bba, bba, bba, bba];
90
+    ```
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+<br><br><br><br>
107
+## Sample Behavior - `StringArrayUtils.getNumberOfOccurrences(array, value)`
108
+* **Method Description**
109
+    * Given an array of `String` objects named `array` and a `String` object named `value`<br>return the number of times `value` appears in `arrays`
110
+
111
+### Example 1
112
+* Sample Script
113
+
114
+    ```
115
+    // : Given
116
+    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
117
+    
118
+    // : When
119
+    int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bba");
120
+    
121
+    // : Then
122
+    System.out.println(numberOfOccurrences);
123
+    ```
124
+
125
+
126
+
127
+* Sample Output
128
+
129
+    ```
130
+    4
131
+    ```
132
+    
133
+    
134
+    
135
+
136
+### Example 2
137
+* Sample Script
138
+
139
+    ```
140
+    // : Given
141
+    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
142
+    
143
+    // : When
144
+    int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bbb");
145
+    
146
+    // : Then
147
+    System.out.println(numberOfOccurrences);
148
+    ```
149
+
150
+
151
+
152
+* Sample Output
153
+
154
+    ```
155
+    2
156
+    ```
157
+    
158
+
159
+### Example 3
160
+* Sample Script
161
+
162
+    ```
163
+    // : Given
164
+    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
165
+    
166
+    // : When
167
+    int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "baa");
168
+    
169
+    // : Then
170
+    System.out.println(numberOfOccurrences);
171
+    ```
172
+
173
+
174
+
175
+* Sample Output
176
+
177
+    ```
178
+    1
179
+    ```
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+<br><br><br><br>
198
+## Sample Behavior - `StringArrayUtils.contains(array, value)`
199
+
200
+### Example 1
201
+* Sample Script
202
+
203
+    ```
204
+    // : Given
205
+    String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
206
+    
207
+    // : When
208
+    boolean outcome = StringArrayUtils.contains(array, "the");
209
+    
210
+    // : Then
211
+    System.out.println(outcome);
212
+    ```
213
+
214
+
215
+
216
+* Sample Output
217
+
218
+    ```
219
+    true
220
+    ```
221
+    
222
+    
223
+    
224
+
225
+### Example 2
226
+* Sample Script
227
+
228
+    ```
229
+    // : Given
230
+    String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
231
+    
232
+    // : When
233
+    boolean outcome = StringArrayUtils.contains(array, "potatoes");
234
+    
235
+    // : Then
236
+    System.out.println(outcome);
237
+    ```
238
+
239
+
240
+
241
+* Sample Output
242
+
243
+    ```
244
+    false
245
+    ```

+ 19
- 0
pom.xml 파일 보기

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcodewilmington.labs</groupId>
8
+    <artifactId>arrayutils</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>4.12</version>
15
+        </dependency>
16
+    </dependencies>
17
+
18
+
19
+</project>

+ 35
- 0
src/main/java/com/zipcodewilmington/StringArrayUtils.java 파일 보기

1
+package com.zipcodewilmington;
2
+
3
+/**
4
+ * Created by leon on 1/29/18.
5
+ */
6
+public class StringArrayUtils {
7
+    /**
8
+     * @param array - array of String objects
9
+     * @param value - value to check array for
10
+     * @return - number of occurrences the specified `value` has occurred
11
+     */ // TODO
12
+    public static int getNumberOfOccurrences(String[] array, String value) {
13
+        return 0;
14
+    }
15
+
16
+    /**
17
+     * @param array - array of String objects
18
+     * @param value - value to check array for
19
+     * @return - true if the array contains the specified `value`
20
+     */
21
+    public static boolean contains(String[] array, String value) {
22
+        return false;
23
+    }
24
+
25
+
26
+    /**
27
+     * @param array - array of String objects
28
+     * @param valueToRemove - value to remove from array
29
+     * @return - array with identical contents excluding values of `value`
30
+     */
31
+
32
+    public static String[] removeValue(String[] array, String valueToRemove) {
33
+        return null;
34
+    }
35
+}

+ 54
- 0
src/test/java/com/zipcodewilmington/StringArrayUtilsTest.java 파일 보기

1
+package com.zipcodewilmington;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * Created by leon on 1/29/18.
8
+ */
9
+public class StringArrayUtilsTest {
10
+    private static final String[] testArray = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
11
+
12
+    @Test
13
+    public void testContains() {
14
+        for (String s : testArray) {
15
+            boolean outcome = StringArrayUtils.contains(testArray, s);
16
+            Assert.assertTrue(outcome);
17
+        }
18
+    }
19
+
20
+    @Test
21
+    public void testRemoveValue() {
22
+        String[] expected = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
23
+        String[] actual = StringArrayUtils.removeValue(expected, "The");
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void testRemoveValue1() {
29
+        String[] expected = {"the", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
30
+        String[] actual = StringArrayUtils.removeValue(expected, "quick");
31
+        Assert.assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void testRemoveValue2() {
36
+        String[] expected = {"the", "quick", "fox", "jumps", "over", "the", "lazy", "dog"};
37
+        String[] actual = StringArrayUtils.removeValue(expected, "brown");
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+    @Test
42
+    public void testGetNumberOfOccurrences1() {
43
+        int expected = 2;
44
+        int actual = StringArrayUtils.getNumberOfOccurrences(testArray, "the");
45
+        Assert.assertEquals(expected, actual);
46
+    }
47
+
48
+    @Test
49
+    public void testGetNumberOfOccurrences2() {
50
+        int expected = 1;
51
+        int actual = StringArrayUtils.getNumberOfOccurrences(testArray, "quick");
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+}