Class Immutables


  • public final class Immutables
    extends java.lang.Object
    An immutables utils.
    Author:
    jumperchen
    • Constructor Summary

      Constructors 
      Constructor Description
      Immutables()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends IComponent>
      java.util.List<T>
      createComponents​(java.lang.String uri, java.util.Map<?,​?> arg)
      Creates IComponents from Components that don't belong to any page from a page file specified by an URI.
      static <T extends IComponent>
      java.util.List<T>
      createComponents​(org.zkoss.zk.ui.metainfo.PageDefinition pagedef, java.util.Map<?,​?> arg)
      Creates IComponents from Components that don't belong to any page from the specified page definition.
      static <T extends IComponent>
      java.util.List<T>
      createComponentsDirectly​(java.lang.String content, java.lang.String extension, java.util.Map<?,​?> arg)
      Creates IComponents from Components that don't belong to any page from the raw content specified by a string.
      static <T extends IComponent>
      IReplacer<T>
      newReplacer​(T root)
      Constructs a replacer for replacing the descendant of the IComponent tree in a bulk execution for multiple replacements.
      static IComponent proxyIChild​(org.zkoss.zk.ui.Component instance)  
      static IComponent proxyIChild​(org.zkoss.zk.ui.Component instance, java.lang.Class<? extends org.zkoss.zk.ui.Component> skipClass)  
      static java.util.List<? extends IComponent> proxyIChildren​(org.zkoss.zk.ui.Component instance)  
      static <T extends org.zkoss.zk.ui.Component,​I extends IComponent>
      I
      proxyIComponent​(T t)
      Makes a proxy of Component into IComponent.
      static <R extends IComponent,​T extends IComponent>
      R
      replaceDescendant​(R root, T source, T target)
      Replaces the descendant of the given root with the new child from the given source, if any.
      static <R extends IComponent,​T extends IComponent>
      R
      replaceDescendantById​(R root, java.lang.String sourceId, CheckedFunction<T,​T> targetFunction)
      Replaces the descendant of the given root with the new child from the given source, if any.
      static <R extends IComponent>
      R
      replaceDescendantById​(R root, java.lang.String sourceId, IComponent<?> target)
      Replaces the descendant of the given root with the new child from the given source, if any.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Immutables

        public Immutables()
    • Method Detail

      • proxyIComponent

        public static <T extends org.zkoss.zk.ui.Component,​I extends IComponent> I proxyIComponent​(T t)
        Makes a proxy of Component into IComponent.
        Parameters:
        t - a ZK Component
        Returns:
        a proxy of IComponent
      • proxyIChildren

        public static java.util.List<? extends IComponent> proxyIChildren​(org.zkoss.zk.ui.Component instance)
      • proxyIChild

        public static IComponent proxyIChild​(org.zkoss.zk.ui.Component instance)
      • proxyIChild

        public static IComponent proxyIChild​(org.zkoss.zk.ui.Component instance,
                                             java.lang.Class<? extends org.zkoss.zk.ui.Component> skipClass)
      • createComponents

        public static <T extends IComponent> java.util.List<T> createComponents​(org.zkoss.zk.ui.metainfo.PageDefinition pagedef,
                                                                                java.util.Map<?,​?> arg)
        Creates IComponents from Components that don't belong to any page from the specified page definition.
        Parameters:
        pagedef - the page definition to use. It cannot be null.
        arg - a map of parameters that is accessible by the arg variable in EL, or by Execution.getArg(). Ignored if null.
        Returns:
        the first component being created.
        Since:
        2.4.0
        See Also:
        createComponents(String, Map)
      • createComponents

        public static <T extends IComponent> java.util.List<T> createComponents​(java.lang.String uri,
                                                                                java.util.Map<?,​?> arg)
        Creates IComponents from Components that don't belong to any page from a page file specified by an URI.

        It loads the page definition from the specified URI (by use Execution.getPageDefinition(java.lang.String) ), and then invokes createComponents(PageDefinition,Map) to create components.

        Parameters:
        arg - a map of parameters that is accessible by the arg variable in EL, or by Execution.getArg(). Ignored if null.
        See Also:
        createComponents(PageDefinition, Map)
      • createComponentsDirectly

        public static <T extends IComponent> java.util.List<T> createComponentsDirectly​(java.lang.String content,
                                                                                        java.lang.String extension,
                                                                                        java.util.Map<?,​?> arg)
        Creates IComponents from Components that don't belong to any page from the raw content specified by a string.

        The raw content is parsed to a page definition by use of Execution.getPageDefinitionDirectly(String, String), and then invokes createComponents(PageDefinition,Map) to create components.

        Parameters:
        content - the raw content of the page. It must be in ZUML.
        extension - the default extension if the content doesn't specify an language. In other words, if the content doesn't specify an language, LanguageDefinition.getByExtension(java.lang.String) is called. If extension is null and the content doesn't specify a language, the language called "xul/html" is assumed.
        arg - a map of parameters that is accessible by the arg variable in EL, or by Execution.getArg(). Ignored if null.
        See Also:
        createComponents(PageDefinition, Map), createComponents(String, Map)
      • newReplacer

        public static <T extends IComponentIReplacer<T> newReplacer​(T root)
        Constructs a replacer for replacing the descendant of the IComponent tree in a bulk execution for multiple replacements. By default, the implementation uses BFS algorithm to traverse the whole tree to seek the replacement target.
        Parameters:
        root - The root IComponent tree.
        Returns:
        A replacer implementation of IReplacer
      • replaceDescendant

        public static <R extends IComponent,​T extends IComponent> R replaceDescendant​(R root,
                                                                                            T source,
                                                                                            T target)
        Replaces the descendant of the given root with the new child from the given source, if any.
        Parameters:
        root - The root IComponent tree.
        source - The replaced source.
        target - The replaced target.
        Returns:
        The new IComponent tree.
      • replaceDescendantById

        public static <R extends IComponent> R replaceDescendantById​(R root,
                                                                     java.lang.String sourceId,
                                                                     IComponent<?> target)
        Replaces the descendant of the given root with the new child from the given source, if any.
        Parameters:
        root - The root IComponent tree.
        sourceId - The id of the replaced source.
        target - The replaced target.
        Returns:
        The new IComponent tree.
      • replaceDescendantById

        public static <R extends IComponent,​T extends IComponent> R replaceDescendantById​(R root,
                                                                                                java.lang.String sourceId,
                                                                                                CheckedFunction<T,​T> targetFunction)
        Replaces the descendant of the given root with the new child from the given source, if any.
        Parameters:
        root - The root IComponent tree.
        sourceId - The id of the replaced source.
        targetFunction - The replacement function by passing the result of the source and returning the new replacement. If null, it means to remove the replaced source.
        Returns:
        The new IComponent tree.