Example #1
0
    public ArrayList <Path> getShortestPath(Int32 start, Int32 target, Int32 number)
    {
        ArrayList <Path> L0, L, P;
        HashSet <Path>   L1;

        L = new ArrayList <Path>(getShortestPath(start, target));
        if (L.size() >= number)
        {
            return(new ArrayList <Path>(L.subList(0, number)));
        }

        if (L.size() == 0)
        {
            return(new ArrayList <Path>());
        }

        L0 = new ArrayList <Path>(L.subList(0, 1));
        L1 = new HashSet <Path>(L.subList(1, L.size()).ToArray());
        P  = new ArrayList <Path>(L0);

        for (int k = 1; k < number; k++)
        {
            Path[] paths = getPathDeviations(P.get(k - 1), P).ToArray();
            foreach (Path p in paths)
            {
                bool b = true;
                foreach (Path l in L1)
                {
                    if (p.Equals(l))
                    {
                        b = false; break;
                    }
                }
                if (b)
                {
                    L1.Add(p);
                }
            }
            double minLen     = Double.MaxValue;
            Path   shortestL1 = null;
            foreach (Path p in L1)
            {
                if (p.val < minLen)
                {
                    minLen     = p.val;
                    shortestL1 = p;
                }
            }

            if (shortestL1 == null)
            {
                break;
            }
            L0.add(shortestL1);
            P.add(shortestL1);
            L1.Remove(shortestL1);
        }

        return(L0);
    }
        static void ArrayListTest()
        {
            ArrayList <int> list = new ArrayList <int>();

            for (int i = 0; i < 100; i++)
            {
                list.add(i);
            }

            Console.WriteLine("Size: " + list.size());

            list = list.subList(0, 50);
            Console.WriteLine("Size: " + list.size());

            list.print();

            Console.WriteLine(list.isEmpty());

            list.reverse();
            list[0] = 350;
            Console.WriteLine(list.get(5));
            Console.WriteLine(list[5]);
            Console.WriteLine(list.contains(3));
            list.print();
        }
Example #3
0
        private static void duplicatePath(int num, State state, State state2, ArrayList arrayList)
        {
            ArrayList arrayList2 = (ArrayList)arrayList.get(num);
            int       num2       = arrayList2.indexOf(state);
            int       num3       = arrayList2.indexOf(state2);

            if (num3 == -1)
            {
                num3 = arrayList2.size() - 1;
            }
            ArrayList arrayList3 = new ArrayList(arrayList2.subList(num2, num3));

            arrayList.add(arrayList3);
        }
Example #4
0
        public static int search(ArrayList src, ArrayList pattern, int start)
        {
            int result = -1;
            int num    = 0;

            if (start > src.size() - pattern.size())
            {
                return(-1);
            }
            int num2;

            for (;;)
            {
                num2 = src.subList(num + start, src.size() - pattern.size() + 1).indexOf(pattern.get(0));
                if (num2 == -1)
                {
                    break;
                }
                int num3 = 1;
                for (int i = 1; i < pattern.size(); i++)
                {
                    if (!String.instancehelper_equals((string)src.get(num + start + num2 + i), pattern.get(i)))
                    {
                        result = -1;
                        num3   = 0;
                        break;
                    }
                }
                if (num3 != 0)
                {
                    goto Block_5;
                }
                num += num2 + 1;
                if (num + start >= src.size())
                {
                    return(result);
                }
            }
            return(num2);

Block_5:
            result = num + num2;
            return(result);
        }
 public String[] split(CharSequence input, int limit) {
     int index = 0;
     boolean matchLimited = limit > 0;
     ArrayList<String> matchList = new ArrayList<String>();
     Matcher m = matcher(input);
     // Add segments before each match found
     while(m.find()) {
         if (!matchLimited || matchList.size() < limit - 1) {
             String match = input.subSequence(index, m.start()).toString();
             matchList.add(match);
             index = m.end();
         } else if (matchList.size() == limit - 1) { // last one
             String match = input.subSequence(index,
                                              input.length()).toString();
             matchList.add(match);
             index = m.end();
         }
     }
     // If no match was found, return this
     if (index == 0)
         return new String[] {input.toString()};
     // Add remaining segment
     if (!matchLimited || matchList.size() < limit)
         matchList.add(input.subSequence(index, input.length()).toString());
     // Construct result
     int resultSize = matchList.size();
     if (limit == 0)
         while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
             resultSize--;
     String[] result = new String[resultSize];
     return matchList.subList(0, resultSize).toArray(result);
 }
Example #6
0
        public String[] split(String regex, int limit)
        {
            /* fastpath if the regex is a
             * (1)one-char String and this character is not one of the
             *  RegEx's meta characters ".$|()[{^?*+\\", or
             * (2)two-char String and the first char is the backslash and
             *  the second is not the ascii digit or ascii letter.
             */
            char ch = (char)0;

            if (((regex.value.Length == 1 &&
                  new String(".$|()[{^?*+\\").indexOf(ch = regex.charAt(0)) == -1) ||
                 (regex.length() == 2 &&
                  regex.charAt(0) == '\\' &&
                  (((ch = regex.charAt(1)) - '0') | ('9' - ch)) < 0 &&
                  ((ch - 'a') | ('z' - ch)) < 0 &&
                  ((ch - 'A') | ('Z' - ch)) < 0)) &&
                (ch < Character.MIN_HIGH_SURROGATE ||
                 ch > Character.MAX_LOW_SURROGATE))
            {
                int                off     = 0;
                int                next    = 0;
                boolean            limited = limit > 0;
                ArrayList <String> list    = new ArrayList <String>();
                while ((next = indexOf(ch, off)) != -1)
                {
                    if (!limited || list.size() < limit - 1)
                    {
                        list.add(substring(off, next));
                        off = next + 1;
                    }
                    else    // last one
                    //assert (list.size() == limit - 1);
                    {
                        list.add(substring(off, value.Length));
                        off = value.Length;
                        break;
                    }
                }
                // If no match was found, return this
                if (off == 0)
                {
                    return new String[] { this }
                }
                ;

                // Add remaining segment
                if (!limited || list.size() < limit)
                {
                    list.add(substring(off, value.Length));
                }

                // Construct result
                int resultSize = list.size();
                if (limit == 0)
                {
                    while (resultSize > 0 && list.get(resultSize - 1).length() == 0)
                    {
                        resultSize--;
                    }
                }
                String[] result = new String[resultSize];
                return(list.subList(0, resultSize).toArray(result));
            }
            return(Pattern.compile(regex).split(this, limit));
        }