Пример #1
0
        public static ListSet GetAirfields(String text)
        {
            ListSet aset = new ListSet();

            if (text.Contains("(") && text.Contains(")"))
            {
                String id = text.Substring(text.LastIndexOf("(") + 1, text.LastIndexOf(")") - text.LastIndexOf("(") - 1);
                if (id.Contains("Lat:") && id.Contains("Long:"))
                {
                    Airfield a = new Airfield();
                    a.ICAOCODE     = "T-T" + RandomPassword.Generate(5);
                    a.AirfieldName = text.Remove(text.IndexOf(",")).Trim();
                    a.Country      = text.Substring(text.IndexOf(",") + 1, text.IndexOf("(") - text.IndexOf(",") - 1).Trim();
                    foreach (String l in id.Split(",".ToCharArray()))
                    {
                        Double temp;
                        if (l.Contains("Lat:"))
                        {
                            temp = Double.Parse(l.Substring(l.LastIndexOf(":") + 1));
                            string[] parts = DDtoDMS(temp, CoordinateType.latitude).Split(".".ToCharArray());
                            a.LattitudeDegrees = Int32.Parse(parts[0]);
                            a.LattitudeMinutes = Int32.Parse(parts[1]);
                            a.NS = Char.Parse(parts[2]);
                        }
                        else if (l.Contains("Long:"))
                        {
                            temp = Double.Parse(l.Substring(l.LastIndexOf(":") + 1));
                            string[] parts = DDtoDMS(temp, CoordinateType.longitude).Split(".".ToCharArray());
                            a.LongitudeDegrees = Int32.Parse(parts[0]);
                            a.LongitudeMinutes = Int32.Parse(parts[1]);
                            a.EW = Char.Parse(parts[2]);
                        }
                    }
                    aset.Add(a);
                }
                else
                {
                    Airfield a = AirfieldDAO.FindAirfieldByID(id);
                    aset.Add(a);
                }
            }
            else
            {
                aset.AddAll(SearchAifields(text));
                if (aset.Count == 0)
                {
                    String[] keywords = text.Split(", ".ToCharArray());
                    foreach (String s in keywords)
                    {
                        if (s.Length >= 3)
                        {
                            aset.AddAll(SearchAifields(s));
                        }
                    }
                }
            }
            return(aset);
        }
Пример #2
0
        /// <summary> Tests whether a <see cref="Geometry"/> is sequenced correctly.
        /// <see cref="LineString"/>s are trivially sequenced.
        /// <see cref="MultiLineString"/>s are checked for correct sequencing.
        /// Otherwise, <code>isSequenced</code> is defined
        /// to be <see langword="true"/> for geometries that are not lineal.
        ///
        /// </summary>
        /// <param name="geom">the geometry to test
        /// </param>
        /// <returns> <see langword="true"/> if the geometry is sequenced or is not lineal
        /// </returns>
        public static bool IsSequenced(Geometry geom)
        {
            if (!(geom is MultiLineString))
            {
                return(true);
            }

            MultiLineString mls = (MultiLineString)geom;
            // the nodes in all subgraphs which have been completely scanned
            //TODO--PAUL 'java.util.TreeSet' was converted to ListSet
            ListSet prevSubgraphNodes = new ListSet();

            Coordinate lastNode  = null;
            IList      currNodes = new ArrayList();

            for (int i = 0; i < mls.NumGeometries; i++)
            {
                LineString line      = (LineString)mls.GetGeometry(i);
                Coordinate startNode = line.GetCoordinate(0);
                Coordinate endNode   = line.GetCoordinate(line.NumPoints - 1);

                // If this linestring is connected to a previous subgraph,
                // geom is not sequenced
                if (prevSubgraphNodes.Contains(startNode))
                {
                    return(false);
                }
                if (prevSubgraphNodes.Contains(endNode))
                {
                    return(false);
                }

                if (lastNode != null)
                {
                    if (!startNode.Equals(lastNode))
                    {
                        // start new connected sequence
                        prevSubgraphNodes.AddAll(currNodes);
                        currNodes.Clear();
                    }
                }

                currNodes.Add(startNode);
                currNodes.Add(endNode);
                lastNode = endNode;
            }

            return(true);
        }
        public void TestDifferentCollectionTypes()
        {
            const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
            <objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'>
          <v:group id='validatePerson' when='T(Spring.Objects.TestObject) == #this.GetType()'>
            <v:required id ='req' when='true' test='Name'/>
            <v:regex id ='reg' test='Name'>
              <v:property name='Expression' value='[a-z]*\s[a-z]*'/>
              <v:property name='Options' value='IgnoreCase'/>
              <v:message id='reg1' providers='regularni' when='true'>
                 <v:param value='#this.ToString()'/> 
              </v:message>
            </v:regex>
          </v:group>  
           <v:collection id='collectionValidator' validate-all='true'>
                <v:ref name='validatePerson'/>
           </v:collection>
           </objects>";

            MemoryStream stream   = new MemoryStream(new UTF8Encoding().GetBytes(xml));
            IResource    resource = new InputStreamResource(stream, "collectionValidator");

            XmlObjectFactory    objectFactory = new XmlObjectFactory(resource, null);
            CollectionValidator validator     = (CollectionValidator)objectFactory.GetObject("collectionValidator");

            IList       listPersons = new ArrayList();
            IDictionary dictPersons = new Hashtable();
            ISet        setPersons  = new ListSet();

            listPersons.Add(new TestObject("DAMJAN Tomic", 24));
            listPersons.Add(new TestObject("Goran Milosavljevic", 24));
            listPersons.Add(new TestObject("Ivan CIKIC", 28));

            dictPersons.Add(1, listPersons[0]);
            dictPersons.Add(2, listPersons[1]);
            dictPersons.Add(3, listPersons[2]);

            setPersons.AddAll(listPersons);
            IValidationErrors ve = new ValidationErrors();

            Assert.IsTrue(validator.Validate(listPersons, ve));
            Assert.IsTrue(ve.IsEmpty);
            Assert.IsTrue(validator.Validate(dictPersons, ve));
            Assert.IsTrue(ve.IsEmpty);
            Assert.IsTrue(validator.Validate(setPersons, ve));
            Assert.IsTrue(ve.IsEmpty);
        }
