public static String ruleToRuleContentsString ( Rule originalRule , int indentLevel ) { if ( originalRule instanceof Context && ( ( Context ) originalRule ) . containsKey ( RuleMetadataType . RULE_XML ) ) { return ( String ) ( ( Context ) originalRule ) . get ( RuleMetadataType . RULE_XML ) ; } if ( ! ( originalRule instanceof RuleBuilder ) ) { return wrap ( originalRule . toString ( ) , MAX_WIDTH , indentLevel ) ; } final RuleBuilder rule = ( RuleBuilder ) originalRule ; StringBuilder result = new StringBuilder ( ) ; if ( indentLevel == 0 ) result . append ( "addRule()" ) ; for ( Condition condition : rule . getConditions ( ) ) { String conditionToString = conditionToString ( condition , indentLevel + 1 ) ; if ( ! conditionToString . isEmpty ( ) ) { result . append ( System . lineSeparator ( ) ) ; insertPadding ( result , indentLevel + 1 ) ; result . append ( ".when(" ) . append ( wrap ( conditionToString , MAX_WIDTH , indentLevel + 2 ) ) . append ( ")" ) ; } } for ( Operation operation : rule . getOperations ( ) ) { String operationToString = operationToString ( operation , indentLevel + 1 ) ; if ( ! operationToString . isEmpty ( ) ) { result . append ( System . lineSeparator ( ) ) ; insertPadding ( result , indentLevel + 1 ) ; result . append ( ".perform(" ) . append ( wrap ( operationToString , MAX_WIDTH , indentLevel + 2 ) ) . append ( ")" ) ; } } if ( rule . getId ( ) != null && ! rule . getId ( ) . isEmpty ( ) ) { result . append ( System . lineSeparator ( ) ) ; insertPadding ( result , indentLevel ) ; result . append ( "withId(\"" ) . append ( rule . getId ( ) ) . append ( "\")" ) ; } if ( rule . priority ( ) != 0 ) { result . append ( System . lineSeparator ( ) ) ; insertPadding ( result , indentLevel ) ; result . append ( ".withPriority(" ) . append ( rule . priority ( ) ) . append ( ")" ) ; } return result . toString ( ) ; }
Attempts to create a human - readable String representation of the provided rule .