Exemple #1
0
        public virtual void testAddAll()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap(m1);

            m2.put("a2", "v3");
            JDFAttributeMap m3 = new JDFAttributeMap(m1);

            m3.put("a2", "v3");
            VJDFAttributeMap v = new VJDFAttributeMap();

            v.Add(m1);
            v.Add(m2);
            VJDFAttributeMap v2 = new VJDFAttributeMap();

            v2.Add(m2);
            v2.Add(m3);
            v.addAll(v2);
            Assert.AreEqual(4, v.Count);
            Assert.IsTrue(v.Contains(m1));
            Assert.IsTrue(v.Contains(m2));
            Assert.IsTrue(v.Contains(m3));
        }
Exemple #2
0
        ///
        ///	 <summary> * entrySet - Returns a Set view of the entries contained in this Hashtable. Each element in this collection is a
        ///	 * Map.Entry. The Set is backed by the Hashtable, so changes to the Hashtable are reflected in the Set, and
        ///	 * vice-versa. The Set supports element removal (which removes the corresponding entry from the Hashtable), but not
        ///	 * element addition.
        ///	 *  </summary>
        ///	 * <returns> Set - the set view of the entries contained in this hashtable </returns>
        ///
        // TODO: Just Delete this?
        //      public virtual Set entrySet()
        //      {
        ////JAVA TO VB & C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'entrySet' method:
        //         return m_hashTable.entrySet();
        //      }

        ///
        ///	 <summary> * subMap - returns true if map contains subMap, all keys of submap must be in this hashtable and they must have the
        ///	 * same value<br>
        ///	 *
        ///	 * if subMap is null, the function returns true if subMap contains any wildcards, then the existance of the key in
        ///	 * this defines a match
        ///	 *  </summary>
        ///	 * <param name="subMap"> the map to compare
        ///	 *  </param>
        ///	 * <returns> boolean - true if this map contains subMap </returns>
        ///
        public virtual bool subMap(JDFAttributeMap subMap)
        {
            if (subMap == null) // the null map is a subset of everything
            {
                return(true);
            }

            ICollection <string> mapSet    = this.Keys;
            ICollection <string> subMapSet = subMap.Keys;

            if (!this.containsAll(subMapSet))
            {
                return(false);
            }

            IEnumerator <string> it = subMapSet.GetEnumerator();

            while (it.MoveNext())
            {
                string key    = it.Current;
                string subVal = subMap[key];
                if (!KElement.isWildCard(subVal))
                {
                    string val = this[key];
                    if (!val.Equals(subVal))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #3
0
        ///
        ///	 <summary> * equals - Compares two maps, returns true if content equal, otherwise false.<br> If input is not of type
        ///	 * JDFAttributeMap, the result of the superclasses' equals method is returned.
        ///	 *  </summary>
        ///	 * <param name="obj"> JDFAttributeMap to compare with <code>this</code>
        ///	 *  </param>
        ///	 * <returns> boolean - true if the maps are equal, otherwise false </returns>
        ///
        public override bool Equals(object other)
        {
            if (this == other)
            {
                return(true);
            }
            if (other == null || !(other is JDFAttributeMap))
            {
                return(false);
            }

            JDFAttributeMap otherMap = (JDFAttributeMap)other;

            if (this.Count != otherMap.Count)
            {
                return(false);
            }
            foreach (string key in this.Keys)
            {
                if (!otherMap.ContainsKey(key))
                {
                    return(false);
                }

                if (this[key] != otherMap[key])
                {
                    return(false);
                }
            }
            return(true);
        }
        public virtual void testOverlapMap()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            Assert.IsTrue(m1.overlapMap((JDFAttributeMap)null));
            JDFAttributeMap m2 = new JDFAttributeMap("a1", "v1");

            Assert.IsTrue(m1.overlapMap(m2));
            m2.put("a2", "v2");
            Assert.IsTrue(m1.overlapMap(m2));
            m2.put("a2", "v3");
            Assert.IsFalse(m1.overlapMap(m2));
            m2.put("a2", "v2");
            Assert.IsTrue(m1.overlapMap(m2));
            m2.put("a2", "*");
            Assert.IsTrue(m1.overlapMap(m2));
            m2.put("a3", "v3");
            Assert.IsTrue(m1.overlapMap(m2));
            m2.put("a4", null);
            Assert.IsTrue(m1.overlapMap(m2));
            m2.put("a4", null);
            Assert.IsTrue(m1.overlapMap(m2));
            m1.put("a4", null);
            Assert.IsTrue(m1.overlapMap(m2));
            Assert.IsTrue(m1.overlapMap((JDFAttributeMap)null));
        }
Exemple #5
0
        ///
        ///	 <summary> * orMap - put all key/value pairs which are not in this map to this map. Clear this, if both maps have the same
        ///	 * keys with different values.
        ///	 *  </summary>
        ///	 * <param name="subMap"> the map to compare with <code>this</this> </param>
        ///
        public virtual JDFAttributeMap orMap(JDFAttributeMap subMap)
        {
            IEnumerator <string> subMapEnum = subMap.getKeyIterator();

            while (subMapEnum.MoveNext())
            {
                string subMapKey    = subMapEnum.Current;
                string subMapVal    = subMap[subMapKey];
                string hashTableVal = this[subMapKey];

                if (hashTableVal != null)
                {
                    if (!hashTableVal.Equals(subMapVal))
                    {
                        this.Clear();
                        break;
                    }
                }
                else
                {
                    this.put(subMapKey, subMapVal);
                }
            }

            return(this);
        }
Exemple #6
0
        ///
        ///	 <summary> * overlapMap - identical keys must have the same values in both maps i.e submap is either a superset or a subset of
        ///	 * this
        ///	 *  </summary>
        ///	 * <param name="subMap"> the map to compare with <code>this</this>
        ///	 *  </param>
        ///	 * <returns> boolean - true if identical keys have the same values in both maps </returns>
        ///
        public virtual bool overlapMap(JDFAttributeMap subMap)
        {
            if (subMap == null || subMap.Count == 0)
            {
                return(true);
            }

            IEnumerator <string> subMapEnum = subMap.getKeyIterator();

            while (subMapEnum.MoveNext())
            {
                string subMapKey = subMapEnum.Current;
                string subMapVal = subMap[subMapKey];
                if (KElement.isWildCard(subMapVal))
                {
                    continue;
                }

                string val = this[subMapKey];
                if (val != null && !subMapVal.Equals(val))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #7
0
 ///
 ///	 <summary> * Method JDFAttributeMap clone the content of the input map
 ///	 *  </summary>
 ///	 * <param name="inputMap"> map to clone </param>
 ///
 public JDFAttributeMap(JDFAttributeMap inputMap)
 {
     if (inputMap != null)
     {
         m_hashTable = new Dictionary <string, string>(inputMap.m_hashTable);
     }
 }
        public virtual void testGet()
        {
            JDFAttributeMap m1 = new JDFAttributeMap(EnumPartIDKey.SignatureName, "v1");

            Assert.AreEqual("v1", m1.get("SignatureName"));
            m1.put(EnumPartIDKey.SheetName, "s1");
            Assert.AreEqual("v1", m1.get(EnumPartIDKey.SignatureName));
        }
Exemple #9
0
 ///
 ///	 <summary> * Method overlapMap.
 ///	 *  </summary>
 ///	 * <param name="map"> the map to check against </param>
 ///
 public virtual void overlapMap(JDFAttributeMap map)
 {
     for (int i = this.Count - 1; i >= 0; i--)
     {
         if (!this[i].overlapMap(map))
         {
             this.RemoveAt(i);
         }
     }
 }
Exemple #10
0
        public virtual void testCopy()
        {
            JDFAttributeMap  m1 = new JDFAttributeMap("a1", "v1");
            VJDFAttributeMap v2 = new VJDFAttributeMap();

            v2.Add(new JDFAttributeMap(m1));
            VJDFAttributeMap v3 = new VJDFAttributeMap(v2);

            Assert.AreEqual(v3, v2);
        }
Exemple #11
0
        public virtual void testShowKeys()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            Assert.AreEqual("(a1 = v1)", m1.showKeys(" "));
            m1.put("b1", "v2");
            Assert.AreEqual("(a1 = v1) (b1 = v2)", m1.showKeys(" "));
            Assert.AreEqual("(a1 = v1)\n(b1 = v2)", m1.showKeys("\n"));
            Assert.AreEqual("(a1 = v1)(b1 = v2)", m1.showKeys(null));
        }
Exemple #12
0
 ///
 ///	 <summary> * Method subMap.
 ///	 *  </summary>
 ///	 * <param name="map"> the submap to check against </param>
 ///	 * <returns> true if this has at least one entry that subMap is a submap of </returns>
 ///
 public virtual bool subMap(JDFAttributeMap map)
 {
     for (int i = this.Count - 1; i >= 0; i--)
     {
         if (this[i].subMap(map))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #13
0
 ///
 ///	 <summary> * Method overlapMap.
 ///	 *  </summary>
 ///	 * <param name="map"> the map to check against </param>
 ///
 public virtual bool overlapsMap(JDFAttributeMap map)
 {
     for (int i = Count - 1; i >= 0; i--)
     {
         if (this[i].overlapMap(map))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #14
0
        public virtual void testReduceMapSet()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap("a1", "v1");

            SupportClass.HashSetSupport <string> keys = new SupportClass.HashSetSupport <string>();
            keys.Add("a1");
            m1.reduceMap(keys);
            Assert.AreEqual(m1, m2);
        }
Exemple #15
0
        public virtual void testPut()
        {
            JDFAttributeMap m1 = new JDFAttributeMap(EnumPartIDKey.SignatureName, "v1");

            Assert.AreEqual("v1", m1.get("SignatureName"));
            m1.put(EnumPartIDKey.SheetName, "s1");
            Assert.AreEqual("s1", m1.get("SheetName"));
            m1.put(EnumPartIDKey.Side, EnumSide.Front);
            Assert.AreEqual("Front", m1.get("Side"));
            m1.put("Usage", EnumUsage.Input);
            Assert.AreEqual("Input", m1.get("Usage"));
        }
Exemple #16
0
        public virtual void testReduceMap()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            JDFAttributeMap m2   = new JDFAttributeMap("a1", "v1");
            VString         keys = new VString();

            keys.Add("a1");
            m1.reduceMap(keys);
            Assert.AreEqual(m1, m2);
        }
Exemple #17
0
        ///
        ///	 <summary> *  </summary>
        ///	 * <param name="map"> map to append </param>
        ///
        public virtual void appendUnique(JDFAttributeMap map)
        {
            for (int i = 0; i < m_vec.Count; i++)
            {
                if ((m_vec[i]).Equals(map))
                {
                    return;
                }
            }

            m_vec.Add(map);
        }
Exemple #18
0
        public virtual bool hasEntryWithEqualKeyValuePairs(JDFAttributeMap attmap)
        {
            bool bEquals = false;

            for (int i = 0; i < Count; i++)
            {
                // if its the same object...ne further action needed
                if (attmap == this[i])
                {
                    return(true);
                }

                // reset for every entry
                bEquals = false;
                JDFAttributeMap map = this[i];

                // only check if both have the same size

                if (map.Count == attmap.Count)
                {
                    // now that we found a entry with same entry counter set
                    // this to true. A single wrong entry will set it to false and
                    // break. If bEquals is still true after all checks, we found
                    // the map
                    bEquals = true;
                    IEnumerator <string> it = map.getKeyIterator();
                    while (it.MoveNext())
                    {
                        string key = it.Current;
                        if (!attmap.ContainsKey(key))
                        {
                            bEquals = false;
                            break;
                        }
                        string value1 = map.get(key);
                        string value2 = attmap.get(key);
                        if (!value1.Equals(value2))
                        {
                            bEquals = false;
                            break;
                        }
                    }
                    // if bEquals is still true we found a matching map
                    if (bEquals)
                    {
                        return(bEquals);
                    }
                }
            }

            return(bEquals);
        }
Exemple #19
0
        public virtual void testCloneNull()
        {
            JDFAttributeMap m1 = new JDFAttributeMap(null);

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap(m1);

            Assert.AreEqual(m1, m2);
            m2.put("a2", "v3");
            Assert.AreNotEqual(m1, m2);
            Assert.AreEqual("v2", m1.get("a2"));
            Assert.AreEqual("v3", m2.get("a2"));
        }
Exemple #20
0
        public virtual void testOverlapsMap()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap(m1);

            m2.put("a2", "v3");
            VJDFAttributeMap v = new VJDFAttributeMap();

            v.Add(m1);
            v.Add(m2);
            Assert.IsTrue(v.overlapsMap(m1));
            Assert.IsFalse(v.overlapsMap(new JDFAttributeMap("a2", "v4")));
        }
Exemple #21
0
        public virtual void testShowKeys()
        {
            JDFAttributeMap m1 = new JDFAttributeMap();

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap(m1);

            m2.put("a2", "v3");
            m2.put("a3", "v3");
            VJDFAttributeMap v = new VJDFAttributeMap();

            v.Add(m1);
            v.Add(m2);
            Assert.AreEqual("[0](a2 = v2)-[1](a2 = v3) (a3 = v3)", v.showKeys("-", " "));
        }
Exemple #22
0
        ///
        ///	 <summary> * returns the index of a given JDFAttributeMap, -1 if not present
        ///	 *  </summary>
        ///	 * <param name="map"> the given JDFAttributeMap </param>
        ///
        public virtual int IndexOf(JDFAttributeMap map)
        {
            int index = -1;
            int size  = this.Count;

            for (int i = 0; i < size; i++)
            {
                if (this[i].Equals(map))
                {
                    index = i;
                    break;
                }
            }
            return(index);
        }
Exemple #23
0
        ///
        ///	 * <param name="sepMap"> the separator between maps </param>
        ///	 * <param name="sepEntry"> the saparator between map entries </param>
        ///	 * <returns> the string representation </returns>
        ///
        public virtual string showKeys(string sepMap, string sepEntry)
        {
            StringBuilder sb        = new StringBuilder();
            int           nPartMaps = this.Count;

            for (int i = 0; i < nPartMaps; i++)
            {
                JDFAttributeMap amParts = this[i];
                sb.Append("[").Append(i).Append("]").Append(amParts.showKeys(sepEntry));
                if (i + 1 < nPartMaps)
                {
                    sb.Append(sepMap);
                }
            }
            return(sb.ToString());
        }
Exemple #24
0
        public virtual void testEquals()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap("a1", "v1");

            Assert.AreNotEqual(m1, m2);
            m2.put("a2", "v2");
            Assert.AreEqual(m1, m2);
            m1.put("a2", null);
            Assert.AreNotEqual(m1, m2);
            m2.put("a2", null);
            Assert.AreEqual(m1, m2);
            Assert.AreNotEqual(null, m1);
        }
Exemple #25
0
        public virtual void testPut()
        {
            JDFAttributeMap  m1 = new JDFAttributeMap("a1", "v1");
            VJDFAttributeMap v2 = new VJDFAttributeMap();

            v2.Add(m1);
            VJDFAttributeMap v3 = new VJDFAttributeMap(v2);

            Assert.AreEqual(v3, v2);
            v3.put("a2", "b");
            m1.put("a2", "b");
            Assert.AreEqual(v2, v3);
            VJDFAttributeMap v4 = new VJDFAttributeMap((VJDFAttributeMap)null);

            v4.put("a1", "b1");
            Assert.AreEqual(1, v4.Count);
        }
Exemple #26
0
        public virtual void reduceKey(ICollection <string> vKeys)
        {
            VJDFAttributeMap v = new VJDFAttributeMap();

            for (int i = 0; i < m_vec.Count; i++)
            {
                JDFAttributeMap map = m_vec[i];
                map.reduceMap(vKeys);

                if (!map.IsEmpty())
                {
                    v.appendUnique(map);
                }
            }

            m_vec = v.getVector();
        }
Exemple #27
0
        ///
        ///	 <summary> * reduce each JDFAttributeMap in <code>this</code> by keySet
        ///	 *  </summary>
        ///	 * <param name="keySet"> </param>
        ///
        public virtual void reduceMap(ICollection <string> keySet)
        {
            VJDFAttributeMap v = new VJDFAttributeMap();

            for (int i = 0; i < m_vec.Count; i++)
            {
                JDFAttributeMap map      = m_vec[i];
                bool            bNullMap = map.IsEmpty();
                map.reduceMap(keySet);

                if (bNullMap || !map.IsEmpty())
                {
                    v.appendUnique(map);
                }
            }
            m_vec = v.getVector();
        }
Exemple #28
0
        public virtual void testClone()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap(m1);

            m2.put("a2", "v3");
            VJDFAttributeMap v = new VJDFAttributeMap((VJDFAttributeMap)null);

            v.Add(m1);
            v.Add(m2);
            VJDFAttributeMap v2 = new VJDFAttributeMap(v);

            Assert.AreEqual(v2, v);
            m1.put("a3", "a4");
            Assert.AreNotEqual(v2, v, "modification did not migrate!");
        }
Exemple #29
0
        public virtual void testReduceMap()
        {
            JDFAttributeMap  m1 = new JDFAttributeMap("a1", "v1");
            VJDFAttributeMap v2 = new VJDFAttributeMap();

            v2.Add(new JDFAttributeMap(m1));
            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap(m1);

            m2.put("a2", "v3");
            VJDFAttributeMap v = new VJDFAttributeMap();

            v.Add(m1);
            v.Add(m2);
            VString vs = new VString("a1", " ");

            v.reduceMap(vs.getSet());
            Assert.AreEqual(v2, v);
        }
Exemple #30
0
        public virtual void testEquals()
        {
            JDFAttributeMap m1 = new JDFAttributeMap("a1", "v1");

            m1.put("a2", "v2");
            JDFAttributeMap m2 = new JDFAttributeMap(m1);

            m2.put("a2", "v3");
            VJDFAttributeMap v = new VJDFAttributeMap();

            v.Add(m1);
            v.Add(m2);
            VJDFAttributeMap v2 = new VJDFAttributeMap();

            v2.Add(m2);
            v2.Add(m1);
            Assert.AreEqual(v2, v, "mixed ordering");
            v2.Add(m1);
            Assert.AreNotEqual(v2, v, "mixed ordering -other cardinality ");
        }