Пример #4
0
        public void TestDifferenceOperator()
        {
            object o = ExpressionEvaluator.GetValue(null, "{111, 11} - {14, 12, 11}");
            Assert.IsInstanceOf(typeof(ISet), o);
            ISet diff = (ISet)o;
            Assert.AreEqual(1, diff.Count);
            Assert.IsTrue(diff.Contains(111));

            o = ExpressionEvaluator.GetValue(null, "{111, 11} - {14, 12, 11} - {111}");
            Assert.IsInstanceOf(typeof(ISet), o);
            diff = (ISet)o;
            Assert.AreEqual(0, diff.Count);

            ISet testset = new ListSet();
            testset.AddAll(new int[] { 1, 2, 3, 5, 8 });
            o = ExpressionEvaluator.GetValue(testset, "#this - #{1:'one', 10:'ten'}");
            Assert.IsInstanceOf(typeof(ISet), o);
            diff = (ISet)o;
            Assert.AreEqual(4, diff.Count);
            Assert.IsFalse(diff.Contains(1));

            o = ExpressionEvaluator.GetValue(null, "#{1:'one', 2:'two', 3:'three'} - #{1:'ivan', 5:'five'}");
            Assert.IsInstanceOf(typeof(IDictionary), o);
            IDictionary result = (IDictionary)o;
            Assert.AreEqual(2, result.Count);
            Assert.IsNull(result[1]);
            Assert.AreEqual("three", result[3]);

            o = ExpressionEvaluator.GetValue(null, "#{1:'one', 2:'two', 3:'three'} - {1, 2, 3, 5, 7}");
            Assert.IsInstanceOf(typeof(IDictionary), o);
            result = (IDictionary)o;
            Assert.AreEqual(0, result.Count);
        }
Пример #5
0
        public void TestUnionOperator()
        {
            object o = ExpressionEvaluator.GetValue(null, "{1,2,3} + {3,4,5}");
            Assert.IsInstanceOf(typeof(ISet), o);
            ISet union = (ISet)o;
            Assert.AreEqual(5, union.Count);
            Assert.IsTrue(union.Contains(1));
            Assert.IsTrue(union.Contains(3));
            Assert.IsTrue(union.Contains(5));

            o = ExpressionEvaluator.GetValue(null, "{1,2,3} + {3,4,5} + {'ivan', 'gox', 'damjao', 5}");
            Assert.IsInstanceOf(typeof(ISet), o);
            union = (ISet)o;
            Assert.AreEqual(8, union.Count);
            Assert.IsTrue(union.Contains(1));
            Assert.IsTrue(union.Contains("ivan"));

            ISet testset = new ListSet();
            testset.AddAll(new int[] { 1, 2, 3, 5, 8 });
            o = ExpressionEvaluator.GetValue(testset, "#this + {1, 2, 13, 15}");
            Assert.IsInstanceOf(typeof(ISet), o);
            union = (ISet)o;
            Assert.AreEqual(7, union.Count);
            Assert.IsTrue(union.Contains(1));
            Assert.IsTrue(union.Contains(15));

            o = ExpressionEvaluator.GetValue(null, "#{1:'one', 2:'two', 3:'three'} + #{1:'ivan', 5:'five'}");
            Assert.IsInstanceOf(typeof(IDictionary), o);
            IDictionary result = (IDictionary)o;
            Assert.AreEqual(4, result.Count);
            Assert.AreEqual("one", result[1]);
            Assert.AreEqual("five", result[5]);
        }
