<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Freya.no &#187; howto</title>
	<atom:link href="http://wp.freya.no/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.freya.no</link>
	<description>Knowledge is power</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:56:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring MVC: how to build a thread-safe Controller</title>
		<link>http://wp.freya.no/2012/02/spring-mvc-how-to-build-a-thread-safe-controller/</link>
		<comments>http://wp.freya.no/2012/02/spring-mvc-how-to-build-a-thread-safe-controller/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 14:24:28 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=1131</guid>
		<description><![CDATA[Controllers in Spring MVC are desined to be shared between requests. Each controller has a default singleton scope so if you are using controllers you neeed to be aware of that. The easiest way to make sure your controller is thread-safe is to not to have class variables. F.ex. this example from Spring MVC tutorial: [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Controllers in Spring MVC are desined to be shared between requests. Each controller has a default singleton scope so if you are using controllers you neeed to be aware of that. The easiest way to make sure your controller is thread-safe is to not to have class variables. F.ex. this example from <a href="http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#13.11.13">Spring MVC tutorial</a>:</p>
<pre class="brush: java; title: ; notranslate">
@Controller
@RequestMapping(&quot;/editPet.do&quot;)
public class EditPetForm {

    private final Clinic clinic;

    public EditPetForm(Clinic clinic) {
        this.clinic = clinic;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(@RequestParam(&quot;petId&quot;) int petId, ModelMap model) {
        Pet pet = this.clinic.loadPet(petId);
        model.addAttribute(&quot;pet&quot;, pet);
        return &quot;petForm&quot;;
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(
            @ModelAttribute(&quot;pet&quot;) Pet pet, BindingResult result, SessionStatus status) {

        new PetValidator().validate(pet, result);
        if (result.hasErrors()) {
            return &quot;petForm&quot;;
        }
        else {
            this.clinic.storePet(pet);
            status.setComplete();
            return &quot;redirect:owner.do?ownerId=&quot; + pet.getOwner().getId();
        }
    }
}
</pre>
<p>In this example we can have a serious issue regarding thread-safety: private variable clinic. If there will be a situation where to different requests access the controller simultaniously, one of them will instanciate the controller and begin to process a form, then the other one comes inn. The result from processing of the first request will be sent to the other one, thus the requests receive fail data or nothing.</p>
<p>The solution to the problem may be the following:<br />
1. Annotate Controller with @Scope(&#8220;request&#8221;) or @Scope(&#8220;session&#8221;)<br />
2. Move private variable into one of the methods or save it in session or model.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1131" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2012%2F02%2Fspring-mvc-how-to-build-a-thread-safe-controller%2F&amp;title=Spring%20MVC%3A%20how%20to%20build%20a%20thread-safe%20Controller" id="wpa2a_6"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2012/02/spring-mvc-how-to-build-a-thread-safe-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get a value of mx:DataGridColumn</title>
		<link>http://wp.freya.no/2011/02/how-to-get-a-value-of-mxdatagridcolumn/</link>
		<comments>http://wp.freya.no/2011/02/how-to-get-a-value-of-mxdatagridcolumn/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 20:23:42 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=987</guid>
		<description><![CDATA[No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:DataGrid xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Label;

            public function willShowResult(result:Label, myVar:String):Boolean {
                if (myVar== 'XXX') {
                    return false;
                }
                return true;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:columns&gt;
        &lt;mx:DataGridColumn
            dataField=&quot;myVar&quot;
            headerText=&quot;My var&quot;/&gt;
        &lt;mx:DataGridColumn
            dataField=&quot;result&quot;
            headerText=&quot;My result&quot;&gt;
            &lt;mx:itemRenderer&gt;
                &lt;mx:Component&gt;
                    &lt;mx:Label text=&quot;{outerDocument.willShowResult(this, data.myVar) ? data.result : ' ' }&quot;/&gt;
                &lt;/mx:Component&gt;
            &lt;/mx:itemRenderer&gt;
        &lt;/mx:DataGridColumn&gt;
    &lt;/mx:columns&gt;

&lt;/mx:DataGrid&gt;
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=987" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2011%2F02%2Fhow-to-get-a-value-of-mxdatagridcolumn%2F&amp;title=How%20to%20get%20a%20value%20of%20mx%3ADataGridColumn" id="wpa2a_14"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2011/02/how-to-get-a-value-of-mxdatagridcolumn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse autocomplete problem</title>
		<link>http://wp.freya.no/2011/02/eclipse-autocomplete-problem/</link>
		<comments>http://wp.freya.no/2011/02/eclipse-autocomplete-problem/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 14:17:44 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=983</guid>
		<description><![CDATA[If an autocomplete stopped working go Window -&#62; Preferences -&#62; Java -&#62; Editor -&#62; Content Assist -&#62; Advanced -&#62;  check for &#8220;Other Java Proposals&#8221; No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If an autocomplete stopped working go</p>
<p>Window -&gt; Preferences -&gt; Java -&gt; Editor -&gt; Content Assist -&gt; Advanced -&gt;  check for &#8220;Other Java Proposals&#8221;</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=983" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2011%2F02%2Feclipse-autocomplete-problem%2F&amp;title=Eclipse%20autocomplete%20problem" id="wpa2a_22"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2011/02/eclipse-autocomplete-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fallout New Vegas: Gaining entrance to Nellis Air Force Base</title>
		<link>http://wp.freya.no/2010/11/fallout-new-vegas-gaining-entrance-to-nellis-air-force-base/</link>
		<comments>http://wp.freya.no/2010/11/fallout-new-vegas-gaining-entrance-to-nellis-air-force-base/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 21:13:41 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[Game review]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[bombardment]]></category>
		<category><![CDATA[boomer]]></category>
		<category><![CDATA[Fallout: New Vegas]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Nellis AFB]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=931</guid>
		<description><![CDATA[This is how you gain access to the Nellis Air Force Base in New Vegas. Once you start entering the area, you&#8217;ll get bombarded by the Boomers. Overview picture: Click the picture for full size image. Refill with stimpacks, food, water, doctors bags when necessary. And remeber to make the bet with George before you [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>This is how you gain access to the Nellis Air Force Base in New Vegas.</p>
<p>Once you start entering the area, you&#8217;ll get bombarded by the Boomers.</p>
<p>Overview picture:</p>
<div id="attachment_932" class="wp-caption alignleft" style="width: 1034px"><a href="http://wp.freya.no/files/2010/11/boomers.jpg"><img src="http://wp.freya.no/files/2010/11/boomers-1024x640.jpg" alt="" title="Nellis AFB" width="1024" height="640" class="size-large wp-image-932" /></a><p class="wp-caption-text">This is how you enter the Nellis Air Force Base in New Vegas</p></div>
<p>Click the picture for full size image.</p>
<p>Refill with stimpacks, food, water, doctors bags when necessary.</p>
<p>And remeber to make the bet with George before you enter the area. If you have 60 speech or more you can lie to raise the wager to 700 after you&#8217;ve entered Nellis AFB and came back.</p>
<p>When you reach the gate you&#8217;ll be let in.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=931" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2010%2F11%2Ffallout-new-vegas-gaining-entrance-to-nellis-air-force-base%2F&amp;title=Fallout%20New%20Vegas%3A%20Gaining%20entrance%20to%20Nellis%20Air%20Force%20Base" id="wpa2a_30"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2010/11/fallout-new-vegas-gaining-entrance-to-nellis-air-force-base/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fallout New Vegas: Brotherhood Scout Locations</title>
		<link>http://wp.freya.no/2010/11/fallout-new-vegas-brotherhood-scout-locations/</link>
		<comments>http://wp.freya.no/2010/11/fallout-new-vegas-brotherhood-scout-locations/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 13:59:01 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[Game review]]></category>
		<category><![CDATA[Fallout: New Vegas]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=925</guid>
		<description><![CDATA[After finding the locations of the Brotherhood patrols, you&#8217;re asked to find the scouts and retrieve observations from them. Locations are: 1) Near the NCR Correctional Facility 2) Near Nipton 3) Near Camp Forlorn Hope No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>After finding the locations of the Brotherhood patrols, you&#8217;re asked to find the scouts and retrieve observations from them.</p>
<p>Locations are:<br />
1) Near the NCR Correctional Facility<br />
2) Near Nipton<br />
3) Near Camp Forlorn Hope</p>
<div id="attachment_926" class="wp-caption alignleft" style="width: 988px"><a href="http://wp.freya.no/files/2010/11/scout_locations.jpg"><img src="http://wp.freya.no/files/2010/11/scout_locations.jpg" alt="Scout Locations" title="Scout Locations" width="978" height="698" class="size-full wp-image-926" /></a><p class="wp-caption-text">Scout Locations</p></div>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=925" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2010%2F11%2Ffallout-new-vegas-brotherhood-scout-locations%2F&amp;title=Fallout%20New%20Vegas%3A%20Brotherhood%20Scout%20Locations" id="wpa2a_38"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2010/11/fallout-new-vegas-brotherhood-scout-locations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fallout: New Vegas Hidden Valley Bunker Virus</title>
		<link>http://wp.freya.no/2010/10/fallout-new-vegas-hidden-valley-bunker-virus/</link>
		<comments>http://wp.freya.no/2010/10/fallout-new-vegas-hidden-valley-bunker-virus/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 20:08:25 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[Game review]]></category>
		<category><![CDATA[Fallout: New Vegas]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[hidden valley]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[virus]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=885</guid>
		<description><![CDATA[This is a simple howto on how to beat the virus infection in the Brotherhood of Steel datastore. 1) Talk to Scribe Ibsen about the virus infection and ask if you could help him. 2) After much talking Scribe Ibsen will ask you to wait until he says the virus has jumped. Do a quicksave [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>This is a simple howto on how to beat the virus infection in the Brotherhood of Steel datastore.</p>
<p>1) Talk to Scribe Ibsen about the virus infection and ask if you could help him.</p>
<p>2) After much talking Scribe Ibsen will ask you to wait until he says the virus has jumped. Do a quicksave here just before Scribe Ibsen tells you the virus has jumped.</p>
<p>3) Place yourself in front of one of the terminals.</p>
<p>4) When Scribe Ibsen gives you GO, search for the virus in the computers. Do a systematic search. And remember what computers have the virus. If you fail the first attempt, reload the quicksave.</p>
<p>5) Go to the computers you had the virus in the previous attempt and isolate them there.</p>
<p>6) Continue the search for additional infected computers.</p>
<p>7) If unsuccessful, goto 4.</p>
<div id="attachment_899" class="wp-caption alignleft" style="width: 1034px"><a href="http://wp.freya.no/files/2010/10/ScreenShot9.jpg"><img class="size-large wp-image-899" title="Scribe Ibsen at the terminal" src="http://wp.freya.no/files/2010/10/ScreenShot9-1024x640.jpg" alt="Scribe Ibsen at the terminal" width="1024" height="640" /></a><p class="wp-caption-text">Scribe Ibsen at the terminal</p></div>
<p>More screenshots in the next post.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=885" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2010%2F10%2Ffallout-new-vegas-hidden-valley-bunker-virus%2F&amp;title=Fallout%3A%20New%20Vegas%20Hidden%20Valley%20Bunker%20Virus" id="wpa2a_46"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2010/10/fallout-new-vegas-hidden-valley-bunker-virus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex: force focus on parent change</title>
		<link>http://wp.freya.no/flash-flex/flex-force-focus-on-parent-change/</link>
		<comments>http://wp.freya.no/flash-flex/flex-force-focus-on-parent-change/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 08:36:05 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=743</guid>
		<description><![CDATA[I was trying to solve a problem of resetting a focus if the parent changes. I had different buttons that show the same .mxml-form but with different data. The problem was that I needed the focus to be on the first date-field whenever the form is shown so that the user can begin typing data [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I was trying to solve a problem of resetting a focus if the parent changes. I had different buttons that show the same .mxml-form but with different data. The problem was that I needed the focus to be on the first date-field whenever the form is shown so that the user can begin typing data right away.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;mx:HBox&gt;
       &lt;mx:Button id=&quot;noData&quot; click=&quot;showPanelWithNoData()&quot; /&gt;
       &lt;mx:Button id=&quot;someData&quot; click=&quot;showPanelWithSomeData()&quot; /&gt;
       &lt;mx:Button id=&quot;withData&quot; click=&quot;showPanelWithData()&quot; /&gt;

       &lt;myCustomForm:DataForm width=&quot;100%&quot; /&gt;
&lt;/mx:HBox&gt;
</pre>
<p>So for each time one of the buttons is pushed I need the focus to be on myDate-field. To solve the problem I used &#8220;<strong>updateComplete</strong>&#8220;-property of the field.</p>
<p>DataForm.mxml</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;DataForm
    xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.managers.FocusManager;

            private function resetFocus():void {
                if (focusManager != null &amp;&amp; myDate.focusManager != null) {
                    focusManager.setFocus(myDate);
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:FormItem&gt;
        &lt;mx:TextField id=&quot;myDate&quot;
            updateComplete=&quot;resetFocus()&quot;/&gt;
    &lt;/mx:FormItem&gt;

&lt;/DataForm&gt;
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=743" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fflash-flex%2Fflex-force-focus-on-parent-change%2F&amp;title=Flex%3A%20force%20focus%20on%20parent%20change" id="wpa2a_54"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/flash-flex/flex-force-focus-on-parent-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recipe for a high-quality &#8220;equals&#8221; method</title>
		<link>http://wp.freya.no/java/recipe-for-a-high-quality-equals-method/</link>
		<comments>http://wp.freya.no/java/recipe-for-a-high-quality-equals-method/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 21:49:25 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Memorable]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[equals]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=675</guid>
		<description><![CDATA[1. Use the == to check if the argument is a reference to this object. 2. Use the instanceof operator to check if the argument has the correct type. 3. Cast the argument to the correct type. 4. For each &#8220;significant&#8221; field in the class, check if that field of the argument matches the corresponding [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>1. Use the == to check if the argument is a reference to this object.</p>
<p>2. Use the <em>instanceof </em>operator to check if the argument has the correct type.</p>
<p>3. Cast the argument to the correct type.</p>
<p>4. For each &#8220;significant&#8221; field in the class, check if that field of the argument matches the corresponding field of this object.</p>
<p>5. Always override <em>hashCode </em>when you override <em>equals</em>.</p>
<p>6. Don&#8217;t substitute another type for Object in the equals declaration.</p>
<p>7. Write unit-test.</p>
<pre class="brush: java; title: ; notranslate">
   @Override
   public boolean equals(Object obj) {
      if(obj == this) {
         return true;
      }
      if(!(obj instanceof Person)) {
          return false;
      }
      Person p = (Person)obj;
      return p.name.equals(name)
             p.birthday.equals(birthday)
             p.personNumber == personNumber;
      }
</pre>
<p><em><br />
Ref.&#8221;Effective Java&#8221; by Joshua Bloch</em></p>
<p>Enother example with hashCode and toString:</p>
<pre class="brush: java; title: ; notranslate">
    @Override
    public boolean equals(Object obj) {
        if (obj == null || !obj.getClass().isInstance(this)) {
            return false;
        }
        Beregning b = (Beregning) obj;

        return new EqualsBuilder()
                .append(simulertPensjon, b.getSimulertPensjon())
                .append(linjer.size(), b.getLinjer().size()).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(simulertPensjon).append(linjer).hashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
        .append(&quot;simulertPensjon&quot;, simulertPensjon)
        .append(&quot;antall linjer&quot;, linjer.size()).toString();
    }
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=675" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fjava%2Frecipe-for-a-high-quality-equals-method%2F&amp;title=Recipe%20for%20a%20high-quality%20%26%238220%3Bequals%26%238221%3B%20method" id="wpa2a_62"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/java/recipe-for-a-high-quality-equals-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean code</title>
		<link>http://wp.freya.no/ugly-code/clean-code/</link>
		<comments>http://wp.freya.no/ugly-code/clean-code/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:13:49 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Memorable]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=585</guid>
		<description><![CDATA[The book by Robert C. Martin &#8220;Clean Code&#8221; is a really very useful material for all programmers. You can disagree with him sometimes (as I do), but it still provides some useful notes that helped me to place my programmer experience and knowledge where they belong. Here I&#8217;ll provide some key notes that I did [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>The book by Robert C. Martin &#8220;Clean Code&#8221; is a really very useful material for all programmers. You can disagree with him sometimes (as I do), but it still provides some useful notes that helped me to place my programmer experience and knowledge where they belong. Here I&#8217;ll provide some key notes that I did while reading the book and that I&#8217;d like to memorize.</p>
<p>What you as a programmer <strong>SHOULD DO</strong>:</p>
<p>1. Give everything meaningful, searchable and pronounceable names.<br />
2. Use names that other programmers can understand. Remember that the code is for programmers, not customers.<br />
3. Functions should be small and smaller than that.<br />
4. Functions should do one thing. They should do it well. They should do it only.<br />
5. The ideal number of arguments for a function is zero. Max 3.<br />
6. Prefer exceptions to returning error codes. Create informative error messages.<br />
7. Prefer meaningful names to comments.<br />
8. Write JavaDoc only for public API&#8217;s.<br />
9. Format your code. While working in a team use a single formatting style.<br />
10. Test your code with clean tests. Remember that test code is just as important as production code.<br />
11. Test just one concept per test.<br />
12. Test should follow the FIRST rule:</p>
<ul> <strong>Fast </strong>-  tests should be fast.<br />
<strong>Independent </strong>- tests should not depend on each other<br />
<strong>Repeatable </strong>- tests should be repeatable in any environment<br />
<strong>Self-validating</strong> &#8211; the test should have a boolean output<br />
<strong>Timely </strong>- write unit tests before the production code.</ul>
<p>What you as a programmer should <strong>AVOID</strong>:<br />
1. Avoid encoding<br />
2. Avoid duplicate code. Watch out not only duplicate functions but also duplicate functionality.<br />
3. Avoid noisy, redundant, uninformative comments. Remember that one of the more common motivations for writing comments is bad code.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=585" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fugly-code%2Fclean-code%2F&amp;title=Clean%20code" id="wpa2a_70"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/ugly-code/clean-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building opensource Qt on Windows</title>
		<link>http://wp.freya.no/2009/12/building-opensource-qt-on-windows/</link>
		<comments>http://wp.freya.no/2009/12/building-opensource-qt-on-windows/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 10:43:47 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=263</guid>
		<description><![CDATA[Open Visual Studio command prompt. Go to the folder you installed the source files in. Execute configure with the wanted options. S:\Qt\2009.04\qt&#62;configure -debug-and-release -fast -no-webkit -opensource This is the Qt for Windows Open Source Edition. You are licensed to use this software under the terms of the GNU General Public License (GPL) version 3 or [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Open Visual Studio command prompt.</p>
<p>Go to the folder you installed the source files in.</p>
<p>Execute configure with the wanted options.</p>
<blockquote>
<pre>S:\Qt\2009.04\qt&gt;configure -debug-and-release -fast -no-webkit -opensource

This is the Qt for Windows Open Source Edition.

You are licensed to use this software under the terms of
the GNU General Public License (GPL) version 3
or the GNU Lesser General Public License (LGPL) version 2.1.

Type '3' to view the GNU General Public License version 3 (GPLv3).
Type 'L' to view the Lesser GNU General Public License version 2.1 (LGPLv2.1).
Type 'y' to accept this license offer.
Type 'n' to decline this license offer.

Do you accept the terms of the license?</pre>
</blockquote>
<p>Wait.</p>
<p>Then execute nmake and wait.</p>
<h2 id="toc-configure-command-line-options">&#8220;configure&#8221; command line options</h2>
<pre>Usage: configure [-buildkey &lt;key&gt;]
 [-release] [-debug] [-debug-and-release] [-shared] [-static]
 [-no-fast] [-fast] [-no-exceptions] [-exceptions]
 [-no-accessibility] [-accessibility] [-no-rtti] [-rtti]
 [-no-stl] [-stl] [-no-sql-&lt;driver&gt;] [-qt-sql-&lt;driver&gt;]
 [-plugin-sql-&lt;driver&gt;] [-system-sqlite] [-arch &lt;arch&gt;]
 [-D &lt;define&gt;] [-I &lt;includepath&gt;] [-L &lt;librarypath&gt;]
 [-help] [-no-dsp] [-dsp] [-no-vcproj] [-vcproj]
 [-no-qmake] [-qmake] [-dont-process] [-process]
 [-no-style-&lt;style&gt;] [-qt-style-&lt;style&gt;] [-redo]
 [-saveconfig &lt;config&gt;] [-loadconfig &lt;config&gt;]
 [-qt-zlib] [-system-zlib] [-no-gif] [-qt-gif] [-no-libpng]
 [-qt-libpng] [-system-libpng] [-no-libtiff] [-qt-libtiff]
 [-system-libtiff] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg]
 [-no-libmng] [-qt-libmng] [-system-libmng] [-no-qt3support] [-mmx]
 [-no-mmx] [-3dnow] [-no-3dnow] [-sse] [-no-sse] [-sse2] [-no-sse2]
 [-no-iwmmxt] [-iwmmxt] [-direct3d] [-openssl] [-openssl-linked]
 [-no-openssl] [-no-dbus] [-dbus] [-dbus-linked] [-platform &lt;spec&gt;]
 [-qtnamespace &lt;namespace&gt;] [-qtlibinfix &lt;infix&gt;] [-no-phonon]
 [-phonon] [-no-phonon-backend] [-phonon-backend]
 [-no-webkit] [-webkit]
 [-no-scripttools] [-scripttools]
 [-graphicssystem raster|opengl]

Installation options:

 You may use these options to turn on strict plugin loading:

 -buildkey &lt;key&gt; .... Build the Qt library and plugins using the specified
 &lt;key&gt;.  When the library loads plugins, it will only
 load those that have a matching &lt;key&gt;.

Configure options:

 The defaults (*) are usually acceptable. A plus (+) denotes a default value
 that needs to be evaluated. If the evaluation succeeds, the feature is
 included. Here is a short explanation of each option:

 -release ........... Compile and link Qt with debugging turned off.
 *  -debug ............. Compile and link Qt with debugging turned on.
 +  -debug-and-release . Compile and link two Qt libraries, with and without
 debugging turned on.

 -opensource ........ Compile and link the Open-Source Edition of Qt.
 -commercial ........ Compile and link the Commercial Edition of Qt.

 -developer-build ... Compile and link Qt with Qt developer options
 (including auto-tests exporting)

 *  -shared ............ Create and use shared Qt libraries.
 -static ............ Create and use static Qt libraries.

 -ltcg .............. Use Link Time Code Generation. (Release builds only)
 *  -no-ltcg ........... Do not use Link Time Code Generation.

 *  -no-fast ........... Configure Qt normally by generating Makefiles for all
 project files.
 -fast .............. Configure Qt quickly by generating Makefiles only for
 library and subdirectory targets.  All other Makefiles
 are created as wrappers which will in turn run qmake

 -no-exceptions ..... Disable exceptions on platforms that support it.
 *  -exceptions ........ Enable exceptions on platforms that support it.

 -no-accessibility .. Do not compile Windows Active Accessibility support.
 *  -accessibility ..... Compile Windows Active Accessibility support.

 -no-stl ............ Do not compile STL support.
 *  -stl ............... Compile STL support.

 -no-sql-&lt;driver&gt; ... Disable SQL &lt;driver&gt; entirely, by default none are
 turned on.
 -qt-sql-&lt;driver&gt; ... Enable a SQL &lt;driver&gt; in the Qt Library.
 -plugin-sql-&lt;driver&gt; Enable SQL &lt;driver&gt; as a plugin to be linked to at run
 time.
 Available values for &lt;driver&gt;:
 mysql
 psql
 oci
 odbc
 tds
 db2
 +                         sqlite
 sqlite2
 ibase
 (drivers marked with a '+' have been detected as
 available on this system)

 -system-sqlite ..... Use sqlite from the operating system.

 -no-qt3support ..... Disables the Qt 3 support functionality.

 -no-opengl ......... Disables OpenGL functionality

 -platform &lt;spec&gt; ... The operating system and compiler you are building on.
 (default %QMAKESPEC%)

 -xplatform &lt;spec&gt; .. The operating system and compiler you are cross
 compiling to.

 See the README file for a list of supported operating
 systems and compilers.

 -qtnamespace &lt;namespace&gt; Wraps all Qt library code in 'namespace name {...}
 -qtlibinfix &lt;infix&gt; Renames all Qt* libs to Qt*&lt;infix&gt;

 -D &lt;define&gt; ........ Add an explicit define to the preprocessor.
 -I &lt;includepath&gt; ... Add an explicit include path.
 -L &lt;librarypath&gt; ... Add an explicit library path.
 -l &lt;libraryname&gt; ... Add an explicit library name, residing in a
 librarypath.

 -graphicssystem &lt;sys&gt; Specify which graphicssystem should be used.
 Available values for &lt;sys&gt;:
 *                         raster - Software rasterizer
 opengl - Using OpenGL accelleration, experimental!
 -help, -h, -? ...... Display this information.

Third Party Libraries:

 -qt-zlib ........... Use the zlib bundled with Qt.
 +  -system-zlib ....... Use zlib from the operating system.
 See http://www.gzip.org/zlib

 -no-gif ............ Do not compile the plugin for GIF reading support.
 +  -qt-gif ............ Compile the plugin for GIF reading support.
 See also src/plugins/imageformats/gif/qgifhandler.h

 -no-libpng ......... Do not compile in PNG support.
 -qt-libpng ......... Use the libpng bundled with Qt.
 +  -system-libpng ..... Use libpng from the operating system.
 See http://www.libpng.org/pub/png

 -no-libmng ......... Do not compile in MNG support.
 -qt-libmng ......... Use the libmng bundled with Qt.
 +  -system-libmng ..... Use libmng from the operating system.
 See See http://www.libmng.com

 -no-libtiff ........ Do not compile the plugin for TIFF support.
 -qt-libtiff ........ Use the libtiff bundled with Qt.
 +  -system-libtiff .... Use libtiff from the operating system.
 See http://www.libtiff.org

 -no-libjpeg ........ Do not compile the plugin for JPEG support.
 -qt-libjpeg ........ Use the libjpeg bundled with Qt.
 +  -system-libjpeg .... Use libjpeg from the operating system.
 See http://www.ijg.org

Qt for Windows only:

 -no-dsp ............ Do not generate VC++ .dsp files.
 *  -dsp ............... Generate VC++ .dsp files, only if spec "win32-msvc".

 -no-vcproj ......... Do not generate VC++ .vcproj files.
 *  -vcproj ............ Generate VC++ .vcproj files, only if platform
 "win32-msvc.net".

 -no-incredibuild-xge Do not add IncrediBuild XGE distribution commands to
 custom build steps.
 +  -incredibuild-xge .. Add IncrediBuild XGE distribution commands to custom
 build steps. This will distribute MOC and UIC steps,
 and other custom buildsteps which are added to the
 INCREDIBUILD_XGE variable.
 (The IncrediBuild distribution commands are only added
 to Visual Studio projects)

 -no-plugin-manifests Do not embed manifests in plugins.
 *  -plugin-manifests .. Embed manifests in plugins.

 -no-qmake .......... Do not compile qmake.
 *  -qmake ............. Compile qmake.

 -dont-process ...... Do not generate Makefiles/Project files. This will
 override -no-fast if specified.
 *  -process ........... Generate Makefiles/Project files.

 -no-rtti ........... Do not compile runtime type information.
 *  -rtti .............. Compile runtime type information.

 -no-mmx ............ Do not compile with use of MMX instructions
 +  -mmx ............... Compile with use of MMX instructions
 -no-3dnow .......... Do not compile with use of 3DNOW instructions
 +  -3dnow ............. Compile with use of 3DNOW instructions
 -no-sse ............ Do not compile with use of SSE instructions
 +  -sse ............... Compile with use of SSE instructions
 -no-sse2 ........... Do not compile with use of SSE2 instructions
 +  -sse2 .............. Compile with use of SSE2 instructions
 +  -direct3d .......... Compile in Direct3D support (experimental - see
 INSTALL for more info)
 -no-openssl ........ Do not compile in OpenSSL support
 +  -openssl ........... Compile in run-time OpenSSL support
 -openssl-linked .... Compile in linked OpenSSL support
 -no-dbus ........... Do not compile in D-Bus support
 +  -dbus .............. Compile in D-Bus support and load libdbus-1 dynamicall
 y
 -dbus-linked ....... Compile in D-Bus support and link to libdbus-1
 -no-phonon ......... Do not compile in the Phonon module
 +  -phonon ............ Compile the Phonon module (Phonon is built if a decent
 C++ compiler is used.)
 -no-phonon-backend . Do not compile the platform-specific Phonon backend-pl
 ugin
 *  -phonon-backend .... Compile in the platform-specific Phonon backend-plugin
 -no-webkit ......... Do not compile in the WebKit module
 +  -webkit ............ Compile in the WebKit module (WebKit is built if a
 decent C++ compiler is used.)
 -no-scripttools .... Do not build the QtScriptTools module.
 *  -scripttools ....... Build the QtScriptTools module.
 -arch &lt;arch&gt; ....... Specify an architecture.
 Available values for &lt;arch&gt;:
 *                         windows
 windowsce
 boundschecker
 generic

 -no-style-&lt;style&gt; .. Disable &lt;style&gt; entirely.
 -qt-style-&lt;style&gt; .. Enable &lt;style&gt; in the Qt Library.
 Available styles:
 *                         windows
 +                         windowsxp
 +                         windowsvista
 *                         plastique
 *                         cleanlooks
 *                         motif
 *                         cde
 windowsce
 windowsmobile

 -loadconfig &lt;config&gt; Run configure with the parameters from file configure_
 &lt;config&gt;.cache.
 -saveconfig &lt;config&gt; Run configure and save the parameters in file
 configure_&lt;config&gt;.cache.
 -redo .............. Run configure with the same parameters as last time.

Qt for Windows CE only:

 -no-iwmmxt ......... Do not compile with use of IWMMXT instructions
 +  -iwmmxt ............ Do compile with use of IWMMXT instructions (Qt for
 Windows CE on Arm only)
 *  -no-crt ............ Do not add the C runtime to default deployment rules
 -qt-crt ............ Qt identifies C runtime during project generation
 -crt &lt;path&gt; ........ Specify path to C runtime used for project generation.
 -no-cetest ......... Do not compile Windows CE remote test application
 +  -cetest ............ Compile Windows CE remote test application
 -signature &lt;file&gt; .. Use file for signing the target project
 -opengl-es-cm ...... Enable support for OpenGL ES Common
 -opengl-es-cl ...... Enable support for OpenGL ES Common Lite
 -opengl-es-2 ....... Enable support for OpenGL ES 2.0
 *  -phonon-wince-ds9 .. Enable Phonon Direct Show 9 backend for Windows CE
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=263" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2009%2F12%2Fbuilding-opensource-qt-on-windows%2F&amp;title=Building%20opensource%20Qt%20on%20Windows" id="wpa2a_78"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2009/12/building-opensource-qt-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

