<?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>Looking for the paradigm &#187; programming</title>
	<atom:link href="http://www.evanhoffman.com/evan/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.evanhoffman.com/evan</link>
	<description>So I can pass it off</description>
	<lastBuildDate>Thu, 26 Jan 2012 22:17:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Displaying currently-playing iTunes track in the Mac menu bar</title>
		<link>http://www.evanhoffman.com/evan/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=displaying-currently-playing-itunes-track-in-the-mac-menu-bar</link>
		<comments>http://www.evanhoffman.com/evan/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 18:48:42 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[current track]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[menulet]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[whine]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=1641</guid>
		<description><![CDATA[TweetIn an attempt to teach myself Objective C, and because I couldn&#8217;t find anything that did what I wanted, I wrote a little utility to display the currently-playing iTunes track in the Mac taskbar. Originally I had it display the full track name right in the taskbar but it was too much text for such [...]]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/&via=EvanHoffman&text=Displaying currently-playing iTunes track in the Mac menu bar&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/"></g:plusone></div><p>In an attempt to teach myself Objective C, and because I couldn&#8217;t find anything that did what I wanted, I wrote a little utility to display the currently-playing iTunes track in the Mac taskbar.  Originally I had it display the full track name right in the taskbar but it was too much text for such a small space (especially on a 1440&#215;900 screen), so now you click a little musical note and it shows you the info in a menu.  </p>
<p>Here&#8217;s a screenshot:</p>
<p><a href="http://www.evanhoffman.com/evan/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/screen-shot-2011-10-20-at-8-54-49-pm/" rel="attachment wp-att-1642"><img src="http://www.evanhoffman.com/evan/wp-content/uploads/2011/10/Screen-shot-2011-10-20-at-8.54.49-PM.png" alt="" title="Screen shot 2011-10-20 at 8.54.49 PM" width="365" height="416" class="aligncenter size-full wp-image-1642" /></a></p>
<p>The code is all in <a href="https://github.com/evandhoffman/iTunes-Song-Title">github</a>.  If you&#8217;re looking for a similar utility, and are brave enough to try my first-ever Obj-C app, you can download it  <a href='http://www.evanhoffman.com/evan/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/itunes-current-track-app/' rel='attachment wp-att-1646'>here.</a>  But the freshest version will probably be in the github project.  </p>
<p>As an aside, I was surprised at how easy it was to cobble this together having never written ObjC before.  I found some good examples that I mostly ripped off, but it was still remarkably easy to have the app listen to iTunes for track changes, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmarking DNS servers with Java</title>
		<link>http://www.evanhoffman.com/evan/2011/09/26/benchmarking-dns-servers-with-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=benchmarking-dns-servers-with-java</link>
		<comments>http://www.evanhoffman.com/evan/2011/09/26/benchmarking-dns-servers-with-java/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 16:33:28 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=1626</guid>
		<description><![CDATA[TweetI&#8217;m currently in the process of moving our DNS over to another provider and I was curious as to whether the old or new provider offers faster lookups. dig shows query times, but I didn&#8217;t want to just run that over and over. I decided to write something to do this, in Java since I [...]]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2011/09/26/benchmarking-dns-servers-with-java/&via=EvanHoffman&text=Benchmarking DNS servers with Java&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2011/09/26/benchmarking-dns-servers-with-java/"></g:plusone></div><p>I&#8217;m currently in the process of moving our DNS over to another provider and I was curious as to whether the old or new provider offers faster lookups.  <code>dig</code> shows query times, but I didn&#8217;t want to just run that over and over.  I decided to write something to do this, in Java since I like Java.  I found <a href="http://mowyourlawn.com/blog/?p=8">this post,</a> which has the meat of the work done already.  I also read some of Sun&#8217;s <a href="http://download.oracle.com/javase/1,5.0/docs/guide/jndi/jndi-dns.html">JNDI/DNS</a> lookup info, which was pretty dense.  All I want to do is specify the name server&#8217;s IP and do the lookup.  I don&#8217;t even really care about the result, just how long the query takes.</p>
<p>The thing I wrote only looks up <code>A</code> records, but can easily be modified to do CNAMEs or whatever.  Here&#8217;s how you call it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ java <span style="color: #660033;">-jar</span> DNSTester.jar 4.2.2.2 www.google.com <span style="color: #000000;">25</span>
Resolved www.google.com to 74.125.235.19 against NS 4.2.2.2
Performed <span style="color: #000000;">25</span> lookups <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">233.29</span> milliseconds.  Average 9.3316ms per lookup.
&nbsp;
$ java <span style="color: #660033;">-jar</span> DNSTester.jar 8.8.4.4 www.google.com <span style="color: #000000;">25</span>
Resolved www.google.com to 74.125.226.146 against NS 8.8.4.4
Performed <span style="color: #000000;">25</span> lookups <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">450.034</span> milliseconds.  Average 18.00136ms per lookup.</pre></div></div>

<p>Code is in github <a href="https://github.com/evandhoffman/DNSBench">here</a>.  Jar is available <a href="http://www.evanhoffman.com/java/DNSTester.jar">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2011/09/26/benchmarking-dns-servers-with-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Teaching myself node.js: Part 3</title>
		<link>http://www.evanhoffman.com/evan/2011/06/23/teaching-myself-node-js-part-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=teaching-myself-node-js-part-3</link>
		<comments>http://www.evanhoffman.com/evan/2011/06/23/teaching-myself-node-js-part-3/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 21:39:59 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[findandmodify]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mongo]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[mongoskin]]></category>
		<category><![CDATA[mongoskin sequence]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[objectid]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sequence]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=1352</guid>
		<description><![CDATA[Notes on MongoDB's ObjectID vs sequential identifiers.]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2011/06/23/teaching-myself-node-js-part-3/&via=EvanHoffman&text=Teaching myself node.js: Part 3&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2011/06/23/teaching-myself-node-js-part-3/"></g:plusone></div><p>I&#8217;ve been playing around with node, JavaScript &#038; MongoDB a bit with this project and one of the things I ran into was MongoDB&#8217;s lack of a sequential ID.  MongoDB defaults to <a href="http://www.mongodb.org/display/DOCS/Object+IDs#ObjectIDs-TheBSONObjectIdDatatype">ObjectIDs</a> for primary keys in collections, and they have good reasons for doing so, but in writing this app, I&#8217;d rather have URLs look like &#8220;/question/423&#8243; than &#8220;/question/3001024e521e9c6500000000&#8243;.  </p>
<p>Fortunately, there&#8217;s a relatively convenient workaround for this problem, detailed <a href="http://www.mongodb.org/display/DOCS/Object+IDs#ObjectIDs-SequenceNumbers">here</a>.  Essentially, create a collection in which each document is a counter.  The ID for the document is its &#8220;name&#8221; and the property &#8220;next&#8221; contains the next value.  This is similar to creating and using a <a href="http://www.postgresql.org/docs/8.3/static/sql-createsequence.html">sequence</a> in PostgreSQL, though hopefully in the future they&#8217;ll provide an easier way to do this &#8211; perhaps a built-in sequence object.</p>
<p>First, in the mongo shell, I created the <code>counter(name)</code> function as specified in the Mongo wiki:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&gt;</span> counter                                        
<span style="color: #003366; font-weight: bold;">function</span> counter<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> ret <span style="color: #339933;">=</span> db.<span style="color: #660066;">counters</span>.<span style="color: #660066;">findAndModify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>query<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>_id<span style="color: #339933;">:</span><span style="color: #000066;">name</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> update<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>$inc<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>next<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'new'</span><span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> upsert<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> ret.<span style="color: #660066;">next</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then I created the counter document for the &#8220;questions&#8221; collection (so questions can have numeric IDs):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">db.<span style="color: #660066;">counters</span>.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>_id<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;questions&quot;</span><span style="color: #339933;">,</span> next<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is optional &#8211; the counter() function will create the document in the counters collection if needed, with an initial value of 1.  </p>
<p>That&#8217;s it.  Each call to counter() will now return an incrementing number:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">counters</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;_id&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;questions&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;next&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&gt;</span> counter<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;joe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
<span style="color: #CC0000;">1</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">counters</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;_id&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;questions&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;next&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;_id&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;joe&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;next&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&gt;</span> counter<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;joe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
<span style="color: #CC0000;">2</span>
<span style="color: #339933;">&gt;</span> counter<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;joe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #CC0000;">3</span></pre></div></div>

<p>Cool.  So how do we save the counter() function in the DB so we can use it in queries without having to define it every time?  Fortunately Mongo makes <a href="http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Storingfunctionsserverside">saving functions on the server</a> easy:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">system</span>.<span style="color: #660066;">js</span>.<span style="color: #660066;">save</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> _id <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;counter&quot;</span> <span style="color: #339933;">,</span> value <span style="color: #339933;">:</span> counter <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">system</span>.<span style="color: #660066;">js</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;_id&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;counter&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;value&quot;</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> cf__2__f_counter<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> ret <span style="color: #339933;">=</span> db.<span style="color: #660066;">counters</span>.<span style="color: #660066;">findAndModify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>query<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>_id<span style="color: #339933;">:</span><span style="color: #000066;">name</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> update<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>$inc<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>next<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'new'</span><span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> upsert<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> ret.<span style="color: #660066;">next</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Calling the stored procedure directly in the shell is sort of strange, but it works:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&gt;</span> db.<span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;return counter('question')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #CC0000;">3</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;return counter('question')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #CC0000;">4</span>
<span style="color: #339933;">&gt;</span> bye
<span style="color: #009900;">&#91;</span>Wed Jun <span style="color: #CC0000;">22</span> <span style="color: #CC0000;">13</span><span style="color: #339933;">:</span><span style="color: #CC0000;">14</span><span style="color: #339933;">:</span><span style="color: #CC0000;">10</span> evan<span style="color: #339933;">@</span>EvanMBP <span style="color: #CC0000;">3</span> ~<span style="color: #009900;">&#93;</span>$ ~<span style="color: #339933;">/</span>Downloads<span style="color: #339933;">/</span>mongodb<span style="color: #339933;">-</span>osx<span style="color: #339933;">-</span>x86_64<span style="color: #339933;">-</span>1.8.1<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>mongo questionsMongoDB shell version<span style="color: #339933;">:</span> 1.8.1
connecting to<span style="color: #339933;">:</span> questions
<span style="color: #339933;">&gt;</span> db.<span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;return counter('question')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #CC0000;">5</span></pre></div></div>

<p>Unfortunately, I was unable to figure out how to call the stored function from within the <a href="https://github.com/guileen/node-mongoskin">mongoskin</a> driver, and ended up writing analogous code, calling <code>findAndModify()</code> within the app code.   <a href="https://github.com/evandhoffman/Quaro/blob/a8cbaa302760a210abe17f5cade5af521e2be9c3/app.js#L145">I finally got it:</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">        db.<span style="color: #660066;">collection</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'counters'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">findAndModify</span><span style="color: #009900;">&#40;</span>
                <span style="color: #009900;">&#123;</span>_id<span style="color: #339933;">:</span><span style="color: #3366CC;">'questions'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
                <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> 
                <span style="color: #009900;">&#123;</span>$inc <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>next<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
                <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>err<span style="color: #339933;">,</span> counter<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
                        <span style="color: #003366; font-weight: bold;">var</span> ins <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> date<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                                author<span style="color: #339933;">:</span> req.<span style="color: #660066;">body</span>.<span style="color: #660066;">author</span><span style="color: #339933;">,</span> body<span style="color: #339933;">:</span> req.<span style="color: #660066;">body</span>.<span style="color: #660066;">body</span><span style="color: #339933;">,</span>
                                tags<span style="color: #339933;">:</span> tags<span style="color: #339933;">,</span> tag_count<span style="color: #339933;">:</span> tagCount<span style="color: #339933;">,</span>
                                answers<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> votes<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
                                _id<span style="color: #339933;">:</span> counter.<span style="color: #660066;">next</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>  
                        db.<span style="color: #660066;">collection</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'questions'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span>ins<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        res.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Added new question: '</span><span style="color: #339933;">+</span>req.<span style="color: #660066;">body</span>.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>   
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><div id="attachment_1362" class="wp-caption aligncenter" style="width: 404px"><a href="http://www.evanhoffman.com/evan/2011/06/23/teaching-myself-node-js-part-3/question-detail2/" rel="attachment wp-att-1362"><img src="http://www.evanhoffman.com/evan/wp-content/uploads/2011/06/question-detail2.png" alt="Question detail" title="Question detail" width="394" height="308" class="size-full wp-image-1362" /></a><p class="wp-caption-text">Question detail</p></div><br />
I tried throwing some code in there to query by either ObjectId() or integer but it didn&#8217;t really work <ins datetime="2011-06-24T01:16:32+00:00">(Edit: I tried this again on Linux and it worked fine)</ins>, so I just deleted all the documents with ObjectIds and everything seems to work fine now.  I think the next step is going to have to be some sort of authentication/session stuff, because typing your name in every time kind of sucks (and makes it hard to do things like list questions by user).</p>
<p>Full code for this revision is <a href="https://github.com/evandhoffman/Quaro/tree/a8cbaa302760a210abe17f5cade5af521e2be9c3">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2011/06/23/teaching-myself-node-js-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript regex for stripping leading &amp; trailing whitespaces</title>
		<link>http://www.evanhoffman.com/evan/2011/06/22/javascript-regex-for-stripping-leading-trailing-whitespaces/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript-regex-for-stripping-leading-trailing-whitespaces</link>
		<comments>http://www.evanhoffman.com/evan/2011/06/22/javascript-regex-for-stripping-leading-trailing-whitespaces/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 04:09:51 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[strip]]></category>
		<category><![CDATA[trim]]></category>
		<category><![CDATA[whitespace]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=1347</guid>
		<description><![CDATA[<code>str.replace(/^(\s*)((\S+\s*?)*)(\s*)$/,"$2");</code>]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2011/06/22/javascript-regex-for-stripping-leading-trailing-whitespaces/&via=EvanHoffman&text=JavaScript regex for stripping leading & trailing whitespaces&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2011/06/22/javascript-regex-for-stripping-leading-trailing-whitespaces/"></g:plusone></div><p>I&#8217;m sure there are a bunch of libraries that do this, but sometimes wrestling with regexes is fun.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&gt;</span> <span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;           This string has some mighty fine whitespace.       &quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&gt;</span> str
<span style="color: #3366CC;">'           This string has some mighty fine whitespace.       '</span>
<span style="color: #339933;">&gt;</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^(\s*)((\S+\s*?)*)(\s*)$/</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;$2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #3366CC;">'This string has some mighty fine whitespace.'</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2011/06/22/javascript-regex-for-stripping-leading-trailing-whitespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Teaching myself node.js: Part 1</title>
		<link>http://www.evanhoffman.com/evan/2011/06/14/teaching-myself-node-js-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=teaching-myself-node-js-part-1</link>
		<comments>http://www.evanhoffman.com/evan/2011/06/14/teaching-myself-node-js-part-1/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 04:50:59 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mongo]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=1323</guid>
		<description><![CDATA[In which I try to learn node.js by building a Quora-like site (since it seems everyone is building a blog).]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2011/06/14/teaching-myself-node-js-part-1/&via=EvanHoffman&text=Teaching myself node.js: Part 1&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2011/06/14/teaching-myself-node-js-part-1/"></g:plusone></div><p>I&#8217;ve been meaning for a while to learn node.js.  I read a couple of books and plenty of blog posts but in the end I find, as usual, I can only learn by doing.  I have most of the fundamentals to get started, I just need to have a project.  The typical tutorials I&#8217;ve found focus on creating a blog; I&#8217;m thinking of something more along the lines of a Quora question/answer site.  I&#8217;ll be trying to write this as I go, which will hopefully prod me into actually doing it this time.  (I have a tendency to bounce around different tenses and I expect this will be worse than usual &#8211; stuff will likely be written in past/present/future at various points).<br />
<span id="more-1323"></span><br />
Installing node is pretty easy, I just <a href="http://nodejs.org/dist/">downloaded the source</a> (I used 0.4.7), configured &#038; compiled it.  For MongoDB I use the <a href="http://www.mongodb.org/display/DOCS/CentOS+and+Fedora+Packages">10gen</a> CentOS/Fedora repository.  With node installed, I installed <a href="http://npmjs.org/">npm</a> to facilitate adding other packages.  I started mongod with
<pre>/etc/init.d/mongodb start</pre>
<p>With everything installed and mongod running I thought about the schema of my object.  One of the coolest things about MongoDB is the fact that it&#8217;s &#8220;schemaless&#8221; and you can basically put anything into the DB, so you just need to think about what your objects look like and you can basically shove them into Mongo in that exact format.  I&#8217;ve never been a fan of ORM stuff for SQL and the Mongo document-store type of DB seems like it eliminates the need for that almost entirely, which is great.  So here&#8217;s what I was thinking would be the central object in this q-a site:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;_id&quot;</span> <span style="color: #339933;">:</span> ObjectId<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;4defd2713fce2e9bc35d09f0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;author&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Bob&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;date&quot;</span> <span style="color: #339933;">:</span> ISODate<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2011-06-08T19:49:48.809Z&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;body&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Is it hot in here?&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;votes&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;answers&quot;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                <span style="color: #009900;">&#123;</span>
                        <span style="color: #3366CC;">&quot;author&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;evan&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;date&quot;</span> <span style="color: #339933;">:</span> ISODate<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2011-06-08T19:48:54.388Z&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;body&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;I think so.&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;votes&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                <span style="color: #009900;">&#123;</span>
                        <span style="color: #3366CC;">&quot;author&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Jim&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;date&quot;</span> <span style="color: #339933;">:</span> ISODate<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2011-06-08T19:51:04.714Z&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;body&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Could be.&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;votes&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                <span style="color: #009900;">&#123;</span>
                        <span style="color: #3366CC;">&quot;author&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Aaron&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;date&quot;</span> <span style="color: #339933;">:</span> ISODate<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2011-06-08T19:51:33.313Z&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;body&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;No&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;votes&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;tags&quot;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                <span style="color: #3366CC;">&quot;question&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;silly&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;stupid&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;microsoft&quot;</span>
        <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So this is a &#8220;question&#8221; and it has an author, a date, an array of tags, a title, a vote count, a &#8220;body&#8221; (maybe a longer version of the question), and an array of &#8220;answers&#8221;.  Answers are embedded objects, each with an author, date, body, and votes.  This seems like a decent place to start.</p>
<p>The way the site would work is someone posts a question and other people answer it.  The answers would just be attached to the post in the &#8220;answers&#8221; array.  Other users can vote on answers and the answer with the most votes would be the &#8220;winner&#8221;.  Not exactly groundbreaking, but seems like it should be pretty easy to implement.</p>
<p>I used npm to install the following packages to aid in development:</p>
<pre>$ npm install express jade mongoskin underscore</pre>
<p>Express is a framework that handles request routing and jade is a templating framework.  I used <a href="http://jekjek1989.wordpress.com/2011/03/06/express-with-jade-on-node-js/">this quick walkthrough</a> to setup a basic express/jade app that works and demonstrates most of what I need to know to get this started.  Another good tutorial is <a href="http://dailyjs.com/2010/11/08/node-tutorial-2/">http://dailyjs.com/2010/11/08/node-tutorial-2/</a>.</p>
<p>After some mucking around I figured out how to use Express properly and it made things much easier.  I used mongoskin as the MongoDB library and jade for the template and managed to rig up something that responds to a &#8220;list&#8221; request at http://server:3000/questions by listing all the questions in the &#8220;questions&#8221; collection.  My code as of this point is available on github <a href="https://github.com/evandhoffman/Quaro/tree/f1ea545719c2284d3993f54592eb276563dc1c8d">here</a>.  The <a href="https://github.com/evandhoffman/Quaro/blob/f1ea545719c2284d3993f54592eb276563dc1c8d/views/list.jade">views/list.jade</a> has the template for the question list, and the code that calls the template is in <a href="https://github.com/evandhoffman/Quaro/blob/f1ea545719c2284d3993f54592eb276563dc1c8d/app.js#L47">app.js</a>.</p>
<p>When viewing in a web browser, it currently looks like this (YMMV based on what&#8217;s in your mongodb, of course):</p>
<div id="attachment_1335" class="wp-caption aligncenter" style="width: 656px"><a href="http://www.evanhoffman.com/evan/2011/06/14/teaching-myself-node-js-part-1/fullscreen-capture-6142011-124430-am/" rel="attachment wp-att-1335"><img src="http://www.evanhoffman.com/evan/wp-content/uploads/2011/06/Fullscreen-capture-6142011-124430-AM.jpg" alt="nodeQuestionList.jpg" title="nodeQuestionList.jpg" width="646" height="609" class="size-full wp-image-1335" /></a><p class="wp-caption-text">nodeQuestionList.jpg</p></div>
<p>That&#8217;s enough for today.  So far I&#8217;m enjoying node.js now that I think I can finally wrap my head around the callback stuff.  Hopefully I can keep up the momentum.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2011/06/14/teaching-myself-node-js-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Code: searching a Binary Search Tree for the largest value strictly less than X</title>
		<link>http://www.evanhoffman.com/evan/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x</link>
		<comments>http://www.evanhoffman.com/evan/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/#comments</comments>
		<pubDate>Sun, 09 May 2010 17:43:17 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[binary search tree]]></category>
		<category><![CDATA[bst]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=1246</guid>
		<description><![CDATA[Java code for creating and searching a Binary Search Tree of any element implementing the Comparable interface.]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/&via=EvanHoffman&text=Java Code: searching a Binary Search Tree for the largest value strictly less than X&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/"></g:plusone></div><p>Someone recently asked me how to do this, so I figured I&#8217;d write it up in Java since it&#8217;s still the language I&#8217;m most comfortable with:</p>
<p>Node.java</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.evanhoffman.bst</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Node in a binary search tree in which values &lt; are in the left branch and 
 * values &gt;= are in the right branch.
 * @author evan
 *
 * @param &lt;V&gt;
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Node<span style="color: #339933;">&lt;</span>V <span style="color: #000000; font-weight: bold;">extends</span> Comparable<span style="color: #339933;">&lt;</span>V<span style="color: #339933;">&gt;&gt;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>Node.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Node<span style="color: #339933;">&lt;</span>V<span style="color: #339933;">&gt;</span> left <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Node<span style="color: #339933;">&lt;</span>V<span style="color: #339933;">&gt;</span> right <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> V value <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Node<span style="color: #009900;">&#40;</span>V t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span> <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> V getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> value<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isLeaf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>left <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> right <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addNode<span style="color: #009900;">&#40;</span>Node<span style="color: #339933;">&lt;</span>V<span style="color: #339933;">&gt;</span> node<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>node.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>left <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				left <span style="color: #339933;">=</span> node<span style="color: #339933;">;</span>
				logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Assigning &quot;</span><span style="color: #339933;">+</span>node.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">+</span>
						<span style="color: #0000ff;">&quot;to left child of node &quot;</span><span style="color: #339933;">+</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				left.<span style="color: #006633;">addNode</span><span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>right <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				right <span style="color: #339933;">=</span> node<span style="color: #339933;">;</span>
				logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Assigning &quot;</span><span style="color: #339933;">+</span>node.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">+</span>
						<span style="color: #0000ff;">&quot;to right child of node &quot;</span><span style="color: #339933;">+</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				right.<span style="color: #006633;">addNode</span><span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> V findMaxStrictlyLessThan<span style="color: #009900;">&#40;</span>V t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> findMaxStrictlyLessThan<span style="color: #009900;">&#40;</span>t, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Returns the greatest value in the tree strictly
	 * less than (as defined by {@link Comparable#compareTo(Object)} the given value.
	 * @param t
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> V findMaxStrictlyLessThan<span style="color: #009900;">&#40;</span>V t, V currentMax<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>t.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span>t <span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; is less than current node &quot;</span><span style="color: #339933;">+</span>value<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, checking left (if it exists)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> left <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> currentMax <span style="color: #339933;">:</span> left.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span>t, currentMax<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span>t <span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; is &gt;= current node &quot;</span><span style="color: #339933;">+</span>value<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, checking right (if exists)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			currentMax <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> right <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> currentMax <span style="color: #339933;">:</span> right.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span>t, currentMax<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isLeaf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;{value=&quot;</span><span style="color: #339933;">+</span>value<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;}&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;{value=&quot;</span><span style="color: #339933;">+</span>value<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, left=&quot;</span><span style="color: #339933;">+</span>left<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;, right=&quot;</span><span style="color: #339933;">+</span>right<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;}&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>IntBstBuilder.java:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.evanhoffman.bst</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.BasicConfigurator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> IntBstBuilder <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> min <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> max <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> size <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Random</span> rng <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>IntBstBuilder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		BasicConfigurator.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Node<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> root <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Node<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>max <span style="color: #339933;">-</span> min<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">int</span> num <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">abs</span><span style="color: #009900;">&#40;</span>rng.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #009900;">&#40;</span>max <span style="color: #339933;">-</span> min<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> min<span style="color: #339933;">;</span>
			Node<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> newNode <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Node<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			root.<span style="color: #006633;">addNode</span><span style="color: #009900;">&#40;</span>newNode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>root<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>root.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>root.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>root.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">130</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>root.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">220</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>root.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Output:</p>
<pre lang="" line="1">
0 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 192 to right child of node 100
1 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 140 to left child of node 192
1 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 162 to right child of node 140
1 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 54 to left child of node 100
1 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 155 to left child of node 162
1 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 118 to left child of node 140
2 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 52 to left child of node 54
2 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 184 to right child of node 162
2 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 41 to left child of node 52
2 [main] DEBUG com.evanhoffman.bst.Node  - Assigning 161 to right child of node 155
2 [main] INFO com.evanhoffman.bst.IntBstBuilder  - {value=100, left={value=54, left={value=52, left={value=41}, right=null}, right=null}, right={value=192, left={value=140, left={value=118}, right={value=162, left={value=155, left=null, right={value=161}}, right={value=184}}}, right=null}}
2 [main] DEBUG com.evanhoffman.bst.Node  - 50 is less than current node 100, checking left (if it exists)
2 [main] DEBUG com.evanhoffman.bst.Node  - 50 is less than current node 54, checking left (if it exists)
2 [main] DEBUG com.evanhoffman.bst.Node  - 50 is less than current node 52, checking left (if it exists)
2 [main] DEBUG com.evanhoffman.bst.Node  - 50 is >= current node 41, checking right (if exists)
2 [main] INFO com.evanhoffman.bst.IntBstBuilder  - 41
2 [main] DEBUG com.evanhoffman.bst.Node  - 90 is less than current node 100, checking left (if it exists)
2 [main] DEBUG com.evanhoffman.bst.Node  - 90 is >= current node 54, checking right (if exists)
2 [main] INFO com.evanhoffman.bst.IntBstBuilder  - 54
2 [main] DEBUG com.evanhoffman.bst.Node  - 130 is >= current node 100, checking right (if exists)
2 [main] DEBUG com.evanhoffman.bst.Node  - 130 is less than current node 192, checking left (if it exists)
3 [main] DEBUG com.evanhoffman.bst.Node  - 130 is less than current node 140, checking left (if it exists)
3 [main] DEBUG com.evanhoffman.bst.Node  - 130 is >= current node 118, checking right (if exists)
3 [main] INFO com.evanhoffman.bst.IntBstBuilder  - 118
3 [main] DEBUG com.evanhoffman.bst.Node  - 220 is >= current node 100, checking right (if exists)
3 [main] DEBUG com.evanhoffman.bst.Node  - 220 is >= current node 192, checking right (if exists)
3 [main] INFO com.evanhoffman.bst.IntBstBuilder  - 192
3 [main] DEBUG com.evanhoffman.bst.Node  - -100 is less than current node 100, checking left (if it exists)
3 [main] DEBUG com.evanhoffman.bst.Node  - -100 is less than current node 54, checking left (if it exists)
3 [main] DEBUG com.evanhoffman.bst.Node  - -100 is less than current node 52, checking left (if it exists)
3 [main] DEBUG com.evanhoffman.bst.Node  - -100 is less than current node 41, checking left (if it exists)
3 [main] INFO com.evanhoffman.bst.IntBstBuilder  - 
</pre>
<p>StringBstBuilder.java:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.evanhoffman.bst</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileNotFoundException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.BasicConfigurator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StringBstBuilder <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> size <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Random</span> rng <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>StringBstBuilder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> words <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> getWords<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> words<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	StringBstBuilder<span style="color: #009900;">&#40;</span><span style="color: #003399;">File</span> f, <span style="color: #000066; font-weight: bold;">int</span> maxLines<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Creating &quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; with word list file: &quot;</span><span style="color: #339933;">+</span>f<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; up to &quot;</span><span style="color: #339933;">+</span>maxLines<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; lines&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">BufferedReader</span> br <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileReader</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> maxLines<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> br.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				words.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				i<span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
			logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Added &quot;</span><span style="color: #339933;">+</span>words.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; words to list&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">FileNotFoundException</span> fe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File not found: &quot;</span><span style="color: #339933;">+</span>f,fe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>fe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;IO Exception: &quot;</span><span style="color: #339933;">+</span>ie.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,ie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>ie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		BasicConfigurator.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		StringBstBuilder sbt <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBstBuilder<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>, <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> words <span style="color: #339933;">=</span> sbt.<span style="color: #006633;">getWords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> wordListSize <span style="color: #339933;">=</span> words.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Random number between 1/4 and 3/4 through the list.</span>
		<span style="color: #000066; font-weight: bold;">int</span> seedWordIndex <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">abs</span><span style="color: #009900;">&#40;</span>rng.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #009900;">&#40;</span>wordListSize<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>wordListSize <span style="color: #339933;">/</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Node<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> root <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Node<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>words.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>seedWordIndex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Root word: &quot;</span><span style="color: #339933;">+</span>root.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">abs</span><span style="color: #009900;">&#40;</span>rng.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #009900;">&#40;</span>words.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			Node<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> newNode <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Node<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>words.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			root.<span style="color: #006633;">addNode</span><span style="color: #009900;">&#40;</span>newNode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Entire tree: &quot;</span><span style="color: #339933;">+</span>root<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> searches <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;andy&quot;</span>, <span style="color: #0000ff;">&quot;joker&quot;</span>, <span style="color: #0000ff;">&quot;kale&quot;</span>, <span style="color: #0000ff;">&quot;moonshine&quot;</span>, <span style="color: #0000ff;">&quot;zebra&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> str <span style="color: #339933;">:</span> searches<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Search for &quot;</span><span style="color: #339933;">+</span>str<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> s <span style="color: #339933;">=</span> root.<span style="color: #006633;">findMaxStrictlyLessThan</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max word: &quot;</span><span style="color: #339933;">+</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Output:</p>
<pre lang="" line="1">
0 [main] DEBUG com.evanhoffman.bst.StringBstBuilder  - Creating class com.evanhoffman.bst.StringBstBuilder with word list file: /Users/evan/Downloads/scowl-7.1/final/english-words.20 up to 10000 lines
47 [main] DEBUG com.evanhoffman.bst.StringBstBuilder  - Added 7951 words to list
48 [main] DEBUG com.evanhoffman.bst.StringBstBuilder  - Root word: patient's
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning scroll's to right child of node patient's
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning dual to left child of node patient's
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning bat to left child of node dual
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning moderate to right child of node dual
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning abort to left child of node bat
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning migrates to left child of node moderate
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning terrifying to right child of node scroll's
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning equilibrium to left child of node migrates
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning polynomial to left child of node scroll's
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning tomatoes to right child of node terrifying
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning unusable to right child of node tomatoes
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning nailing to right child of node moderate
48 [main] DEBUG com.evanhoffman.bst.Node  - Assigning supporter to left child of node terrifying
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning prosecution to right child of node polynomial
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning management to right child of node equilibrium
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning disabled to right child of node bat
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning planted to left child of node polynomial
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning midday to right child of node management
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning cloth to left child of node disabled
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning hip to left child of node management
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning tune's to left child of node unusable
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning mortal to left child of node nailing
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning dangers to right child of node cloth
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning concentrate to left child of node dangers
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning intimate to right child of node hip
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning stairs to left child of node supporter
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning attorney to right child of node abort
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning globally to left child of node hip
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning vertical to right child of node unusable
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning close's to left child of node cloth
49 [main] DEBUG com.evanhoffman.bst.Node  - Assigning debatable to right child of node dangers
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning guarding to right child of node globally
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning aided to left child of node attorney
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning contend to right child of node concentrate
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning shined to left child of node stairs
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning journals to right child of node intimate
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning warmed to right child of node vertical
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning blaming to left child of node close's
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning ingredient to left child of node intimate
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning gleaning to left child of node globally
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning boys to right child of node blaming
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning stream's to right child of node stairs
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning tragedy to left child of node tune's
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning brands to right child of node boys
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning revenge to right child of node prosecution
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning knight to right child of node journals
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning discard to right child of node disabled
50 [main] DEBUG com.evanhoffman.bst.Node  - Assigning successor to right child of node stream's
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning synonymous to right child of node supporter
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning bow to left child of node boys
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning satisfaction to right child of node revenge
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning mutters to right child of node mortal
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning tray to right child of node tragedy
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning linkage to right child of node knight
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning face's to left child of node gleaning
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning decreasing to right child of node debatable
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning spoiling to right child of node shined
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning slave's to left child of node spoiling
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning clarified to right child of node brands
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning inspection to right child of node ingredient
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning technically to right child of node synonymous
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning supervises to right child of node successor
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning disconnect to right child of node discard
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning whence to right child of node warmed
51 [main] DEBUG com.evanhoffman.bst.Node  - Assigning creator to right child of node contend
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning oppress to right child of node nailing
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning magnificent to right child of node linkage
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning launch to left child of node linkage
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning compensation to left child of node concentrate
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning cave to left child of node clarified
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning unbearable to right child of node tune's
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning verifies to left child of node vertical
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning compact to left child of node compensation
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning immense to left child of node ingredient
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning empire to left child of node equilibrium
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning foreseeable to right child of node face's
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning joking to left child of node journals
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning opts to right child of node oppress
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning convicting to left child of node creator
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning divisions to right child of node disconnect
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning fascinate to left child of node foreseeable
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning reactions to left child of node revenge
52 [main] DEBUG com.evanhoffman.bst.Node  - Assigning discriminated to left child of node divisions
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning unrealistic to right child of node unbearable
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning crowds to right child of node creator
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning marketed to left child of node midday
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning broad to left child of node cave
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning socket to right child of node slave's
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning verbal to left child of node verifies
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning register's to right child of node reactions
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning attributes to right child of node attorney
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning clarity to right child of node clarified
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning engage to right child of node empire
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning succeeded to left child of node successor
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning resembled to right child of node register's
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning kernel to left child of node knight
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning dot to right child of node divisions
53 [main] DEBUG com.evanhoffman.bst.Node  - Assigning wrecked to right child of node whence
54 [main] DEBUG com.evanhoffman.bst.Node  - Assigning gratuitously to left child of node guarding
54 [main] DEBUG com.evanhoffman.bst.Node  - Assigning syndicate to left child of node synonymous
54 [main] INFO com.evanhoffman.bst.StringBstBuilder  - Entire tree: {value=patient's, left={value=dual, left={value=bat, left={value=abort, left=null, right={value=attorney, left={value=aided}, right={value=attributes}}}, right={value=disabled, left={value=cloth, left={value=close's, left={value=blaming, left=null, right={value=boys, left={value=bow}, right={value=brands, left=null, right={value=clarified, left={value=cave, left={value=broad}, right=null}, right={value=clarity}}}}}, right=null}, right={value=dangers, left={value=concentrate, left={value=compensation, left={value=compact}, right=null}, right={value=contend, left=null, right={value=creator, left={value=convicting}, right={value=crowds}}}}, right={value=debatable, left=null, right={value=decreasing}}}}, right={value=discard, left=null, right={value=disconnect, left=null, right={value=divisions, left={value=discriminated}, right={value=dot}}}}}}, right={value=moderate, left={value=migrates, left={value=equilibrium, left={value=empire, left=null, right={value=engage}}, right={value=management, left={value=hip, left={value=globally, left={value=gleaning, left={value=face's, left=null, right={value=foreseeable, left={value=fascinate}, right=null}}, right=null}, right={value=guarding, left={value=gratuitously}, right=null}}, right={value=intimate, left={value=ingredient, left={value=immense}, right={value=inspection}}, right={value=journals, left={value=joking}, right={value=knight, left={value=kernel}, right={value=linkage, left={value=launch}, right={value=magnificent}}}}}}, right={value=midday, left={value=marketed}, right=null}}}, right=null}, right={value=nailing, left={value=mortal, left=null, right={value=mutters}}, right={value=oppress, left=null, right={value=opts}}}}}, right={value=scroll's, left={value=polynomial, left={value=planted}, right={value=prosecution, left=null, right={value=revenge, left={value=reactions, left=null, right={value=register's, left=null, right={value=resembled}}}, right={value=satisfaction}}}}, right={value=terrifying, left={value=supporter, left={value=stairs, left={value=shined, left=null, right={value=spoiling, left={value=slave's, left=null, right={value=socket}}, right=null}}, right={value=stream's, left=null, right={value=successor, left={value=succeeded}, right={value=supervises}}}}, right={value=synonymous, left={value=syndicate}, right={value=technically}}}, right={value=tomatoes, left=null, right={value=unusable, left={value=tune's, left={value=tragedy, left=null, right={value=tray}}, right={value=unbearable, left=null, right={value=unrealistic}}}, right={value=vertical, left={value=verifies, left={value=verbal}, right=null}, right={value=warmed, left=null, right={value=whence, left=null, right={value=wrecked}}}}}}}}}
55 [main] INFO com.evanhoffman.bst.StringBstBuilder  - Search for andy:
55 [main] DEBUG com.evanhoffman.bst.Node  - andy is less than current node patient's, checking left (if it exists)
55 [main] DEBUG com.evanhoffman.bst.Node  - andy is less than current node dual, checking left (if it exists)
55 [main] DEBUG com.evanhoffman.bst.Node  - andy is less than current node bat, checking left (if it exists)
55 [main] DEBUG com.evanhoffman.bst.Node  - andy is >= current node abort, checking right (if exists)
55 [main] DEBUG com.evanhoffman.bst.Node  - andy is less than current node attorney, checking left (if it exists)
55 [main] DEBUG com.evanhoffman.bst.Node  - andy is >= current node aided, checking right (if exists)
55 [main] INFO com.evanhoffman.bst.StringBstBuilder  - max word: aided
56 [main] INFO com.evanhoffman.bst.StringBstBuilder  - Search for joker:
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is less than current node patient's, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is >= current node dual, checking right (if exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is less than current node moderate, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is less than current node migrates, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is >= current node equilibrium, checking right (if exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is less than current node management, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is >= current node hip, checking right (if exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is >= current node intimate, checking right (if exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is less than current node journals, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - joker is less than current node joking, checking left (if it exists)
56 [main] INFO com.evanhoffman.bst.StringBstBuilder  - max word: intimate
56 [main] INFO com.evanhoffman.bst.StringBstBuilder  - Search for kale:
56 [main] DEBUG com.evanhoffman.bst.Node  - kale is less than current node patient's, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - kale is >= current node dual, checking right (if exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - kale is less than current node moderate, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - kale is less than current node migrates, checking left (if it exists)
56 [main] DEBUG com.evanhoffman.bst.Node  - kale is >= current node equilibrium, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - kale is less than current node management, checking left (if it exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - kale is >= current node hip, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - kale is >= current node intimate, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - kale is >= current node journals, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - kale is less than current node knight, checking left (if it exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - kale is less than current node kernel, checking left (if it exists)
57 [main] INFO com.evanhoffman.bst.StringBstBuilder  - max word: journals
57 [main] INFO com.evanhoffman.bst.StringBstBuilder  - Search for moonshine:
57 [main] DEBUG com.evanhoffman.bst.Node  - moonshine is less than current node patient's, checking left (if it exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - moonshine is >= current node dual, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - moonshine is >= current node moderate, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - moonshine is less than current node nailing, checking left (if it exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - moonshine is less than current node mortal, checking left (if it exists)
57 [main] INFO com.evanhoffman.bst.StringBstBuilder  - max word: moderate
57 [main] INFO com.evanhoffman.bst.StringBstBuilder  - Search for zebra:
57 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node patient's, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node scroll's, checking right (if exists)
57 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node terrifying, checking right (if exists)
58 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node tomatoes, checking right (if exists)
58 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node unusable, checking right (if exists)
58 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node vertical, checking right (if exists)
58 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node warmed, checking right (if exists)
58 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node whence, checking right (if exists)
58 [main] DEBUG com.evanhoffman.bst.Node  - zebra is >= current node wrecked, checking right (if exists)
58 [main] INFO com.evanhoffman.bst.StringBstBuilder  - max word: wrecked
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>House</title>
		<link>http://www.evanhoffman.com/evan/2009/06/29/house/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=house</link>
		<comments>http://www.evanhoffman.com/evan/2009/06/29/house/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 03:23:26 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[house]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=116</guid>
		<description><![CDATA[TweetGuess we&#8217;re moving. I&#8217;m reading about iPhone development. Doesn&#8217;t look terrible.]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2009/06/29/house/&via=EvanHoffman&text=House&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2009/06/29/house/"></g:plusone></div><p>Guess we&#8217;re moving.</p>
<p>I&#8217;m <a href="http://www.amazon.com/exec/obidos/ASIN/193398886X/ref=nosim/evanhoffmasho-20">reading about iPhone development</a>.  Doesn&#8217;t look terrible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2009/06/29/house/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

