RemoveFilter.java revision 1472:c18cbe5936b8
1/* 2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24package com.sun.hotspot.igv.filter; 25 26import com.sun.hotspot.igv.graph.Diagram; 27import com.sun.hotspot.igv.graph.Figure; 28import com.sun.hotspot.igv.graph.InputSlot; 29import com.sun.hotspot.igv.graph.Selector; 30import com.sun.hotspot.igv.data.Properties; 31import java.util.ArrayList; 32import java.util.HashSet; 33import java.util.List; 34import java.util.Set; 35 36/** 37 * 38 * @author Thomas Wuerthinger 39 */ 40public class RemoveFilter extends AbstractFilter { 41 42 private List<RemoveRule> rules; 43 private String name; 44 45 public RemoveFilter(String name) { 46 this.name = name; 47 rules = new ArrayList<RemoveRule>(); 48 } 49 50 public String getName() { 51 return name; 52 } 53 54 public void apply(Diagram diagram) { 55 56 for (RemoveRule r : rules) { 57 58 List<Figure> list = r.getSelector().selected(diagram); 59 Set<Figure> figuresToRemove = new HashSet<Figure>(); 60 61 List<Figure> protectedFigures = null; 62 if (r.getRemoveAllWithoutPredecessor()) { 63 protectedFigures = diagram.getRootFigures(); 64 } 65 66 for (Figure f : list) { 67 if (r.getRemoveOnlyInputs()) { 68 List<InputSlot> inputSlots = new ArrayList<InputSlot>(); 69 for (InputSlot is : f.getInputSlots()) { 70 inputSlots.add(is); 71 } 72 for (InputSlot is : inputSlots) { 73 f.removeSlot(is); 74 } 75 76 f.createInputSlot(); 77 } else { 78 figuresToRemove.add(f); 79 } 80 } 81 82 if (r.getRemoveAllWithoutPredecessor()) { 83 boolean progress = true; 84 while (progress) { 85 List<Figure> rootFigures = diagram.getRootFigures(); 86 progress = false; 87 for (Figure f : rootFigures) { 88 if (!protectedFigures.contains(f)) { 89 figuresToRemove.add(f); 90 progress = true; 91 } 92 } 93 } 94 } 95 96 diagram.removeAllFigures(figuresToRemove); 97 } 98 } 99 100 public void addRule(RemoveRule rule) { 101 rules.add(rule); 102 } 103 104 public static class RemoveRule { 105 106 private Selector selector; 107 private boolean removeAllWithoutPredecessor; 108 private boolean removeOnlyInputs; 109 110 public RemoveRule(Selector selector, boolean b) { 111 this(selector, b, false); 112 } 113 114 public RemoveRule(Selector selector, boolean removeAllWithoutPredecessor, boolean removeOnlyInputs) { 115 this.selector = selector; 116 this.removeOnlyInputs = removeOnlyInputs; 117 this.removeAllWithoutPredecessor = removeAllWithoutPredecessor; 118 } 119 120 public Selector getSelector() { 121 return selector; 122 } 123 124 public boolean getRemoveOnlyInputs() { 125 return removeOnlyInputs; 126 } 127 128 public boolean getRemoveAllWithoutPredecessor() { 129 return removeAllWithoutPredecessor; 130 } 131 } 132} 133