Skip to content

Instantly share code, notes, and snippets.

@samhendley
Created July 29, 2016 13:36
Show Gist options
  • Save samhendley/d377e938d63d1b50f2bd8c259a5db5d7 to your computer and use it in GitHub Desktop.
Save samhendley/d377e938d63d1b50f2bd8c259a5db5d7 to your computer and use it in GitHub Desktop.
Nullable ToString generator for Intellij
class SampleToString {
@Override
public String toString() {
return "KeyManagementState{" +
"repId=" + repId +
(managementState == null ? "" : ", managementState:" + managementState) +
(desiredState == null ? "" : ", desiredState:" + desiredState) +
(lastAction == null ? "" : ", lastAction:" + lastAction) +
(lastActionResult == null ? "" : ", lastActionResult:" + lastActionResult) +
(lastActionTime == null ? "" : ", lastActionTime:" + lastActionTime) +
(nextAction == null ? "" : ", nextAction:" + nextAction) +
(nextActionTime == null ? "" : ", nextActionTime:" + nextActionTime) +
(lastUpdateTime == null ? "" : ", lastUpdateTime:" + lastUpdateTime) +
(statusString == null ? "" : ", statusString:" + "'" + statusString + '\'') +
(nextRotationTime == null ? "" : ", nextRotationTime:" + nextRotationTime) +
", changed=" + changed + '}';
}
}
public java.lang.String toString() {
#if ( $members.size() > 0 )
#set ( $i = 0 )
return "$classname{" +
#foreach( $member in $members )
#if ( $i != 0 )
#set ( $prefix = ", " )
+
#else
#set ( $prefix = "" )
#end
#if ( $member.object || $member.objectArray || $member.primitiveArray )
($member.accessor == null ? "" : "$prefix$member.name:" + ##
#else
"$prefix$member.name=" + ##
#end
#if ( $member.objectArray )
#if ($java_version < 5)
($member.accessor == null ? null : java.util.Arrays.asList($member.accessor)) ##
#else
java.util.Arrays.toString($member.accessor) ##
#end
#elseif ( $member.primitiveArray && $java_version >= 5)
java.util.Arrays.toString($member.accessor) ##
#elseif ( $member.string )
"'" + $member.accessor + '\'' ##
#else
$member.accessor ##
#end
#if ( $member.object || $member.objectArray || $member.primitiveArray )
) ##
#end
#set ( $i = $i + 1 )
#end
+'}';
#else
return "$classname{}";
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment