Lines 58-63
Link Here
|
58 |
import java.util.List; |
58 |
import java.util.List; |
59 |
import java.util.Set; |
59 |
import java.util.Set; |
60 |
import java.util.TreeSet; |
60 |
import java.util.TreeSet; |
|
|
61 |
import java.util.concurrent.Callable; |
61 |
import java.util.concurrent.Executor; |
62 |
import java.util.concurrent.Executor; |
62 |
import java.util.concurrent.atomic.AtomicReference; |
63 |
import java.util.concurrent.atomic.AtomicReference; |
63 |
import java.util.logging.Level; |
64 |
import java.util.logging.Level; |
Lines 312-317
Link Here
|
312 |
new SynchChildren <T> (factory); |
313 |
new SynchChildren <T> (factory); |
313 |
} |
314 |
} |
314 |
|
315 |
|
|
|
316 |
/** |
317 |
* Create a lazy children implementation. |
318 |
* @param factory The {@link Callable} whose <code>call()</code> method |
319 |
* is called just when node's children are really needed. |
320 |
* @return Provides lazy children implementation that can be passed |
321 |
* to {@link Node} constructor and thus allows the client code to decide |
322 |
* what children the node should have when {@link Callable#call()} is called. |
323 |
* @since 7.18 |
324 |
*/ |
325 |
public static Children createLazy(Callable<Children> factory) { |
326 |
return new LazyChildren(factory); |
327 |
} |
328 |
|
315 |
/** Get the parent node of these children. |
329 |
/** Get the parent node of these children. |
316 |
* @return the node attached to this children object, or <code>null</code> if there is none yet |
330 |
* @return the node attached to this children object, or <code>null</code> if there is none yet |
317 |
*/ |
331 |
*/ |
Lines 1793-1798
Link Here
|
1793 |
} |
1807 |
} |
1794 |
} |
1808 |
} |
1795 |
|
1809 |
|
|
|
1810 |
/** |
1811 |
* Lazy children implementation |
1812 |
*/ |
1813 |
static class LazyChildren extends Children { |
1814 |
|
1815 |
private Callable<Children> factory; |
1816 |
private Children original; |
1817 |
private final Object originalLock= new Object(); |
1818 |
|
1819 |
LazyChildren(Callable<Children> factory) { |
1820 |
this.factory = factory; |
1821 |
} |
1822 |
|
1823 |
Children getOriginal() { |
1824 |
synchronized (originalLock) { |
1825 |
if (original == null) { |
1826 |
try { |
1827 |
original = factory.call(); |
1828 |
} catch (Exception ex) { |
1829 |
throw new RuntimeException(ex); |
1830 |
} |
1831 |
} |
1832 |
return original; |
1833 |
} |
1834 |
} |
1835 |
|
1836 |
@Override |
1837 |
public boolean add(Node[] nodes) { |
1838 |
return getOriginal().add(nodes); |
1839 |
} |
1840 |
|
1841 |
@Override |
1842 |
public boolean remove(Node[] nodes) { |
1843 |
return getOriginal().remove(nodes); |
1844 |
} |
1845 |
|
1846 |
@Override |
1847 |
protected void addNotify() { |
1848 |
getOriginal().addNotify(); |
1849 |
} |
1850 |
|
1851 |
@Override |
1852 |
protected void removeNotify() { |
1853 |
getOriginal().removeNotify(); |
1854 |
} |
1855 |
|
1856 |
@Override |
1857 |
EntrySupport entrySupport() { |
1858 |
return getOriginal().entrySupport(); |
1859 |
} |
1860 |
|
1861 |
@Override |
1862 |
public Node findChild(String name) { |
1863 |
return getOriginal().findChild(name); |
1864 |
} |
1865 |
|
1866 |
|
1867 |
/* |
1868 |
void postInitializeEntrySupport(EntrySupport es) { |
1869 |
if (getNodesEntry() == null) { |
1870 |
nodesEntry = createNodesEntry(); |
1871 |
} |
1872 |
es.setEntries(Collections.singleton(getNodesEntry())); |
1873 |
} |
1874 |
*/ |
1875 |
|
1876 |
} |
1877 |
|
1796 |
/* |
1878 |
/* |
1797 |
static void printNodes (Node[] n) { |
1879 |
static void printNodes (Node[] n) { |
1798 |
for (int i = 0; i < n.length; i++) { |
1880 |
for (int i = 0; i < n.length; i++) { |