Skip to content

Commit

Permalink
Updated the $-util based on test results.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilforslund committed Jan 20, 2015
1 parent 39fcbfa commit 21a7a07
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 21 deletions.
9 changes: 8 additions & 1 deletion pom.xml
Expand Up @@ -57,5 +57,12 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project> </project>
44 changes: 24 additions & 20 deletions src/main/java/com/speedment/util/$.java
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.util; package com.speedment.util;


/** /**
Expand All @@ -6,36 +22,24 @@
*/ */
public class $ implements CharSequence { public class $ implements CharSequence {


private static final CharSequence[] EMPTY = new CharSequence[0];

private final StringBuilder str; private final StringBuilder str;


private $() { public $() {
this(EMPTY); this("");
} }

public $(CharSequence... objects) { public $(CharSequence... objects) {
str = new StringBuilder(); str = new StringBuilder();
$(objects); $(objects);
} }


public final $ $(Object firstObject) { public final $ $(CharSequence... objects) {
str.append(firstObject); for (CharSequence object : objects) {
return this; str.append(object);
}

public final $ $(Object firstObject, Object... theRest) {
$(firstObject);
for (Object object : theRest) {
$(object);
} }
return this; return this;
} }


public static $ $(CharSequence... o) {
return new $(o);
}

@Override @Override
public int length() { public int length() {
return str.length(); return str.length();
Expand All @@ -55,4 +59,4 @@ public CharSequence subSequence(int start, int end) {
public String toString() { public String toString() {
return str.toString(); return str.toString();
} }
} }
59 changes: 59 additions & 0 deletions src/test/java/com/speedment/util/TestDollar.java
@@ -0,0 +1,59 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.util;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
*
* @author Duncan
*/
public class TestDollar {

private $ instance;

public TestDollar() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
instance = new $();
}

@After
public void tearDown() {
}

@Test
public void testConcatenation() {
instance.$("qwerty").$("asdfg", "zxcvb");
assertEquals("qwertyasdfgzxcvb", instance.toString());
}
}

0 comments on commit 21a7a07

Please sign in to comment.