-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
org.dadacoalition.yedit/src/org/dadacoalition/yedit/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.dadacoalition.yedit; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Various utility functions. | ||
*/ | ||
public class Utils { | ||
|
||
private Utils(){} | ||
|
||
/** | ||
* Join each element in a collection using a string separator | ||
* @param collection The collection to join | ||
* @param separator The separator to use | ||
* @return A string where the toString method on each object in the collection has been called and each element is | ||
* separated with the separator string. | ||
*/ | ||
public static String joinAsString(Collection<? extends Object> collection, String separator){ | ||
|
||
if(collection.isEmpty()){ | ||
return ""; | ||
} | ||
|
||
StringBuilder result = new StringBuilder(); | ||
boolean first = true; | ||
for( Object o : collection ){ | ||
|
||
if(first){ | ||
first = false; | ||
} else { | ||
result.append(separator); | ||
} | ||
result.append(o.toString()); | ||
|
||
} | ||
return result.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters