Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're right, I think this would be an interesting project.</p> <p>There are loads of approaches you could take to this. One would be to create a <code>Query</code> object that you build up by calling the methods in turn.</p> <p>So something like this:</p> <pre><code>public class Query { public static Query select(String...fields){ //code omitted return query; } public Query from(Collection&lt;Object&gt; collection){ //code omitted return this; } public Query where(String field, Object value){ //code omitted return this; } } </code></pre> <p>So you could then do:</p> <pre><code>Query.select("field1", "field2").from(myList).... </code></pre> <p>You'd need to keep track of which values had been selected at each point and whether they next condition should add to them (as in the case of an <code>or</code>) or remove from them (as in the case of an <code>and</code>). There will be lots of edge cases. My advice would be to start off with something very simple like the <code>ints</code> example and work from there.</p> <p>When you get on to doing the object version you'll need to use <a href="http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29" rel="nofollow">reflection</a> to access the fields of the object.</p> <p>Once you've done that you might want to consider improving the type safety of your code by using <a href="http://en.wikipedia.org/wiki/Generics_in_Java" rel="nofollow">generics</a>.</p> <p>All in all, lots of scope for an interesting project. However, it feels like the sort of thing where there will be lots of edge cases, so worth thinking through the design a fair bit and would also not be a bad idea to do a fair bit of <a href="http://en.wikipedia.org/wiki/Unit_testing" rel="nofollow">unit testing.</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload