<?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>Andrew Pietsch&#039;s Weblog &#187; GWT</title>
	<atom:link href="http://pietschy.com/blog/category/development/gwt/feed/" rel="self" type="application/rss+xml" />
	<link>http://pietschy.com/blog</link>
	<description>Things and stuff</description>
	<lastBuildDate>Sun, 01 Aug 2010 07:43:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Pectin 0.8 Released</title>
		<link>http://pietschy.com/blog/2010/08/pectin-0-8-released/</link>
		<comments>http://pietschy.com/blog/2010/08/pectin-0-8-released/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 07:26:58 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[GWT]]></category>

		<guid isPermaLink="false">http://pietschy.com/blog/?p=234</guid>
		<description><![CDATA[I&#8217;ve just released Pectin 0.8 with lots of new features.  Some of the more significant&#160;are: More generalised binding support, i.e. you no longer need to use forms if you don&#8217;t need&#160;plugins. Beans binding now supports basic nested property&#160;paths. Command improvements &#8230; <a href="http://pietschy.com/blog/2010/08/pectin-0-8-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just released <a href="http://code.google.com/p/gwt-pectin/">Pectin 0.8</a> with lots of new features.  Some of the more significant&nbsp;are:</p>
<ul>
<li>More generalised binding support, i.e. you no longer need to use forms if you don&#8217;t need&nbsp;plugins.</li>
<li>Beans binding now supports basic nested property&nbsp;paths.</li>
<li>Command improvements including new exception&nbsp;handlers.</li>
<li>..and lots of other&nbsp;improvements.</li>
</ul>
<p>Check out the <a href="http://code.google.com/p/gwt-pectin/wiki/ReleaseNotes">release notes for more&nbsp;information</a>.</p>
<p>You can get pectin <a href="http://code.google.com/p/gwt-pectin/downloads/list">from the download&nbsp;page</a>.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2010/08/pectin-0-8-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using &lt;? extends T&gt; and &lt;? super T&gt; for reduce style functions that operate on collections</title>
		<link>http://pietschy.com/blog/2010/02/using-extends-t-and-super-t-for-reduce-style-functions-that-operate-on-collections/</link>
		<comments>http://pietschy.com/blog/2010/02/using-extends-t-and-super-t-for-reduce-style-functions-that-operate-on-collections/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 01:15:51 +0000</pubDate>
		<dc:creator>pietschy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[GWT]]></category>

		<guid isPermaLink="false">http://pietschy.com/blog/?p=226</guid>
		<description><![CDATA[One of the cases I&#8217;ve had to deal with in gwt-pectin is creating Reduce style functions that operate on a collection of values.  The basic idea is to define interface of the&#160;form. public interface Reduce&#60;R,T&#62; { R reduce(List&#60;T&#62; source); } &#8230; <a href="http://pietschy.com/blog/2010/02/using-extends-t-and-super-t-for-reduce-style-functions-that-operate-on-collections/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the cases I&#8217;ve had to deal with in <a href="http://code.google.com/p/gwt-pectin/">gwt-pectin</a> is creating Reduce style functions that operate on a collection of values.  The basic idea is to define interface of the&nbsp;form.</p>
<pre>public interface Reduce&lt;R,T&gt; {
   R reduce(List&lt;T&gt; source);
}</pre>
<p>I use this on my ReducingValueModel&lt;R,T&gt; to automatically compute fields such as a sum&#8217;s of numbers, or a string representation of a list and so forth.  So on my ReducingValueModel I have a method to configure the reducing function to use as&nbsp;follows.</p>
<pre>public class ReducingValueModel&lt;R,T&gt; {
<span style="color: #999999;">   // our function</span>
   private Reduce&lt;R,T&gt; function;
<span style="color: #999999;">   // and it's setter</span>
   public void setFunction(Reduce&lt;R,T&gt; function) {
      this.function = function;
      recompute();
   }
   <span style="color: #999999;">// and every thing else that makes it go
   ...
</span>}</pre>
<p>This works fine when define a new function for each different combination of R and T.  The trouble appears when you want to create a generic Reduce function that you can use on any ReductingValueModel.   Something like a generic &#8220;list to string&#8221; style function for&nbsp;example:</p>
<pre>public class ListToStringFunction&lt;String, Object&gt; {
<span style="color: #c0c0c0;">   // we can convert any list of objects to a string</span>
   public String reduce(List&lt;Object&gt; values) {
     <span style="color: #c0c0c0;">// concate our list values and return the result.</span>
     return ...;
   }
}</pre>
<p>So now lets try and use&nbsp;it.</p>
<pre>ReducingValueModel&lt;String, Integer&gt; reducingModel = ...;
<span style="color: #999999;">// This won't compile...</span>
reductingModel.setFunction(new ListToStringFunction());
</pre>
<p>But this won&#8217;t compile because ListToStringFunction is a Reduce&lt;String, Object&gt; and not Reduce&lt;String, Integer&gt;.  So we bung in the standard &lt;? super T&gt; clause on the ReducingValueModel so it can accept a function that works on any super&nbsp;type.</p>
<pre>public class ReducingValueModel&lt;R,T&gt; {
<pre>  private <strong>Reduce&lt;R, ? super T&gt;</strong> function;
<span style="color: #c0c0c0;">  <span style="color: #999999;">// now lets use &lt;? super S&gt; so we can use functions that
  // operate on any super source type.</span></span>
  public void setFunction(<strong>Reduce&lt;R,? super T&gt;</strong> function) {
    this.function = function;
    recompute();
  }
}</pre>
</pre>
<p>And while it looks like this should work, it doesn&#8217;t.  The problem is that were I&#8217;m using the Reduce function it&#8217;s now defined as a Reduce&lt;R, ? super T&gt; (making it a Reduce&lt;T,Object&gt; for all intents and purposes) so it can&#8217;t accept any old List&lt;T&gt; as an&nbsp;argument.</p>
<pre>public class ReducingValueModel&lt;R,T&gt; {

  private <strong>Reduce&lt;R, ? super T&gt;</strong> function;

  protected void recompute()  {
    ArrayList&lt;T&gt; values = ...;  // prepare the values..
    <span style="color: #999999;">// now this won't compile because our the function we
    // passed in only works on List&lt;? super T&gt; and not List&lt;T&gt;</span>
    <strong>R computedValue = function.compute(values);</strong>
    fireValueChangeEvent(computedValue);
  }
}</pre>
<p>Fortunately the fix is simple.  We need to update our Reduce&lt;R,T&gt; interface to accept any values that extend T. &nbsp;I.e.</p>
<pre>public interface Reduce&lt;R,T&gt; {
<span style="color: #999999;">  <span style="color: #999999;"> // this allows our Reduce&lt;R, ? super T&gt; to operate
   // on any list</span></span><span style="color: #999999;"> that extends T</span>
   T reduce(<strong>List&lt;? extends T&gt;</strong> source);
}</pre>
<p>Now our ReducingValueModel&lt;R,T&gt; can accept functions that work on any super type of T and our Reduce&lt;R,T&gt; can accept any list whose values that extend&nbsp;T.</p>
<p>So the two things to do&nbsp;are:</p>
<ol>
<li>Make sure your functions can operate on source collections of type &lt;? extends T&gt;. i.e.
<pre>public interface Reduce&lt;R,T&gt; {
   R reduce(<strong>List&lt;? extends T&gt;</strong> source)
}</pre>
</li>
<li>Allow users to configure functions use &lt;? super S&gt; for the source values.  i.e.
<pre>public void setFunction(<strong>Reduce&lt;R, ? super T&gt;</strong> function) {...}</pre>
</li>
</ol>
<p>All&nbsp;good.</p>
]]></content:encoded>
			<wfw:commentRss>http://pietschy.com/blog/2010/02/using-extends-t-and-super-t-for-reduce-style-functions-that-operate-on-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

