55502f40dc8b7c769880b10874abc9d0

Too many if statements. Want to avoid reflection.

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 !

F9a9ba6663645458aa8630157ed5e71e

Ants

January 4, 2012, January 04, 2012 08:46, permalink

No rating. Login to rate!

What's wrong with using a switch statement?

D41d8cd98f00b204e9800998ecf8427e

bob

January 4, 2012, January 04, 2012 21:16, permalink

No rating. Login to rate!

@Ants: switch statement with strings is only supported starting in Java 7

F9a9ba6663645458aa8630157ed5e71e

Ants

January 6, 2012, January 06, 2012 04:47, permalink

No rating. Login to rate!

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);
}
E230a9dd061708910438c085ae127145

dry cleaners London

January 6, 2012, January 06, 2012 23:05, permalink

No rating. Login to rate!

Very nice script it is more helpful for everyone

E230a9dd061708910438c085ae127145

London massage

January 8, 2012, January 08, 2012 23:48, permalink

No rating. Login to rate!

This is a very nice script it is quite good very and helpful everyone

Your refactoring





Format Copy from initial code

or Cancel