コード例 #1
0
        public override void Unregister(V extension, Type key)
        {
            Object writeLock = GetWriteLock();

            lock (writeLock)
            {
                base.Unregister(extension, key);

                ClassEntry <V> classEntry = CopyStructure();
                LinkedHashMap <StrongKey <V>, List <DefEntry <V> > > definitionReverseMap = classEntry.definitionReverseMap;
                List <DefEntry <V> > weakEntriesOfStrongType = definitionReverseMap.Remove(new StrongKey <V>(extension, key));
                if (weakEntriesOfStrongType == null)
                {
                    return;
                }
                LinkedHashMap <Type, Object> typeToDefEntryMap = classEntry.typeToDefEntryMap;
                for (int a = weakEntriesOfStrongType.Count; a-- > 0;)
                {
                    DefEntry <V> defEntry       = weakEntriesOfStrongType[a];
                    Type         registeredType = defEntry.type;

                    Object value = typeToDefEntryMap.Get(registeredType);
                    InterfaceFastList <DefEntry <V> > list = (InterfaceFastList <DefEntry <V> >)value;
                    list.Remove(defEntry);
                    if (list.Count == 0)
                    {
                        typeToDefEntryMap.Remove(registeredType);
                    }
                    TypeToDefEntryMapChanged(classEntry, registeredType);
                }
                this.classEntry = classEntry;
            }
        }
コード例 #2
0
        public override void Unregister(V extension, ConversionKey key)
        {
            ParamChecker.AssertParamNotNull(extension, "extension");
            ParamChecker.AssertParamNotNull(key, "key");

            Object writeLock = GetWriteLock();

            lock (writeLock)
            {
                base.Unregister(extension, key);

                ClassTupleEntry <V> classEntry = CopyStructure();
                HashMap <Strong2Key <V>, List <Def2Entry <V> > > definitionReverseMap = classEntry.definitionReverseMap;
                List <Def2Entry <V> > weakEntriesOfStrongType = definitionReverseMap.Remove(new Strong2Key <V>(extension, key));
                if (weakEntriesOfStrongType == null)
                {
                    return;
                }
                HashMap <ConversionKey, Object> typeToDefEntryMap = classEntry.typeToDefEntryMap;
                for (int a = weakEntriesOfStrongType.Count; a-- > 0;)
                {
                    Def2Entry <V> defEntry                  = weakEntriesOfStrongType[a];
                    ConversionKey registeredKey             = new ConversionKey(defEntry.sourceType, defEntry.targetType);
                    Object        value                     = typeToDefEntryMap.Get(registeredKey);
                    InterfaceFastList <Def2Entry <V> > list = (InterfaceFastList <Def2Entry <V> >)value;
                    list.Remove(defEntry);
                    if (list.Count == 0)
                    {
                        typeToDefEntryMap.Remove(registeredKey);
                    }
                    TypeToDefEntryMapChanged(classEntry, registeredKey);
                }
                this.classEntry = classEntry;
            }
        }
コード例 #3
0
        protected ClassEntry <V> CopyStructure()
        {
            ClassEntry <V> newClassEntry = new ClassEntry <V>();
            LinkedHashMap <Type, Object> newTypeToDefEntryMap = newClassEntry.typeToDefEntryMap;
            LinkedHashMap <StrongKey <V>, List <DefEntry <V> > > newDefinitionReverseMap = newClassEntry.definitionReverseMap;
            IdentityHashMap <DefEntry <V>, DefEntry <V> >        originalToCopyMap       = new IdentityHashMap <DefEntry <V>, DefEntry <V> >();

            {
                foreach (Entry <Type, Object> entry in classEntry.typeToDefEntryMap)
                {
                    Type   key   = entry.Key;
                    Object value = entry.Value;

                    if (Object.ReferenceEquals(value, alreadyHandled))
                    {
                        newTypeToDefEntryMap.Put(key, alreadyHandled);
                    }
                    else
                    {
                        InterfaceFastList <DefEntry <V> > list = (InterfaceFastList <DefEntry <V> >)value;

                        InterfaceFastList <DefEntry <V> > newList = new InterfaceFastList <DefEntry <V> >();

                        IListElem <DefEntry <V> > pointer = list.First;
                        while (pointer != null)
                        {
                            DefEntry <V> defEntry    = pointer.ElemValue;
                            DefEntry <V> newDefEntry = new DefEntry <V>(defEntry.extension, defEntry.type, defEntry.distance);
                            originalToCopyMap.Put(defEntry, newDefEntry);

                            newList.PushLast(newDefEntry);
                            pointer = pointer.Next;
                        }
                        newTypeToDefEntryMap.Put(key, newList);
                    }
                    TypeToDefEntryMapChanged(newClassEntry, key);
                }
            }
            foreach (Entry <StrongKey <V>, List <DefEntry <V> > > entry in classEntry.definitionReverseMap)
            {
                List <DefEntry <V> > defEntries    = entry.Value;
                List <DefEntry <V> > newDefEntries = new List <DefEntry <V> >(defEntries.Count);

                for (int a = 0, size = defEntries.Count; a < size; a++)
                {
                    DefEntry <V> newDefEntry = originalToCopyMap.Get(defEntries[a]);
                    if (newDefEntry == null)
                    {
                        throw new Exception("Must never happen");
                    }
                    newDefEntries.Add(newDefEntry);
                }
                newDefinitionReverseMap.Put(entry.Key, newDefEntries);
            }
            return(newClassEntry);
        }