Пример #6
0
        public void TestIntersectionOperator()
        {
            object o = ExpressionEvaluator.GetValue(null, "{111, 'ivan', 23, 24} * {111, 11, 'ivan'}");
            Assert.IsInstanceOf(typeof(ISet), o);
            ISet intersection = (ISet)o;
            Assert.AreEqual(2, intersection.Count);
            Assert.IsTrue(intersection.Contains(111));
            Assert.IsTrue(intersection.Contains("ivan"));

            o = ExpressionEvaluator.GetValue(null, "{24, 25, 'aaa' + 'bb'} * {date('2007/2/5').day * 5, 24 - 1}");
            Assert.IsInstanceOf(typeof(ISet), o);
            intersection = (ISet)o;
            Assert.AreEqual(1, intersection.Count);
            Assert.IsTrue(intersection.Contains(25));

            ISet testset = new ListSet();
            testset.AddAll(new int[] { 1, 2, 3, 5, 8 });
            o = ExpressionEvaluator.GetValue(testset, "#this * #{1:'one', 10:'ten'}");
            Assert.IsInstanceOf(typeof(ISet), o);
            intersection = (ISet)o;
            Assert.AreEqual(1, intersection.Count);
            Assert.IsTrue(intersection.Contains(1));

            o = ExpressionEvaluator.GetValue(null, "#{1:'one', 2:'two', 3:'three'} * #{1:'ivan', 5:'five'}");
            Assert.IsInstanceOf(typeof(IDictionary), o);
            IDictionary result = (IDictionary)o;
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("one", result[1]);

            o = ExpressionEvaluator.GetValue(null, "#{1:'one', 2:'two', 3:'three'} * {1, 2, 5, 7}");
            Assert.IsInstanceOf(typeof(IDictionary), o);
            result = (IDictionary)o;
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("one", result[1]);
            Assert.AreEqual("two", result[2]);
        }
        public void TestDifferentCollectionTypes()
        {
            const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
            <objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'>
          <v:group id='validatePerson' when='T(Spring.Objects.TestObject) == #this.GetType()'>
            <v:required id ='req' when='true' test='Name'/>
            <v:regex id ='reg' test='Name'>
              <v:property name='Expression' value='[a-z]*\s[a-z]*'/>
              <v:property name='Options' value='IgnoreCase'/>
              <v:message id='reg1' providers='regularni' when='true'>
                 <v:param value='#this.ToString()'/> 
              </v:message>
            </v:regex>
          </v:group>  
           <v:collection id='collectionValidator' validate-all='true'>
                <v:ref name='validatePerson'/>
           </v:collection>
           </objects>";

            MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xml));
            IResource resource = new InputStreamResource(stream, "collectionValidator");

            XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);
            CollectionValidator validator = (CollectionValidator) objectFactory.GetObject("collectionValidator");
            
            IList listPersons = new ArrayList();
            IDictionary dictPersons = new Hashtable();
            ISet setPersons = new ListSet();  

            listPersons.Add(new TestObject("DAMJAN Tomic", 24));
            listPersons.Add(new TestObject("Goran Milosavljevic", 24));
            listPersons.Add(new TestObject("Ivan CIKIC", 28));

            dictPersons.Add(1, listPersons[0]);
            dictPersons.Add(2, listPersons[1]);
            dictPersons.Add(3, listPersons[2]);

            setPersons.AddAll(listPersons);
            IValidationErrors ve = new ValidationErrors();

            Assert.IsTrue(validator.Validate(listPersons, ve));                        
            Assert.IsTrue(ve.IsEmpty);                                    
            Assert.IsTrue(validator.Validate(dictPersons, ve));
            Assert.IsTrue(ve.IsEmpty);
            Assert.IsTrue(validator.Validate(setPersons, ve));
            Assert.IsTrue(ve.IsEmpty);
        }