Skip to content

Commit

Permalink
Removed unnecessary String.format invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
valdas-s committed Jul 31, 2014
1 parent 87c05f9 commit 689f5f0
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 71 deletions.
38 changes: 16 additions & 22 deletions xacml-core/src/main/java/org/xacml4j/v30/BagOfAttributeExp.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,11 @@ public final class BagOfAttributeExp
*/
BagOfAttributeExp(BagOfAttributeExpType type,
Iterable<AttributeExp> attributes){
this.type = type;
ImmutableMultiset.Builder<AttributeExp> b = ImmutableMultiset.builder();
for(AttributeExp attr: attributes){
Preconditions.checkArgument(
attr.getType().equals(type.getDataType()),
String.format("Only attributes of type=\"%s\" " +
"are allowed in this bag, given type=\"%s\"",
type.getDataType(), attr.getType()));
b.add(attr);
for (AttributeExp attr : attributes) {
assertExpressionType(attr, type);
}
this.values = b.build();
this.type = type;
this.values = ImmutableMultiset.copyOf(attributes);

}

Expand Down Expand Up @@ -289,6 +283,14 @@ public interface BagOfAttributeVisitor extends ExpressionVisitor
void visitLeave(BagOfAttributeExp v);
}

private static void assertExpressionType(AttributeExp value, BagOfAttributeExpType bagType) {
if (!value.getType().equals(bagType.getDataType())) {
throw new IllegalArgumentException(String.format(
"Given attribute value=\"%s\" " +
"can't be used as a value of bag=\"%s\"", value, bagType));
}
}

