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 周銳 閱讀(294) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 琼海市| 灵川县| 循化| 四会市| 海伦市| 西宁市| 青州市| 彭州市| 祁连县| 吉林市| 汉寿县| 凤庆县| 青海省| 凤山市| 丰台区| 镇宁| 乡宁县| 滦南县| 防城港市| 汕尾市| 丰县| 满城县| 张家界市| 唐河县| 昌平区| 洪湖市| 湖州市| 澄城县| 凤阳县| 中卫市| 明光市| 陆丰市| 承德市| 临朐县| 旺苍县| 昭觉县| 前郭尔| 和政县| 环江| 石林| 于田县|