public void testConstraint() { /** * We'll give ourselves a pass on testing all the possible ways of breaking the constraint, * because we know that newClassMap() is implemented using ConstrainedMap which is itself * well-tested. A purist would object to this, but what can I say, we're dirty cheaters. */ map.put(Integer.class, new Integer(5)); try { map.put(Double.class, new Long(42)); fail(); } catch (ClassCastException expected) { } // Won't compile: map.put(String.class, "x"); }
public void testNull() { try { map.put(null, new Integer(1)); fail(); } catch (NullPointerException expected) { } map.putInstance(Integer.class, null); assertNull(map.get(Integer.class)); assertNull(map.getInstance(Integer.class)); map.put(Long.class, null); assertNull(map.get(Long.class)); assertNull(map.getInstance(Long.class)); }
/** * Add the task with this name, or replace it with a new instance if it already exists. * * @param taskName the task name */ public void addTask(String taskName) { EntityTask oldTask = getTask(taskName); if (oldTask != null) { cancel(oldTask); } EntityTask newTask = getNewTask(taskName); tasksByName.put(taskName, newTask); tasksByClass.put(newTask.getClass(), newTask); tasks.add(newTask); } }
/** * Adds a minion to the squad. * @param minion minion who should join the squad */ public <M extends Minion> void add(M minion) { minions.put(minion.getClass(), minion); Class sc = minion.getClass().getSuperclass(); while (sc != null && !Modifier.isAbstract(sc.getModifiers()) && !sc.equals(Minion.class) ) { minions.putInstance(sc, minion); sc = sc.getSuperclass(); } sorted.add(minion); }
/** * Add the given task, replacing any existing task with the same name. * * @param task the task to add */ public void addTask(EntityTask task) { if (task != null) { String name = task.getName(); EntityTask oldTask = getTask(name); if (oldTask != null) { cancel(oldTask); } tasksByName.put(name, task); tasksByClass.put(task.getClass(), task); tasks.add(task); } }
public void testNull() { try { map.put(null, new Integer(1)); fail(); } catch (NullPointerException expected) { } map.putInstance(Integer.class, null); assertNull(map.get(Integer.class)); assertNull(map.getInstance(Integer.class)); map.put(Long.class, null); assertNull(map.get(Long.class)); assertNull(map.getInstance(Long.class)); }
private ClassToInstanceMap<Annotation> toMap(Collection<? extends Annotation> annotations) { ClassToInstanceMap<Annotation> annotationMap = MutableClassToInstanceMap.create(); for (Annotation annotation : annotations) { if (annotation == null) { continue; } annotationMap.put(annotation.annotationType(), annotation); } return annotationMap; }
/** * Add delegate to set of delegates. * * @param type * - type of delegate * @param impl * - implementation of delegate */ public final <V extends D> void addDelegate(final Class<V> type, final D impl) { delegates.put(type, impl); }
public Builder addTags(AddTagAction addTags) { this.actions.put(AddTagAction.class, addTags); return this; }
public Builder setOpen(Action.OpenAction open) { this.actions.put(Action.OpenAction.class, open); return this; }
public Builder removeTags(RemoveTagAction removeTags) { this.actions.put(RemoveTagAction.class, removeTags); return this; }
public Builder addAppDefined(AppDefinedAction appDefined) { this.actions.put(AppDefinedAction.class, appDefined); return this; }
public Builder setShare(ShareAction shareAction) { actions.put(ShareAction.class, shareAction); return this; }
/** * Adds a provider.<p> * * Note that no two providers of the same exact class may be added.<p> * * @param instance the provider instance to add */ public void addProvider(I_CmsContextMenuItemProvider instance) { m_providerMap.put(instance.getClass(), instance); }
public <T extends Service> ServiceRegistry registerService(Class<? extends T> serviceClass, T serviceInstance) { checkNotNull(serviceClass,"Service class cannot be null"); checkNotNull(serviceInstance,"Service instance cannot be null"); services.put(serviceClass, serviceInstance); return this; }
/** * Adds a new provider class.<p> * * @param providerClass the provider class */ public void addProvider(Class<? extends I_CmsContextMenuItemProvider> providerClass) { try { m_providerMap.put(providerClass, providerClass.newInstance()); } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } }
TemplateManagerBuilder withHandlers(Collection<ResourceHandler> handlers) { checkNotNull(handlers,"Handler collection cannot be null"); for(ResourceHandler handler:handlers) { Class<? extends ResourceHandler> handlerClass = handler.getClass(); if(!this.handlerClasses.contains(handlerClass)) { this.handlerClasses.add(handlerClass); this.handlers.put(handlerClass, handler); } } return this; }
private synchronized <T extends BindingAwareService> T tryToRetrieveSalService(Class<T> service) { final T potential = alreadyRetrievedServices.getInstance(service); if (potential != null) { return potential; } final T requested = serviceProvider.getInstance(service); if (requested == null) { throw new IllegalArgumentException("Requested service " + service.getName() + " is not available."); } final T retrieved = BindingContextUtils.createContextProxyOrReturnService(service,requested); alreadyRetrievedServices.put(service, retrieved); return retrieved; }
private synchronized <T extends BindingAwareService> T tryToRetrieveSalService(Class<T> service) { final T potential = alreadyRetrievedServices.getInstance(service); if(potential != null) { return potential; } final T requested = serviceProvider.getInstance(service); if(requested == null) { throw new IllegalArgumentException("Requested service "+service.getName() +" is not available."); } final T retrieved = BindingContextUtils.createContextProxyOrReturnService(service,requested); alreadyRetrievedServices.put(service, retrieved); return retrieved; }
private SniperTool(Class<? extends IBrush> currentBrush, SnipeData snipeData) { this.snipeData = snipeData; this.messageHelper = new Message(snipeData); snipeData.setVoxelMessage(this.messageHelper); IBrush newBrushInstance = instanciateBrush(currentBrush); if (snipeData.owner().getPlayer().hasPermission(newBrushInstance.getPermissionNode())) { this.brushes.put(currentBrush, newBrushInstance); this.currentBrush = currentBrush; } }