Last active
August 29, 2015 14:17
-
-
Save thecoshman/dda47ba2d7ad250fcc60 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.thecoshman; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
class Formater { | |
class Attribute{ | |
String name; | |
Object value; | |
} | |
public String format(Attribute attr){ | |
return attr.name + ":" + formatValue(attr.value); | |
} | |
String formatValue(Object value){ | |
return value.toString(); | |
} | |
String formatValue(String value){ | |
return value; | |
} | |
String formatValue(Integer value){ | |
return value.toString(); | |
} | |
String formatValue(Boolean value){ | |
return value ? "true" : "false"; | |
} | |
String formatValue(List<Object> value){ | |
String retrunValue = "< "; | |
Iterator<Object> ittr = value.iterator(); | |
while(ittr.hasNext()){ | |
retrunValue += formatValue(ittr.next()); | |
if(ittr.hasNext()){ | |
retrunValue += " , "; | |
} | |
} | |
retrunValue += " >"; | |
return retrunValue; | |
} | |
String formatValue(Map<String, Object> value){ | |
String retrunValue = "[ "; | |
Iterator<String> ittr = value.keySet().iterator(); | |
while(ittr.hasNext()){ | |
String structMemberName = ittr.next(); | |
Object structMemberValue = value.get(structMemberName); | |
retrunValue += structMemberName; | |
retrunValue += ":"; | |
retrunValue += formatValue(structMemberValue); | |
if(ittr.hasNext()){ | |
retrunValue += " , "; | |
} | |
} | |
retrunValue += " ]"; | |
return retrunValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment