Uploaded image for project: 'Commons JXPath'
  1. Commons JXPath
  2. JXPATH-63

Improving MapDynamicPropertyHandler

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • Nightly Builds
    • None
    • None
    • Operating System: All
      Platform: All

    • 26853

    Description

      in: org.apache.commons.jxpath.MapDynamicPropertyHandler

      If the following code:
      public String[] getPropertyNames(Object object) {
      Map map = (Map) object;
      String names[] = new String[map.size()];
      Iterator it = map.keySet().iterator();
      for (int i = 0; i < names.length; i++)

      { names[i] = String.valueOf(it.next()); }

      return names;
      }

      could be replaced by:
      public String[] getPropertyNames(Object object) {
      Set keys = ((Map) object).keySet();
      String names[] = new String[keys.size()];
      Iterator it = keys.iterator();
      for (int i = 0; i < names.length; i++)

      { names[i] = String.valueOf(it.next()); }

      return names;
      }

      This would permit to support very special cases where Map.keySet().size() !=
      Map.size() [which, I know, does not conform to the Map API].
      Anyway, in general, it is better to compute the size on the Set we are actually
      using and not on another one related to it...

      Thanks,

      Yann Duponchel.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ydu@zurich.ibm.com Yann Duponchel
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: