Skip to content

Commit

Permalink
Added String.toBoolean() service.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Dec 15, 2023
1 parent f867984 commit 4a382a1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,24 @@ public String lineSeparator(Object obj) {
return System.getProperty("line.separator");
}

// @formatter:off
@Documentation(
value = "Gets the boolean value of the given String.",
params = {
@Param(name = "value", value = "The current String"),
},
result = "true if then passed String equals ignoring case to 'true', false otherwise",
examples = {
@Example(expression = "'true'.toBoolean()", result = "true"),
@Example(expression = "'True'.toBoolean()", result = "true"),
@Example(expression = "'Some String'.toBoolean()", result = "false")
}
)
// @formatter:on
public Boolean toBoolean(String value) {
return Boolean.valueOf(value);
}

/**
* Gets the empty {@link String} if the given {@link String} is <code>null</code>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1592,4 +1592,25 @@ public void lineSeparator() {
assertEquals(System.getProperty("line.separator"), stringServices.lineSeparator(new Object()));
}

@Test
public void toBooleanNull() {
assertEquals(false, stringServices.toBoolean(null));
}

@Test
public void toBooleanEmptyString() {
assertEquals(false, stringServices.toBoolean(""));
}

@Test
public void toBooleanFalse() {
assertEquals(false, stringServices.toBoolean("Some String"));
}

@Test
public void toBooleanTrue() {
assertEquals(true, stringServices.toBoolean("true"));
assertEquals(true, stringServices.toBoolean("True"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ substring()
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
toBoolean()
* Description:
toBoolean(value: java.lang.String) = Boolean<br><br>Gets the boolean value of the given String.<br><br> @param value<br> The current String<br><br> @return<br> true if then passed String equals ignoring case to 'true', false otherwise<br><br>
* Text:
toBoolean()
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
toInteger()
* Description:
Expand Down

0 comments on commit 4a382a1

Please sign in to comment.