Esempio n. 1
0
        /// <summary>
        /// Exclude all components in the range beginning at "from".
        /// </summary>
        ///
        /// <param name="exclude">The Exclude object to update.</param>
        /// <param name="from">The first component in the exclude range.</param>
        private static void excludeAfter(Exclude exclude, Name.Component from)
        {
            ArrayList entries = getExcludeEntries(exclude);

            int iNewFrom;
            int iFoundFrom = findEntryBeforeOrAt(entries, from);

            if (iFoundFrom < 0)
            {
                // There is no entry before "from" so insert at the beginning.
                entries.Insert(0, new Producer.ExcludeEntry(from, true));
                iNewFrom = 0;
            }
            else
            {
                Producer.ExcludeEntry foundFrom = (Producer.ExcludeEntry)entries[iFoundFrom];

                if (!foundFrom.anyFollowsComponent_)
                {
                    if (foundFrom.component_.equals(from))
                    {
                        // There is already an entry with "from", so just set the "ANY" flag.
                        foundFrom.anyFollowsComponent_ = true;
                        iNewFrom = iFoundFrom;
                    }
                    else
                    {
                        // Insert following the entry before "from".
                        entries.Insert(iFoundFrom + 1, new Producer.ExcludeEntry(from, true));
                        iNewFrom = iFoundFrom + 1;
                    }
                }
                else
                {
                    // The entry before "from" already has an "ANY" flag, so do nothing.
                    iNewFrom = iFoundFrom;
                }
            }

            // Remove entries after the new "from".
            int iRemoveBegin  = iNewFrom + 1;
            int nRemoveNeeded = entries.Count - iRemoveBegin;

            for (int i = 0; i < nRemoveNeeded; ++i)
            {
                ILOG.J2CsMapping.Collections.Collections.RemoveAt(entries, iRemoveBegin);
            }

            setExcludeEntries(exclude, entries);
        }
Esempio n. 2
0
        /// <summary>
        /// Set the Exclude object from the list of ExcludeEntry.
        /// </summary>
        ///
        /// <param name="exclude">The Exclude object to update.</param>
        /// <param name="entries">The list of ExcludeEntry.</param>
        private static void setExcludeEntries(Exclude exclude, ArrayList entries)
        {
            exclude.clear();

            for (int i = 0; i < entries.Count; ++i)
            {
                Producer.ExcludeEntry entry = (Producer.ExcludeEntry)entries[i];

                if (i == 0 && entry.component_.getValue().size() == 0 &&
                    entry.anyFollowsComponent_)
                {
                    // This is a "beginning ANY".
                    exclude.appendAny();
                }
                else
                {
                    exclude.appendComponent(entry.component_);
                    if (entry.anyFollowsComponent_)
                    {
                        exclude.appendAny();
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Exclude all components in the range beginning at "from" and ending at "to".
        /// </summary>
        ///
        /// <param name="exclude">The Exclude object to update.</param>
        /// <param name="from">The first component in the exclude range.</param>
        /// <param name="to">The last component in the exclude range.</param>
        private static void excludeRange(Exclude exclude, Name.Component from,
                                         Name.Component to)
        {
            if (from.compare(to) >= 0)
            {
                if (from.compare(to) == 0)
                {
                    throw new Exception(
                              "excludeRange: from == to. To exclude a single component, sue excludeOne.");
                }
                else
                {
                    throw new Exception(
                              "excludeRange: from must be less than to. Invalid range: ["
                              + from.toEscapedString() + ", "
                              + to.toEscapedString() + "]");
                }
            }

            ArrayList entries = getExcludeEntries(exclude);

            int iNewFrom;
            int iFoundFrom = findEntryBeforeOrAt(entries, from);

            if (iFoundFrom < 0)
            {
                // There is no entry before "from" so insert at the beginning.
                entries.Insert(0, new Producer.ExcludeEntry(from, true));
                iNewFrom = 0;
            }
            else
            {
                Producer.ExcludeEntry foundFrom = (Producer.ExcludeEntry)entries[iFoundFrom];

                if (!foundFrom.anyFollowsComponent_)
                {
                    if (foundFrom.component_.equals(from))
                    {
                        // There is already an entry with "from", so just set the "ANY" flag.
                        foundFrom.anyFollowsComponent_ = true;
                        iNewFrom = iFoundFrom;
                    }
                    else
                    {
                        // Insert following the entry before "from".
                        entries.Insert(iFoundFrom + 1, new Producer.ExcludeEntry(from, true));
                        iNewFrom = iFoundFrom + 1;
                    }
                }
                else
                {
                    // The entry before "from" already has an "ANY" flag, so do nothing.
                    iNewFrom = iFoundFrom;
                }
            }

            // We have at least one "from" before "to", so we know this will find an entry.
            int iFoundTo = findEntryBeforeOrAt(entries, to);

            Producer.ExcludeEntry foundTo = (Producer.ExcludeEntry)entries[iFoundTo];
            if (iFoundTo == iNewFrom)
            {
                // Insert the "to" immediately after the "from".
                entries.Insert(iNewFrom + 1, new Producer.ExcludeEntry(to, false));
            }
            else
            {
                int iRemoveEnd;
                if (!foundTo.anyFollowsComponent_)
                {
                    if (foundTo.component_.equals(to))
                    {
                        // The "to" entry already exists. Remove up to it.
                        iRemoveEnd = iFoundTo;
                    }
                    else
                    {
                        // Insert following the previous entry, which will be removed.
                        entries.Insert(iFoundTo + 1, new Producer.ExcludeEntry(to, false));
                        iRemoveEnd = iFoundTo + 1;
                    }
                }
                else
                {
                    // "to" follows a component which is already followed by "ANY", meaning
                    // the new range now encompasses it, so remove the component.
                    iRemoveEnd = iFoundTo + 1;
                }

                // Remove intermediate entries since they are inside the range.
                int iRemoveBegin  = iNewFrom + 1;
                int nRemoveNeeded = iRemoveEnd - iRemoveBegin;
                for (int i = 0; i < nRemoveNeeded; ++i)
                {
                    ILOG.J2CsMapping.Collections.Collections.RemoveAt(entries, iRemoveBegin);
                }
            }

            setExcludeEntries(exclude, entries);
        }