Révision 2560

tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 2560)
15 15
import java.util.Locale;
16 16
import java.util.Properties;
17 17
import java.util.concurrent.Semaphore;
18
import java.util.logging.Level;
19 18
import java.util.regex.Pattern;
20 19

  
21 20
import org.apache.commons.lang.StringUtils;
......
1586 1585
	 * @param clazz
1587 1586
	 * @return
1588 1587
	 */
1589
	public List<? extends TXMResult> getChildren(Class<? extends TXMResult> clazz) {
1588
	public <T extends TXMResult> List<T> getChildren(Class<T> clazz) {
1590 1589
		return TXMResult.getNodes(this.children, clazz, false);
1591 1590
	}
1592 1591
	
......
1596 1595
	 * @param clazz
1597 1596
	 * @return
1598 1597
	 */
1599
	public List<TXMResult> getChildren(Class<? extends TXMResult> clazz, boolean onlyVisible) {
1598
	public <T extends TXMResult> List<T> getChildren(Class<T> clazz, boolean onlyVisible) {
1600 1599
		return TXMResult.getNodes(this.children, clazz, onlyVisible);
1601 1600
	}
1602 1601
	
......
1606 1605
	 * @param clazz
1607 1606
	 * @return the first child if exists otherwise null
1608 1607
	 */
1609
	public TXMResult getFirstChild(Class<? extends TXMResult> clazz) {
1610
		List<TXMResult> children = this.getChildren(clazz, false);
1608
	public <T extends TXMResult> TXMResult getFirstChild(Class<T> clazz) {
1609
		List<T> children = this.getChildren(clazz, false);
1611 1610
		try {
1612 1611
			return children.get(0);
1613 1612
		}
......
1631 1630
	 * @param clazz
1632 1631
	 * @return
1633 1632
	 */
1634
	public void deleteChildren(Class<? extends TXMResult> clazz) {
1635
		List<TXMResult> children = (List<TXMResult>) this.getChildren(clazz);
1633
	public <T extends TXMResult> void deleteChildren(Class<T> clazz) {
1634
		List<T> children = this.getChildren(clazz);
1636 1635
		for (int i = 0; i < children.size(); i++) {
1637 1636
			children.get(i).delete();
1638 1637
		}
......
1647 1646
	 * @param clazz
1648 1647
	 * @return
1649 1648
	 */
1650
	protected static List<TXMResult> getDeepChildren(TXMResult parent, Class<? extends TXMResult> clazz) {
1649
	@SuppressWarnings("unchecked")
1650
	protected static <T extends TXMResult> List<T> getDeepChildren(TXMResult parent, Class<T> clazz) {
1651 1651
		
1652
		List<TXMResult> results = new ArrayList<>();
1653
		List<? extends TXMResult> children = parent.getChildren(clazz);
1652
		List<T> results = new ArrayList<>();
1653
		List<TXMResult> children = parent.getChildren();
1654 1654
		
1655 1655
		for (int i = 0; i < children.size(); i++) {
1656 1656
			TXMResult child = children.get(i);
1657
			results.add(child);
1657
			if (clazz == null || child.getClass().asSubclass(clazz) != null) {
1658
				results.add((T) child);
1659
			}
1658 1660
			results.addAll(child.getDeepChildren(clazz));
1659 1661
		}
1660 1662
		return results;
......
1665 1667
	 * 
1666 1668
	 * @return
1667 1669
	 */
1668
	public List<TXMResult> getDeepChildren(Class<? extends TXMResult> clazz) {
1670
	public <T extends TXMResult> List<T> getDeepChildren(Class<T> clazz) {
1669 1671
		return TXMResult.getDeepChildren(this, clazz);
1670 1672
	}
1671 1673
	
......
1742 1744
	 * @param onlyVisible
1743 1745
	 * @return a new filtered nodes list
1744 1746
	 */
1745
	protected static List<TXMResult> getNodes(List<TXMResult> srcNodes, Class<? extends TXMResult> clazz, boolean onlyVisible) {
1746
		List<TXMResult> nodes = new ArrayList<>();
1747
	@SuppressWarnings("unchecked")
1748
	protected static <T extends TXMResult> List<T> getNodes(List<TXMResult> srcNodes, Class<T> clazz, boolean onlyVisible) {
1749
		List<T> nodes = new ArrayList<>();
1747 1750
		for (TXMResult child : srcNodes) {
1748 1751
			try {
1749 1752
				if ((clazz == null ||
1750 1753
						child.getClass().asSubclass(clazz) != null)
1751 1754
						&& (onlyVisible == false || child.isVisible())) {
1752
					nodes.add(child);
1755
					nodes.add((T) child);
1753 1756
				}
1754 1757
				
1755 1758
				// add children of a non visible result
1756 1759
				else if (!child.isVisible() && child.hasChildren()) {
1757
					List<TXMResult> subChidlren = child.getChildren(clazz, onlyVisible);
1760
					List<T> subChidlren = child.getChildren(clazz, onlyVisible);
1758 1761
					nodes.addAll(subChidlren);
1759 1762
				}
1760 1763
			}
......
1800 1803
	 * @param clazz the class of parent to look for
1801 1804
	 * @return the first parent of the specified class if exist otherwise null
1802 1805
	 */
1803
	public TXMResult getFirstParent(Class<? extends TXMResult> clazz) {
1804
		TXMResult node = null;
1806
	@SuppressWarnings("unchecked")
1807
	public <T extends TXMResult> T getFirstParent(Class<T> clazz) {
1808
		T node = null;
1805 1809
		TXMResult parent = this.parent;
1806 1810
		do {
1807 1811
			if (parent != null) {
1808
				if (parent.getClass().equals(clazz)) {
1809
					node = parent;
1812
				if (clazz == null || parent.getClass().equals(clazz)) {
1813
					node = (T) parent;
1810 1814
				}
1811 1815
				
1812 1816
				parent = parent.getParent();
......
1849 1853
	 * @param clazz the class of siblings to look for
1850 1854
	 * @return
1851 1855
	 */
1852
	public List<TXMResult> getSiblings(Class<? extends TXMResult> clazz) {
1853
		List<TXMResult> sibling = new ArrayList<>();
1856
	public <T extends TXMResult> List<T> getSiblings(Class<T> clazz) {
1857
		List<T> sibling = new ArrayList<>();
1854 1858
		if (this.parent != null) {
1855 1859
			sibling.addAll(TXMResult.getNodes(this.parent.getChildren(), clazz, true));
1856 1860
			sibling.remove(this);
......
2478 2482
				if (this.parent != null) {
2479 2483
					
2480 2484
					Log.finest("TXMResult.compute(): " + this.getClass().getSimpleName() + ": cascade computing of " + this.children.size() + " child(ren).");
2485
					// SubMonitor subMonitor = SubMonitor.convert(monitor, this.children.size());
2481 2486
					
2482 2487
					for (int i = 0; i < this.children.size(); i++) {
2483 2488
						
......
2487 2492
						// or if this result always needs its children synchronized/computed to be consistent (eg. Partition and children parts)
2488 2493
						if ((deepComputing && child.hasBeenComputedOnce()) || child.mustBeSynchronizedWithParent()) {
2489 2494
							child.compute(monitor, deepComputing);
2495
							// subMonitor.worked(1);
2490 2496
						}
2491 2497
						
2492 2498
						if (monitor != null && this.children.size() > 1) {
......
2495 2501
					}
2496 2502
				}
2497 2503
			}
2498
			
2499 2504
		}
2500 2505
		catch (Exception e) {
2501 2506
			e.printStackTrace();
......
2856 2861
	 * @return the project of the result
2857 2862
	 */
2858 2863
	public final Project getProject() {
2859
		return (Project) this.getFirstParent(Project.class);
2864
		return this.getFirstParent(Project.class);
2860 2865
	}
2861 2866
	
2862 2867
	/**

Formats disponibles : Unified diff