posts - 431,  comments - 344,  trackbacks - 0
          JQL is an extension for Java that provides support for querying collections of objects. These queries can be run over objects in collections in your program, or even used to check expressions on all instances of specific types at runtime.

          Queries provide a powerful abstraction for dealing with sets of objects, allowing the query engine to take care of the implementation details. This allows for shorter, clearer code, and permits the query engine to dynamically optimize query evaluation strategies as the runtime context changes.

          Queries can also be cached and that cache incrementally maintained - this greatly increases their efficiency, and can offer improved performance for many common collection operations.

          A brief example!

          Say we're building a crossword puzzle. We've got a list of candidate words for our puzzle, and a list of the lengths of the gaps we need to fill:
          ArrayList<String> words = dict.getWords(Puzzle.MEDIUM);
          ArrayList<Integer> gaplengths = puzzle.getGapLengths();

          Now we've got a truly marvelous algorithm for building a crossword puzzle (that this webpage is too narrow to contain), which relies on having a list of pairs of [length, word].
          Using a JQL query, we can build this list with ease:
          List<Object[]> matches = selectAll(String w : words,
                                             Integer i : gaplengths |
                                             w.length() == i);
          Contrast with how we could do this in normal Java:
          List<Object[]> matches = new ArrayList<Object[]>();
          for(String w : words){
            for(Integer i : gaplengths){
              if(w.length() == i)
                matches.add(new Object[i,w]);
            }
          }
          The JQL query and the Java code will produce the same list of results - but the JQL version is shorter, neater, and abstracts away the exact method of finding the matches. For a more in-depth look on why this can be helpful, please look at our Examples page.

          下載地址:http://homepages.mcs.vuw.ac.nz/~djp/jql/download.html
          posted on 2009-08-06 09:11 周銳 閱讀(297) 評(píng)論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 本溪市| 宜昌市| 电白县| 文成县| 南充市| 华池县| 建德市| 金川县| 太仓市| 塔城市| 北辰区| 青冈县| 冕宁县| 牟定县| 广西| 深水埗区| 龙山县| 苍溪县| 咸宁市| 安阳市| 徐汇区| 天镇县| 兴安盟| 华池县| 延津县| 门源| 贵定县| 宜兴市| 久治县| 临沂市| 拉萨市| 汶上县| 美姑县| 郴州市| 勐海县| 辽阳市| 浦城县| 壤塘县| 聂拉木县| 洛阳市| 曲靖市|