KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dependencies > SelectionVisitor


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.core.internal.dependencies;
13
14 import java.util.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16
17 /**
18  * Clients may override to provide alternative policies.
19  */

20 public class SelectionVisitor implements IElementSetVisitor {
21     private int order;
22     private ISelectionPolicy selectionPolicy;
23
24     public SelectionVisitor(int order, ISelectionPolicy selectionPolicy) {
25         this.order = order;
26         this.selectionPolicy = selectionPolicy;
27     }
28
29     public final Collection JavaDoc getAncestors(ElementSet elementSet) {
30         return elementSet.getRequiring();
31     }
32
33     public final Collection JavaDoc getDescendants(ElementSet elementSet) {
34         return elementSet.getRequired();
35     }
36
37     public int getOrder() {
38         return order;
39     }
40
41     public void update(ElementSet elementSet) {
42
43         // no versions satisfied, so no versions selected
44
if (elementSet.getSatisfied().isEmpty()) {
45             elementSet.setSelected(Collections.EMPTY_SET);
46             return;
47         }
48         // all versions allow concurrency - select only those which are required, or the highest
49
if (elementSet.allowsConcurrency()) {
50             elementSet.setSelected(this.selectionPolicy.selectMultiple(elementSet));
51             return;
52         }
53         // otherwise, we must pick a single one (if any)
54
Element selected = this.selectionPolicy.selectSingle(elementSet);
55         elementSet.setSelected(selected == null ? Collections.EMPTY_SET : Collections.singleton(selected));
56     }
57
58 }
Popular Tags