示例#1
0
        private Set <EventHandlerInfo> selectEventHandlers(Type eventType, EntityRef entity)
        {
            Set <EventHandlerInfo> result = Sets.newHashSet();

            result.addAll(generalHandlers.get(eventType));
            SetMultimap <Type, EventHandlerInfo> handlers = componentSpecificHandlers[eventType];

            if (handlers == null)
            {
                return(result);
            }

            foreach (Type compClass in handlers.Keys)
            {
                if (entity.hasComponent(compClass))
                {
                    foreach (EventHandlerInfo eventHandler in handlers.get(compClass))
                    {
                        if (eventHandler.isValidFor(entity))
                        {
                            result.add(eventHandler);
                        }
                    }
                }
            }
            return(result);
        }
示例#2
0
        private void addToComponentSpecificHandlers(Type type, EventHandlerInfo handlerInfo, Type c)
        {
            SetMultimap <Type, EventHandlerInfo> componentMap = componentSpecificHandlers[type];

            if (componentMap == null)
            {
                componentMap = HashMultimap.create();
                componentSpecificHandlers[type] = componentMap;
            }
            componentMap.put(c, handlerInfo);
        }
示例#3
0
        public virtual void unregisterEventReceiver <T>(EventReceiver <T> eventReceiver, Type eventClass, params Type[] componentTypes) where T : [email protected]
        {
            SetMultimap <Type, EventHandlerInfo> eventHandlerMap = componentSpecificHandlers[eventClass];

            if (eventHandlerMap != null)
            {
                ReceiverEventHandlerInfo testReceiver = new ReceiverEventHandlerInfo <T>(eventReceiver, 0, componentTypes);
                foreach (Type c in componentTypes)
                {
                    eventHandlerMap.remove(c, testReceiver);
                    foreach (Type childType in childEvents.get(eventClass))
                    {
                        eventHandlerMap.remove(childType, testReceiver);
                    }
                }
            }
        }
        /// <summary>
        /// Obtains a generator from an existing provider and definition.
        /// </summary>
        /// <param name="knownProvider">  the underlying known provider </param>
        /// <param name="groupDefn">  the curve group definition </param>
        /// <param name="refData">  the reference data to use </param>
        /// <returns> the generator </returns>
        public static ImmutableRatesProviderGenerator of(ImmutableRatesProvider knownProvider, RatesCurveGroupDefinition groupDefn, ReferenceData refData)
        {
            IList <CurveDefinition>           curveDefns    = new List <CurveDefinition>();
            IList <CurveMetadata>             curveMetadata = new List <CurveMetadata>();
            SetMultimap <CurveName, Currency> discountNames = HashMultimap.create();
            SetMultimap <CurveName, Index>    indexNames    = HashMultimap.create();

            foreach (CurveDefinition curveDefn in groupDefn.CurveDefinitions)
            {
                curveDefns.Add(curveDefn);
                curveMetadata.Add(curveDefn.metadata(knownProvider.ValuationDate, refData));
                CurveName curveName = curveDefn.Name;
                // A curve group is guaranteed to include an entry for every definition
                RatesCurveGroupEntry entry = groupDefn.findEntry(curveName).get();
                ISet <Currency>      ccy   = entry.DiscountCurrencies;
                discountNames.putAll(curveName, ccy);
                indexNames.putAll(curveName, entry.Indices);
            }
            return(new ImmutableRatesProviderGenerator(knownProvider, curveDefns, curveMetadata, discountNames, indexNames));
        }
示例#5
0
 public virtual void send(EntityRef entity, Event @event, Component component)
 {
     if (Thread.CurrentThread != mainThread)
     {
         pendingEvents.offer(new PendingEvent(entity, @event, component));
     }
     else
     {
         SetMultimap <Type, EventHandlerInfo> handlers = componentSpecificHandlers[@event.GetType()];
         if (handlers != null)
         {
             IList <EventHandlerInfo> eventHandlers = Lists.newArrayList(handlers.get(component.GetType()));
             eventHandlers.Sort(priorityComparator);
             foreach (EventHandlerInfo eventHandler in eventHandlers)
             {
                 if (eventHandler.isValidFor(entity))
                 {
                     eventHandler.invoke(entity, @event);
                 }
             }
         }
     }
 }
 /// <summary>
 /// Creates an instance.
 /// </summary>
 /// <param name="knownProvider">  the underlying known provider </param>
 /// <param name="curveDefinitions">  the curve definitions </param>
 /// <param name="curveMetadata">  the curve metadata </param>
 /// <param name="discountCurveNames">  the map of discount curves </param>
 /// <param name="forwardCurveNames">  the map of index forward curves </param>
 private ImmutableRatesProviderGenerator(ImmutableRatesProvider knownProvider, IList <CurveDefinition> curveDefinitions, IList <CurveMetadata> curveMetadata, SetMultimap <CurveName, Currency> discountCurveNames, SetMultimap <CurveName, Index> forwardCurveNames)
 {
     this.knownProvider      = ArgChecker.notNull(knownProvider, "knownProvider");
     this.curveDefinitions   = ImmutableList.copyOf(ArgChecker.notNull(curveDefinitions, "curveDefinitions"));
     this.curveMetadata      = ImmutableList.copyOf(ArgChecker.notNull(curveMetadata, "curveMetadata"));
     this.discountCurveNames = ImmutableSetMultimap.copyOf(ArgChecker.notNull(discountCurveNames, "discountCurveNames"));
     this.forwardCurveNames  = ImmutableSetMultimap.copyOf(ArgChecker.notNull(forwardCurveNames, "forwardCurveNames"));
 }