-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
text wrap function (using zero with space)
- Loading branch information
Showing
8 changed files
with
87 additions
and
3 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
22 changes: 22 additions & 0 deletions
22
fj-doc-base/src/main/java/org/fugerit/java/doc/base/helper/TextWrapHelper.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,22 @@ | ||
package org.fugerit.java.doc.base.helper; | ||
|
||
import org.fugerit.java.core.function.SafeFunction; | ||
|
||
public class TextWrapHelper { | ||
|
||
private TextWrapHelper() {} | ||
|
||
public static final String ZERO_WITH_SPACE = "​"; | ||
|
||
public static String padZeroWithSpace( String input ) { | ||
return SafeFunction.getIfNotNull( input, () -> { | ||
StringBuilder builder = new StringBuilder(); | ||
for( int i=0; i<input.length(); i++ ) { | ||
builder.append( input.charAt( i ) ); | ||
builder.append( ZERO_WITH_SPACE ); | ||
} | ||
return builder.toString(); | ||
} ); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
fj-doc-base/src/test/java/test/org/fugerit/java/doc/base/helper/TestTextWrapHelper.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,17 @@ | ||
package test.org.fugerit.java.doc.base.helper; | ||
|
||
import org.fugerit.java.doc.base.helper.TextWrapHelper; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TestTextWrapHelper { | ||
|
||
@Test | ||
public void testWrap() { | ||
String input = "123"; | ||
String test = "1"+TextWrapHelper.ZERO_WITH_SPACE+"2"+TextWrapHelper.ZERO_WITH_SPACE+"3"+TextWrapHelper.ZERO_WITH_SPACE; | ||
String out = TextWrapHelper.padZeroWithSpace( input ); | ||
Assert.assertEquals( test, out ); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/FMFunHelper.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,21 @@ | ||
package org.fugerit.java.doc.freemarker.fun; | ||
|
||
import freemarker.template.TemplateModelException; | ||
|
||
import java.util.List; | ||
|
||
public class FMFunHelper { | ||
|
||
private FMFunHelper() {} | ||
|
||
public static void checkFirstRequredWithMessage( List<Object> arguments, String message ) throws TemplateModelException { | ||
if ( arguments.isEmpty() ) { | ||
throw new TemplateModelException( message ); | ||
} | ||
} | ||
|
||
public static void checkFirstRequred( List<Object> arguments ) throws TemplateModelException { | ||
checkFirstRequredWithMessage( arguments, "At least one parameter is needed" ); | ||
} | ||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/TextWrapFun.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,21 @@ | ||
package org.fugerit.java.doc.freemarker.fun; | ||
|
||
import freemarker.template.SimpleScalar; | ||
import freemarker.template.TemplateMethodModelEx; | ||
import freemarker.template.TemplateModelException; | ||
import freemarker.template.TemplateScalarModel; | ||
import org.fugerit.java.doc.base.helper.TextWrapHelper; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.List; | ||
|
||
public class TextWrapFun implements TemplateMethodModelEx { | ||
|
||
@Override | ||
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { | ||
FMFunHelper.checkFirstRequred( arguments ); | ||
String input = ((TemplateScalarModel)arguments.get( 0 )).getAsString(); | ||
return new SimpleScalar(TextWrapHelper.padZeroWithSpace( input )); | ||
} | ||
|
||
} |
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