コード例 #4
0
        protected bool AppendRegistration(ConversionKey strongTypeKey, ConversionKey key, V extension, int sourceDistance, int targetDistance,
                                          ClassTupleEntry <V> classEntry)
        {
            HashMap <ConversionKey, Object> typeToDefEntryMap = classEntry.typeToDefEntryMap;
            Object fastList = typeToDefEntryMap.Get(key);

            if (fastList != null && fastList != alreadyHandled)
            {
                IListElem <Def2Entry <V> > pointer = ((InterfaceFastList <Def2Entry <V> >)fastList).First;
                while (pointer != null)
                {
                    Def2Entry <V> existingDefEntry = pointer.ElemValue;
                    if (Object.ReferenceEquals(existingDefEntry.extension, extension) && existingDefEntry.sourceDistance == sourceDistance &&
                        existingDefEntry.targetDistance == targetDistance)
                    {
                        // DefEntry already exists with same distance
                        return(false);
                    }
                    pointer = pointer.Next;
                }
            }
            if (fastList == null || Object.ReferenceEquals(fastList, alreadyHandled))
            {
                fastList = new InterfaceFastList <Def2Entry <V> >();
                typeToDefEntryMap.Put(key, fastList);
            }
            Def2Entry <V> defEntry = new Def2Entry <V>(extension, key.SourceType, key.TargetType, sourceDistance, targetDistance);

            HashMap <Strong2Key <V>, List <Def2Entry <V> > > definitionReverseMap = classEntry.definitionReverseMap;
            Strong2Key <V>        strongKey   = new Strong2Key <V>(extension, strongTypeKey);
            List <Def2Entry <V> > typeEntries = definitionReverseMap.Get(strongKey);

            if (typeEntries == null)
            {
                typeEntries = new List <Def2Entry <V> >();
                definitionReverseMap.Put(strongKey, typeEntries);
            }
            typeEntries.Add(defEntry);

            InterfaceFastList <Def2Entry <V> > .InsertOrdered((InterfaceFastList <Def2Entry <V> >) fastList, defEntry);

            TypeToDefEntryMapChanged(classEntry, key);
            return(true);
        }
コード例 #5
0
        protected bool AppendRegistration(Type strongType, Type type, V extension, int distance, ClassEntry <V> classEntry)
        {
            LinkedHashMap <Type, Object> typeToDefEntryMap = classEntry.typeToDefEntryMap;
            Object fastList = typeToDefEntryMap.Get(type);

            if (fastList != null && !Object.ReferenceEquals(fastList, alreadyHandled))
            {
                IListElem <DefEntry <V> > pointer = ((InterfaceFastList <DefEntry <V> >)fastList).First;
                while (pointer != null)
                {
                    DefEntry <V> existingDefEntry = pointer.ElemValue;
                    if (Object.ReferenceEquals(existingDefEntry.extension, extension) && existingDefEntry.distance == distance)
                    {
                        // DefEntry already exists with same distance
                        return(false);
                    }
                    pointer = pointer.Next;
                }
            }
            if (fastList == null || Object.ReferenceEquals(fastList, alreadyHandled))
            {
                fastList = new InterfaceFastList <DefEntry <V> >();
                typeToDefEntryMap.Put(type, fastList);
            }
            DefEntry <V> defEntry = new DefEntry <V>(extension, type, distance);

            LinkedHashMap <StrongKey <V>, List <DefEntry <V> > > definitionReverseMap = classEntry.definitionReverseMap;
            StrongKey <V>        strongKey   = new StrongKey <V>(extension, strongType);
            List <DefEntry <V> > typeEntries = definitionReverseMap.Get(strongKey);

            if (typeEntries == null)
            {
                typeEntries = new List <DefEntry <V> >();
                definitionReverseMap.Put(strongKey, typeEntries);
            }
            typeEntries.Add(defEntry);

            InterfaceFastList <DefEntry <V> > .InsertOrdered((InterfaceFastList <DefEntry <V> >) fastList, defEntry);

            TypeToDefEntryMapChanged(classEntry, type);
            return(true);
        }