comparison org.eclipse.core.commands/src/org/eclipse/core/commands/common/HandleObjectManager.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13
14 module org.eclipse.core.commands.common.HandleObjectManager;
15
16 import org.eclipse.core.commands.common.HandleObject;
17 import org.eclipse.core.commands.common.EventManager;
18 import java.lang.all;
19
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Iterator;
23 import java.util.Map;
24 import java.util.Set;
25
26 /**
27 * <p>
28 * A manager of {@link HandleObject} instances. This has some common behaviour
29 * which is shared between all such managers.
30 * </p>
31 * <p>
32 * Clients may extend.
33 * </p>
34 *
35 * @since 3.2
36 */
37 public abstract class HandleObjectManager : EventManager {
38
39 /**
40 * The set of handle objects that are defined. This value may be empty, but
41 * it is never <code>null</code>.
42 */
43 protected const Set definedHandleObjects;
44
45 /**
46 * The map of identifiers (<code>String</code>) to handle objects (
47 * <code>HandleObject</code>). This collection may be empty, but it is
48 * never <code>null</code>.
49 */
50 protected const Map handleObjectsById;
51
52 public this(){
53 definedHandleObjects = new HashSet();
54 handleObjectsById = new HashMap();
55 }
56
57 /**
58 * Verifies that the identifier is valid. Exceptions will be thrown if the
59 * identifier is invalid in some way.
60 *
61 * @param id
62 * The identifier to validate; may be anything.
63 */
64 protected final void checkId(String id) {
65 if (id is null) {
66 throw new NullPointerException(
67 "A handle object may not have a null identifier"); //$NON-NLS-1$
68 }
69
70 if (id.length < 1) {
71 throw new IllegalArgumentException(
72 "The handle object must not have a zero-length identifier"); //$NON-NLS-1$
73 }
74 }
75
76 /**
77 * Returns the set of identifiers for those handle objects that are defined.
78 *
79 * @return The set of defined handle object identifiers; this value may be
80 * empty, but it is never <code>null</code>.
81 */
82 protected final HashSet getDefinedHandleObjectIds() {
83 HashSet definedHandleObjectIds = new HashSet(definedHandleObjects
84 .size());
85 Iterator handleObjectItr = definedHandleObjects.iterator();
86 while (handleObjectItr.hasNext()) {
87 HandleObject handleObject = cast(HandleObject) handleObjectItr
88 .next();
89 String id = handleObject.getId();
90 definedHandleObjectIds.add(id);
91 }
92 return definedHandleObjectIds;
93 }
94 }