<?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>Silveira Neto &#187; Jedi</title>
	<atom:link href="http://silveiraneto.net/tag/jedi/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Jedi Name</title>
		<link>http://silveiraneto.net/2009/11/08/jedi-name/</link>
		<comments>http://silveiraneto.net/2009/11/08/jedi-name/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 20:47:33 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Jedi]]></category>
		<category><![CDATA[joke]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[star wars]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2918</guid>
		<description><![CDATA[A simple Java class that calculates your Jedi name based on your first, last name, mother&#8217;s maiden name and the city you grew up. /* Jedi first name: 1st 3 letters of last name + 1st 2 letters of first name Jedi last name: 1st 2 letters of mother's maiden name + 1st 3 letters [...]]]></description>
			<content:encoded><![CDATA[<p><center><img src="http://silveiraneto.net/wp-content/uploads/2009/11/rsz_lightsaber.jpg" alt="lightsaber" title="lightsaber" width="145" height="175" class="alignnone size-full wp-image-2921" /></center></p>
<p>A simple Java class that calculates your Jedi name based on your first, last name, mother&#8217;s maiden name and the city you grew up.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
 Jedi first name: 1st 3 letters of last name + 1st 2 letters of first name
 Jedi last name: 1st 2 letters of mother's maiden name + 1st 3 letters of city you were raised in
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JediName <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> capitalize<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> s.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span>0,<span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> s.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>,s.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> sub<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s, <span style="color: #000066; font-weight: bold;">int</span> begin, <span style="color: #000066; font-weight: bold;">int</span> end<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> s.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span>begin, <span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;=</span>end<span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>end<span style="color: #339933;">:</span>s.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> generate<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> firstName, <span style="color: #003399;">String</span> lastName, <span style="color: #003399;">String</span> city, <span style="color: #003399;">String</span> mother <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">String</span> jediFirstName <span style="color: #339933;">=</span> capitalize<span style="color: #009900;">&#40;</span>sub<span style="color: #009900;">&#40;</span>lastName, 0, <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> sub<span style="color: #009900;">&#40;</span>firstName, 0,<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
      <span style="color: #003399;">String</span> jediLastName <span style="color: #339933;">=</span> capitalize<span style="color: #009900;">&#40;</span>sub<span style="color: #009900;">&#40;</span>mother,0,<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span> sub<span style="color: #009900;">&#40;</span>city,0,<span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
      <span style="color: #000000; font-weight: bold;">return</span> jediFirstName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> jediLastName;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>I used inline conditional expression ()?: to avoid raise  a IndexOutOfBoundsException when the string is to small to cut the proper size we want.</p>
<p>And a example of how to use it:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JediNameTester <span style="color: #009900;">&#123;</span>
	<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>
		<span style="color: #003399;">String</span> myJediName <span style="color: #339933;">=</span> JediName.<span style="color: #006633;">generate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pedro&quot;</span>, <span style="color: #0000ff;">&quot;Madeira&quot;</span>, <span style="color: #0000ff;">&quot;Fortaleza&quot;</span>, <span style="color: #0000ff;">&quot;Maria&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>myJediName<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>My jedi name is <em>Siljo Iruba</em>. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/11/08/jedi-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

