public void setPageOption(String key, String value){
if (key==null) return;
Boolean boolValue = value==null? null: "true".equals(value);
if ("allowAdvertising".equals(key)) setAllowAdvertising(boolValue);
if ("allowDateStamp".equals(key)) setAllowDateStamp(boolValue);
if ("allowPrintingSharingLinks".equals(key)) setAllowPrintingSharingLinks(boolValue);
if ("allowHeadline".equals(key)) setAllowHeadline(boolValue);
if ("allowRightHandSide".equals(key)) setAllowRightHandSide(boolValue);
if ("allowRelatedStoriesBox".equals(key)) setAllowRelatedStoriesBox(boolValue);
if ("includeComments".equals(key)) setIncludeComments(boolValue) ;
}
Refactorings
No refactoring yet !
bob
January 4, 2012, January 04, 2012 21:16, permalink
@Ants: switch statement with strings is only supported starting in Java 7
Ants
January 6, 2012, January 06, 2012 04:47, permalink
Taking away the 'if' statements just makes the code more verbose elsewhere...
Hashtable m_options;
interface Option
{
void set(Boolean value);
}
private void initPageOptions()
{
m_options = new Hashtable();
m_options.add("allowAdvertising", new Option() { public void set(Boolean value) { setAllowAdvertising(value);} } );
m_options.add("allowDateStamp", new Option() { public void set(Boolean value) { setAllowDateStamp(value);} } );
m_options.add("allowPrintSharingLinks", new Option() { public void set(Boolean value) { setAllowPrintSharingLinks(value);} } );
m_options.add("allowHeadline", new Option() { public void set(Boolean value) { setAllowHeadline(value);} } );
m_options.add("allowRightHandSide", new Option() { public void set(Boolean value) { setAllowRightHandSide(value);} } );
m_options.add("allowRelatedStoriesBox", new Option() { public void set(Boolean value) { setAllowRelatedStoriesBox(value);} } );
m_options.add("includeComments", new Option() { public void set(Boolean value) { setIncludeComments(value);} } );
}
public void setPageOption(String key, String value)
{
Option option = key != null ? m_options.get(key) : null;
if (option != null)
option.set(value != null ? value.equals("true") : null);
}
dry cleaners London
January 6, 2012, January 06, 2012 23:05, permalink
Very nice script it is more helpful for everyone
London massage
January 8, 2012, January 08, 2012 23:48, permalink
This is a very nice script it is quite good very and helpful everyone
Too many if statements. Want to avoid reflection.