Wicket
  1. Wicket
  2. WICKET-5233

Component.getBehaviors() can be implemented slightly more efficiently

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 6.8.0
    • Fix Version/s: 6.9.0, 7.0.0-M1
    • Component/s: wicket
    • Labels:

      Description

      Component.getBehaviors() is implemented as
      "return getBehaviors(Behavior.class);"
      but can be
      "return getBehaviors(null);"

      As mentioned in getBehaviors(Class type) documentation: "The type or null for all". The handling code in Behaviors.getBehaviors method is following:

      if (obj != null && obj instanceof Behavior)
      {
      if (type == null || type.isAssignableFrom(obj.getClass()))

      { subset.add((M)obj); }

      }

      When called with "null" parameter, only the first condition of inner "if" is tested. If called with Behavior.class, all conditions has to be evaluated and you call "obj instanceof Behavior" twice in fact (because "Behavior.class.isAssignableFrom(obj.getClass())" is equivalent to "obj instanceof Behavior").

        Activity

        Hide
        Martin Grigorov added a comment -

        Thanks!

        Show
        Martin Grigorov added a comment - Thanks!

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Ota Hauptmann
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development