public static class Builder
{

Expand All @@ -301,11 +303,7 @@ public Builder(AttributeExpType type){

public Builder attribute(AttributeExp ...values){
for(AttributeExp v : values){
if(!v.getType().equals(bagType.getDataType())){
throw new IllegalArgumentException(String.format(
"Given attribute value=\"%s\" " +
"can't be used as a value of bag=\"%s\"", v, bagType));
}
assertExpressionType(v, bagType);
this.valuesBuilder.add(v);
}
return this;
Expand All @@ -326,14 +324,10 @@ public Builder values(Iterable<Object> values){
}

public Builder attributes(Iterable<AttributeExp> values){
for(AttributeExp v : values){
if(!v.getType().equals(bagType.getDataType())){
throw new IllegalArgumentException(String.format(
"Given attribute value=\"%s\" " +
"can't be used as a value of bag=\"%s\"", v, bagType));
}
this.valuesBuilder.add(v);
for (AttributeExp v : values) {
assertExpressionType(v, bagType);
}
this.valuesBuilder.addAll(values);
return this;
}

Expand Down
3 changes: 1 addition & 2 deletions xacml-core/src/main/java/org/xacml4j/v30/IPAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ private IPAddress(Builder b)
Preconditions.checkArgument(
((b.addr instanceof Inet6Address) && (b.mask == null || b.mask instanceof Inet6Address)) ||
((b.addr instanceof Inet4Address) && (b.mask == null || b.mask instanceof Inet4Address)),
String.format("Address=\"%s\" and mask=\"%s\" " +
"should be either IPV4 or IPV6", b.addr, b.mask));
"Address=\"%s\" and mask=\"%s\" should be either IPV4 or IPV6", b.addr, b.mask);
this.address = b.addr;
this.mask = b.mask;
this.range = b.range;
Expand Down
12 changes: 6 additions & 6 deletions xacml-core/src/main/java/org/xacml4j/v30/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ private static int[] parseVersion(
{
if(!version.matches(VERSION_PATTERN)){
throw new IllegalArgumentException(
String.format("Invalid version=\"%s\", " +
"does not match regular expression=\"%s\"",
version, VERSION_PATTERN));
String.format(
"Invalid version=\"%s\", does not match regular expression=\"%s\"",
version, VERSION_PATTERN));
}
String[] vc = version.split("\\.");
int[] v = new int[vc.length];
for(int i = 0; i < vc.length; i++){
v[i] = Integer.parseInt(vc[i]);
if(v[i] < 0){
throw new IllegalArgumentException(
String.format("Invalid version=\"%s\", " +
"component=\"%s\", number is negative", version,
Integer.toString(v[i])));
String.format(
"Invalid version=\"%s\", component=\"%d\", number is negative",
version, v[i]));
}
}
return v;
Expand Down
18 changes: 7 additions & 11 deletions xacml-core/src/main/java/org/xacml4j/v30/VersionMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http:https://www.gnu.org/licenses/lgpl-3.0.html>.
Expand Down Expand Up @@ -55,9 +55,8 @@ public VersionMatch(String versionMatchPattern)
if(!versionMatchPattern.matches(PATTERN)){
throw new XacmlSyntaxException(
String.format(
"Given version match=\"%s\" should " +
"match regular expression=\"%s\"",
versionMatchPattern, PATTERN));
"Given version match=\"%s\" should match regular expression=\"%s\"",
versionMatchPattern, PATTERN));
}
this.pattern = versionMatchPattern;
this.compiledPattern = Pattern.compile(convertVersionMatchToJavaRE(versionMatchPattern));
Expand Down Expand Up @@ -85,9 +84,9 @@ public boolean match(Version version) {
*/
private String convertVersionMatchToJavaRE(String pattern)
{
String plus = "\\.\\+", plusRep = "(.\\\\d+)*";
String dot = "\\.", dotRep = "\\\\.";
String ast = "\\*", astRep = "\\\\d";
final String plus = "\\.\\+", plusRep = "(.\\\\d+)*";
final String dot = "\\.", dotRep = "\\\\.";
final String ast = "\\*", astRep = "\\\\d";
// replace all "*" with "\d"
String phase1 = pattern.replaceAll(ast, astRep);
// replace all ".+" with "(.\d+)*"
Expand Down Expand Up @@ -122,9 +121,6 @@ public boolean equals(Object o){
if(o == this){
return true;
}
if(o == null){
return false;
}
if(!(o instanceof VersionMatch)){
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public Iterable<String> getVariableDefinitionExpressions(){
public void pushVariableDefinition(String variableId)
{
if(resolutionStack.contains(variableId)){
throw new IllegalArgumentException(String.format("Cyclic " +
"variable reference=\"%s\" detected", variableId));
throw new IllegalArgumentException(
String.format(
"Cyclic variable reference=\"%s\" detected", variableId));
}
this.resolutionStack.push(variableId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public EvaluationContext createContext(EvaluationContext context)
CompositeDecisionRule resolvedPolicy = context.resolve(this);
if(resolvedPolicy == null){
if(log.isDebugEnabled()){
log.debug(String.format(
"Failed to resolve policy reference=\"%s\"",
this));
log.debug("Failed to resolve policy reference=\"{}\"", this);
}
return refContext;
}
Expand All @@ -94,9 +92,7 @@ public EvaluationContext createContext(EvaluationContext context)
return resolvedPolicy.createContext(refContext);
}catch(PolicyResolutionException e){
if(log.isDebugEnabled()){
log.debug(String.format(
"Failed to resolve policy reference=\"%s\"",
this), e);
log.debug("Failed to resolve policy reference=\"{}\"", this, e);
}
return refContext;
}
Expand Down Expand Up @@ -157,8 +153,7 @@ private static boolean isReferenceCyclic(PolicyIDReference ref,
if(otherRef != null){
if(ref.equals(otherRef)){
if(log.isDebugEnabled()){
log.debug("Policy reference=\"{}\" " +
"cycle detected", ref);
log.debug("Policy reference=\"{}\" cycle detected", ref);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public final void addRuleCombineAlgorithm(
DecisionCombiningAlgorithm<Rule> oldAlgo = ruleAlgo.put(algorithm.getId(), algorithm);
if(oldAlgo != null){
throw new IllegalArgumentException(
String.format("Rule algorithm with identifier=\"%s\" already exist", algorithm));
String.format("Rule algorithm with identifier=\"%s\" already exists", algorithm));
}
}

Expand All @@ -100,8 +100,9 @@ public final void addCompositeRuleCombineAlgorithm(
algorithm.getId(), algorithm);
if(oldAlgo != null){
throw new IllegalArgumentException(
String.format("Policy decision combining" +
" algorithm with identifier=\"%s\" already exist", algorithm));
String.format(
"Policy decision combining algorithm with identifier=\"%s\" already exists",
algorithm));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public final void add(FunctionProvider provider)
for(String functionId : provider.getProvidedFunctions())
{
if(functions.containsKey(functionId)){
throw new IllegalArgumentException(String.format("Function provider " +
"already contains a function with functionId=\"%s\"",
functionId));
throw new IllegalArgumentException(
String.format(
"Function provider already contains a function with functionId=\"%s\"",
functionId));
}
FunctionSpec spec = provider.getFunction(functionId);
if(log.isDebugEnabled()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,37 @@

abstract class BaseFunctionParamSpec implements FunctionParamSpec
{
private boolean optional = false;
private Expression defaultValue;
private boolean variadic;
private final boolean optional;
private final Expression defaultValue;
private final boolean variadic;

protected BaseFunctionParamSpec(){
this(false, false, null);
}

protected BaseFunctionParamSpec(
boolean optional,
boolean optional,
boolean variadic,
Expression defaultValue){
if(!optional && defaultValue != null){
if (!optional && defaultValue != null) {
throw new XacmlSyntaxException("Function parameter can't be required " +
"and have default value at the same time");
}
this.optional = optional;
this.variadic = variadic;
this.defaultValue = defaultValue;
}

@Override
public final boolean isOptional(){
return optional;
}

@Override
public final boolean isVariadic(){
return variadic;
}

@Override
public final Expression getDefaultValue(){
return defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http:https://www.gnu.org/licenses/lgpl-3.0.html>.
Expand Down Expand Up @@ -188,9 +188,9 @@ public FunctionSpec createFunctionSpec(Method m, Object instance) throws XacmlSy
}
if (m.isVarArgs() && i < params.length - 1) {
throw new IllegalArgumentException(
String.format("Found varArg parameter "
"Found varArg parameter "
+ "declaration in incorrect place, "
+ "varArg parameter must be a last parameter in the method"));
+ "varArg parameter must be a last parameter in the method");
}
XacmlFuncParamVarArg param = (XacmlFuncParamVarArg) params[i][0];
Optional<AttributeExpType> type = XacmlTypes.getType(param.typeId());
Expand Down

0 comments on commit 689f5f0

Please sign in to comment.