KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.core.internal.dependencies;
12
13 import java.util.*;
14
15 /**
16  * Simple selection policy.
17  */

18
19 public class SimpleSelectionPolicy implements ISelectionPolicy {
20     public Set selectMultiple(ElementSet elementSet) {
21         // all satisfied are selected
22
return new HashSet(elementSet.getSatisfied());
23     }
24
25     public Element selectSingle(ElementSet elementSet) {
26         // just pick the satisfied element with the highest version
27
Element highest = null;
28         for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) {
29             Element satisfiedVersion = (Element) satisfiedIter.next();
30             if (highest == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), highest.getVersionId()) > 0)
31                 highest = satisfiedVersion;
32         }
33         return highest;
34     }
35 }
Popular Tags