Example #1
0
        protected internal virtual bool optimizeNodeForward(Node n)
        {
            if (!LatticeOptimizer.assertionsDisabled && !this.__lattice.hasNode(n))
            {
                throw new AssertionError();
            }
            ArrayList arrayList = new ArrayList(n.getLeavingEdges());

            for (int i = 0; i < arrayList.size(); i++)
            {
                Edge edge = (Edge)arrayList.get(i);
                for (int j = i + 1; j < arrayList.size(); j++)
                {
                    Edge edge2 = (Edge)arrayList.get(j);
                    if (!LatticeOptimizer.assertionsDisabled && edge == edge2)
                    {
                        throw new AssertionError();
                    }
                    if (this.equivalentNodesForward(edge.getToNode(), edge2.getToNode()))
                    {
                        this.mergeNodesAndEdgesForward(edge, edge2);
                        return(true);
                    }
                }
            }
            return(false);
        }
    public static string test()
    {
        var result = "";
        var l1     = new ArrayList <string> {
            "A", "B", "C"
        };
        var l2 = new ArrayList <string> {
            "A", "C"
        };

        for (int i = 0, j = 0; i < l1.size() && j < l2.size(); i++, j++)
        {
            if (l1[i].equals(l2[j]))
            {
                result += l1[i];
            }
            else
            {
                break;
            }
        }
        for (int i = l1.size() - 1, j = l2.size() - 1; i >= 0 && j >= 0; --i, --j)
        {
            if (l1[i].equals(l2[j]))
            {
                result += l1[i];
            }
            else
            {
                break;
            }
        }
        return(result);
    }
        public int execute(Env env, Value stillRunning)
        {
            if (_runningCount == 0)
            {
                stillRunning.set(LongValue.ZERO);

                return(CurlModule.CURLM_OK);
            }
            else if (_runningCount < 0)
            {
                _runningCount = _curlList.size();

                for (CurlResource curl : _curlList)
                {
                    curl.execute(env, false);

                    _msgQueue.add(curl);
                }
            }

            _runningCount--;

            stillRunning.set(LongValue.create(_runningCount));

            if (_runningCount == 0)
            {
                return(CurlModule.CURLM_OK);
            }
            else
            {
                return(CurlModule.CURLM_CALL_MULTI_PERFORM);
            }
        }
 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);
 }
        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();
        }
        public override bool func_22101_a(string s, IProgressUpdate iprogressupdate)
        {
            iprogressupdate.setLoadingProgress(0);
            var arraylist  = new ArrayList();
            var arraylist1 = new ArrayList();
            var arraylist2 = new ArrayList();
            var arraylist3 = new ArrayList();
            var file       = new File(field_22106_a, s);
            var file1      = new File(file, "DIM-1");

            [email protected]("Scanning folders...");
            func_22108_a(file, arraylist, arraylist1);
            if (file1.exists())
            {
                func_22108_a(file1, arraylist2, arraylist3);
            }
            int i = arraylist.size() + arraylist2.size() + arraylist1.size() + arraylist3.size();

            [email protected](
                (new StringBuilder()).append("Total conversion count is ").append(i).toString());
            func_22107_a(file, arraylist, 0, i, iprogressupdate);
            func_22107_a(file1, arraylist2, arraylist.size(), i, iprogressupdate);
            WorldInfo worldinfo = func_22103_b(s);

            worldinfo.func_22191_a(19132);
            ISaveHandler isavehandler = func_22105_a(s, false);

            isavehandler.func_22094_a(worldinfo);
            func_22109_a(arraylist1, arraylist.size() + arraylist2.size(), i, iprogressupdate);
            if (file1.exists())
            {
                func_22109_a(arraylist3, arraylist.size() + arraylist2.size() + arraylist1.size(), i, iprogressupdate);
            }
            return(true);
        }
Example #7
0
        /// <summary>
        /// 触摸点击方法
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public void onClick(FCTouchInfo touchInfo)
        {
            FCPoint mp = touchInfo.m_firstPoint;
            int     monthButtonsSize = m_monthButtons.size();

            for (int i = 0; i < monthButtonsSize; i++)
            {
                MonthButton monthButton = m_monthButtons.get(i);
                if (monthButton.Visible)
                {
                    FCRect bounds = monthButton.Bounds;
                    if (mp.x >= bounds.left && mp.x <= bounds.right && mp.y >= bounds.top && mp.y <= bounds.bottom)
                    {
                        monthButton.onClick(touchInfo);
                        return;
                    }
                }
            }
            int monthButtonAmSize = m_monthButtons_am.size();

            for (int i = 0; i < monthButtonAmSize; i++)
            {
                MonthButton monthButton = m_monthButtons_am.get(i);
                if (monthButton.Visible)
                {
                    FCRect bounds = monthButton.Bounds;
                    if (mp.x >= bounds.left && mp.x <= bounds.right && mp.y >= bounds.top && mp.y <= bounds.bottom)
                    {
                        monthButton.onClick(touchInfo);
                        return;
                    }
                }
            }
        }
        /**
         * Ends an element
         */
        public bool endElement(Env env)
        {
            if (_state == WriterState.ATTRIBUTE)
            {
                endAttribute();
            }

            if (_elementStack.size() == 0)
            {
                return(false);
            }
            else if (_state == WriterState.ELEMENT_HEADER)
            {
                popElement();

                _s.append("/>");

                return(true);
            }
            else if (_state == WriterState.ELEMENT_BODY)
            {
                StringValue name = popElement();

                _s.append("</").append(env, name).append(">");

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #9
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);
    }
Example #10
0
        public EntityPainting(World world, int i, int j, int k, int l) : this(world)
        {
            xPosition = i;
            yPosition = j;
            zPosition = k;
            var       arraylist = new ArrayList();
            EnumArt[] aenumart  = EnumArt.values();
            int       i1        = aenumart.Length;
            for (int j1 = 0; j1 < i1; j1++)
            {
                EnumArt enumart = aenumart[j1];
                art = enumart;
                func_179_a(l);
                if (onValidSurface())
                {
                    arraylist.add(enumart);
                }
            }

            if (arraylist.size() > 0)
            {
                art = (EnumArt)arraylist.get(rand.nextInt(arraylist.size()));
            }
            func_179_a(l);
        }
        public void writePageGroup(int id, int parentId, ArrayList <PDFPage> pages)

        {
            beginObject(id);
            println("  << /Type /Pages");
            print("     /Kids [");

            for (int i = 0; i < pages.size(); i++)
            {
                if (i != 0)
                {
                    print(" ");
                }

                print(pages.get(i).getId() + " 0 R");
            }

            println("]");
            println("     /Count " + pages.size());
            println("     /Parent " + parentId + " 0 R");

            println("  >>");
            endObject();

            for (int i = 0; i < pages.size(); i++)
            {
                pages.get(i).write(this);
            }
        }
Example #12
0
 public DataInputStream getChunkDataInputStream(int i, int j)
 {
     if (outOfBounds(i, j))
     {
         debugln("READ", i, j, "out of bounds");
         return(null);
     }
     try
     {
         int k = getOffset(i, j);
         if (k == 0)
         {
             return(null);
         }
         int l  = k >> 8;
         int i1 = k & 0xff;
         if (l + i1 > sectorFree.size())
         {
             debugln("READ", i, j, "invalid sector");
             return(null);
         }
         dataFile.seek(l * 4096);
         int j1 = dataFile.readInt();
         if (j1 > 4096 * i1)
         {
             debugln("READ", i, j,
                     (new StringBuilder()).append("invalid length: ").append(j1).append(" > 4096 * ").append(i1).
                     toString());
             return(null);
         }
         byte byte0 = dataFile.readByte();
         if (byte0 == 1)
         {
             var abyte0 = new byte[j1 - 1];
             dataFile.read(abyte0);
             var datainputstream =
                 new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(abyte0)));
             return(datainputstream);
         }
         if (byte0 == 2)
         {
             var abyte1 = new byte[j1 - 1];
             dataFile.read(abyte1);
             var datainputstream1 =
                 new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(abyte1)));
             return(datainputstream1);
         }
         else
         {
             debugln("READ", i, j, (new StringBuilder()).append("unknown version ").append(byte0).toString());
             return(null);
         }
     }
     catch (IOException)
     {
         debugln("READ", i, j, "exception");
     }
     return(null);
 }
        protected int addUpdateableCompositeToEntity(UpdateableComposite updateable)
        {
            int index = updateablesList.size();

            updateablesList.add(updateable);

            return(index);
        }
Example #14
0
 //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'"
 public virtual void  writeExternal(System.IO.BinaryWriter out_Renamed)
 {
     ExtUtil.writeNumeric(out_Renamed, points.size());
     for (int i = 0; i < points.size(); ++i)
     {
         GeoPointData t = points.get_Renamed(i);
         t.writeExternal(out_Renamed);
     }
 }
Example #15
0
        /// <summary>
        /// 隐藏
        /// </summary>
        public virtual void hide()
        {
            int yearButtonSize = m_yearButtons.size();

            for (int i = 0; i < yearButtonSize; i++)
            {
                YearButton yearButton = m_yearButtons.get(i);
                yearButton.Visible = false;
            }
        }
Example #16
0
        /// <summary>
        /// 隐藏
        /// </summary>
        public virtual void hide()
        {
            int monthButtonSize = m_monthButtons.size();

            for (int i = 0; i < monthButtonSize; i++)
            {
                MonthButton monthButton = m_monthButtons.get(i);
                monthButton.Visible = false;
            }
        }
Example #17
0
        private Fst entryToFSA(ArrayList arrayList)
        {
            TropicalSemiring tropicalSemiring = new TropicalSemiring();
            Fst   fst   = new Fst(tropicalSemiring);
            State state = new State(tropicalSemiring.zero());

            fst.addState(state);
            fst.setStart(state);
            for (int i = 0; i < arrayList.size() + 1; i++)
            {
                state = new State(tropicalSemiring.zero());
                fst.addState(state);
                if (i >= 1)
                {
                    int index = Utils.getIndex(this.g2pmodel.getIsyms(), (string)arrayList.get(i - 1));
                    fst.getState(i).addArc(new Arc(index, index, 0f, state));
                }
                else if (i == 0)
                {
                    int index = Utils.getIndex(this.g2pmodel.getIsyms(), this.sb);
                    fst.getStart().addArc(new Arc(index, index, 0f, state));
                }
                if (i == arrayList.size())
                {
                    State state2 = new State(tropicalSemiring.zero());
                    fst.addState(state2);
                    int num = Utils.getIndex(this.g2pmodel.getIsyms(), this.se);
                    state.addArc(new Arc(num, num, 0f, state2));
                    state2.setFinalWeight(0f);
                }
            }
            for (int i = 0; i < this.clusters.Length; i++)
            {
                ArrayList arrayList2 = this.clusters[i];
                if (arrayList2 != null)
                {
                    int num  = 0;
                    int num2 = 0;
                    while (num2 != -1)
                    {
                        num2 = Utils.search(arrayList, arrayList2, num);
                        if (num2 != -1)
                        {
                            State state3 = fst.getState(num + num2 + 1);
                            state3.addArc(new Arc(i, i, 0f, fst.getState(num + num2 + arrayList2.size() + 1)));
                            num = num + num2 + arrayList2.size();
                        }
                    }
                }
            }
            fst.setIsyms(this.g2pmodel.getIsyms());
            fst.setOsyms(this.g2pmodel.getIsyms());
            return(fst);
        }
Example #18
0
        /// <summary>
        /// 清除单元格
        /// </summary>
        public void clearCells()
        {
            int cellSize = m_cells.size();

            for (int i = 0; i < cellSize; i++)
            {
                m_cells.get(i).onRemove();
                m_cells.get(i).delete();
            }
            m_cells.clear();
        }
 public override string getNodeName()
 {
     if (_attrList.size() > 0)
     {
         return(_attrList.get(0).getNodeName());
     }
     else
     {
         return("");
     }
 }
Example #20
0
        /**
         * Adds a new report
         */
        public static void addReport(ProfileReport report)
        {
            synchronized(_reportList)
            {
                _reportList.add(0, report);

                while (_reportList.size() > 32)
                {
                    _reportList.remove(_reportList.size() - 1);
                }
            }
        }
        public ListHeadExpr(ArrayList <Expr> varList)
        {
            _varList = new Expr[varList.size()];
            varList.toArray(_varList);

            _keyList = new Value[varList.size()];

            for (int i = 0; i < varList.size(); i++)
            {
                _keyList[i] = LongValue.create(i);
            }
        }
Example #22
0
        /// <summary>
        /// 清除列
        /// </summary>
        public void clearColumns()
        {
            int columnsSize = m_columns.size();

            for (int i = 0; i < columnsSize; i++)
            {
                FCBandedFCGridColumn column = m_columns.get(i);
                m_grid.removeColumn(column);
                column.delete();
            }
            m_columns.clear();
        }
Example #23
0
        /// <summary>
        /// Calculates the ratio of each part of speech to the total size of the vocabulary
        /// </summary>
        /// <param name="wc">An array of integers representing the count of each POS</param>
        /// <param name="wl">The list of VocabWords</param>
        /// <returns>An array of doubles representing the ratio of each part of speech to the total size of the vocabulary</returns>
        public double[] getRatios(int[] wc, ArrayList wl)
        {
            double[] toReturn = new double[5];

            toReturn[0] = Math.Round(100.0 * wc[0] / (double)wl.size(), 2);
            toReturn[1] = Math.Round(100.0 * wc[1] / (double)wl.size(), 2);
            toReturn[2] = Math.Round(100.0 * wc[2] / (double)wl.size(), 2);
            toReturn[3] = Math.Round(100.0 * wc[3] / (double)wl.size(), 2);
            toReturn[4] = Math.Round(100.0 * (wc[0] + wc[1] + wc[2] + wc[3]) / (double)wl.size(), 2);


            return(toReturn);
        }
Example #24
0
 /// <summary>
 /// 清除所有节点
 /// </summary>
 public void clearNodes()
 {
     while (m_nodes.size() > 0)
     {
         removeNode(m_nodes.get(m_nodes.size() - 1));
     }
 }
Example #25
0
        public BlockStatement append(ArrayList <Statement> statementList)
        {
            Statement [] statements
                = new Statement[_statements.length + statementList.size()];

            System.arraycopy(_statements, 0, statements, 0, _statements.length);

            for (int i = 0; i < statementList.size(); i++)
            {
                statements[i + _statements.length] = statementList.get(i);
            }

            return(new BlockStatement(getLocation(), statements));
        }
	public void testGenerateCorrect3Successors() {
		List<Action> actions = new ArrayList<Action>(EightPuzzleFunctionFactory
				.getActionsFunction().actions(board));
		Assert.assertEquals(3, actions.size());

		// test first successor
		EightPuzzleBoard expectedFirst = new EightPuzzleBoard(new int[] { 1, 2,
				0, 3, 4, 5, 6, 7, 8 });
		EightPuzzleBoard actualFirst = (EightPuzzleBoard) EightPuzzleFunctionFactory
				.getResultFunction().result(board, actions.get(0));
		Assert.assertEquals(expectedFirst, actualFirst);
		Assert.assertEquals(EightPuzzleBoard.UP, actions.get(0));

		// test second successor
		EightPuzzleBoard expectedSecond = new EightPuzzleBoard(new int[] { 1,
				2, 5, 3, 4, 8, 6, 7, 0 });
		EightPuzzleBoard actualSecond = (EightPuzzleBoard) EightPuzzleFunctionFactory
				.getResultFunction().result(board, actions.get(1));
		Assert.assertEquals(expectedSecond, actualSecond);
		Assert.assertEquals(EightPuzzleBoard.DOWN, actions.get(1));

		// test third successor
		EightPuzzleBoard expectedThird = new EightPuzzleBoard(new int[] { 1, 2,
				5, 3, 0, 4, 6, 7, 8 });
		EightPuzzleBoard actualThird = (EightPuzzleBoard) (EightPuzzleBoard) EightPuzzleFunctionFactory
				.getResultFunction().result(board, actions.get(2));
		Assert.assertEquals(expectedThird, actualThird);
		Assert.assertEquals(EightPuzzleBoard.LEFT, actions.get(2));
	}
Example #27
0
        public VPFRelation[] getFeatureClassRelations(String className)
        {
            if (className == null)
            {
                String message = Logging.getMessage("nullValue.ClassNameIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            ArrayList <VPFRelation> rels = new ArrayList <VPFRelation>();

            foreach (VPFRecord row in this.featureClassSchemaTable)
            {
                Object o = row.getValue("feature_class");
                if (o == null || !(o is String))
                {
                    continue;
                }

                if (!className.equalsIgnoreCase((String)o))
                {
                    continue;
                }

                rels.add(new VPFRelation(
                             (String)row.getValue("table1"),
                             (String)row.getValue("table1_key"),
                             (String)row.getValue("table2"),
                             (String)row.getValue("table2_key")));
            }

            VPFRelation[] array = new VPFRelation[rels.size()];
            rels.toArray(array);
            return(array);
        }
Example #28
0
        /// <summary>
        /// 移除节点方法
        /// </summary>
        public virtual void onRemovingNode()
        {
            m_indent = 0;
            FCGridRow row = Row;

            if (row != null)
            {
                if (m_nodes != null && m_nodes.size() > 0)
                {
                    int nodeSize = m_nodes.size();
                    for (int i = 0; i < nodeSize; i++)
                    {
                        m_nodes.get(i).onRemovingNode();
                    }
                }
                m_tree.removeRow(row);
                row.clearCells();
                Row = null;
                ArrayList <FCGridRow> rows = m_tree.getRows();
                int rowSize = rows.size();
                for (int i = 0; i < rowSize; i++)
                {
                    rows.get(i).Index = i;
                }
                m_targetColumn = null;
            }
        }
Example #29
0
	// TODO checks
	public ParameterList(InputPacket packet)   {
		super(0);
		// array lists in which store parameters
		ArrayList parameters = new ArrayList();
		
		bool stop = false;
		do {
			// at least 4 bytes for length and type
			if (packet.getCursorPosition() + 4 <= packet.getLength()) {
				short parameterId = packet.read_short();
				short length = packet.read_short();
				byte[] p = new byte[length];
				if (parameterId != PID_SENTINEL) {
					for (int i=0; i<length; i++) {
						p[i] = packet.read_octet();
					}
					parameters.add(new Parameter(parameterId,length,p));
				}
				else {
					stop = true;
				}
			}
			else {
				throw  new MalformedSubmessageElementException("ParameterList too short");
			}
		} while (!stop);
		
		value = new Parameter[parameters.size()];
		parameters.toArray(value);
	}	
Example #30
0
 /// <summary>
 /// 绘制背景方法
 /// </summary>
 /// <param name="paint">绘图对象</param>
 /// <param name="clipRect">裁剪区域</param>
 public override void onPaintBackground(FCPaint paint, FCRect clipRect)
 {
     base.onPaintBackground(paint, clipRect);
     if (paint.supportTransparent())
     {
         ArrayList <FCView> controls = m_controls;
         int controlsSize            = controls.size();
         for (int i = 0; i < controlsSize; i++)
         {
             FCWindow window = controls.get(i) as FCWindow;
             if (window != null)
             {
                 long shadowColor = window.ShadowColor;
                 int  shadowSize  = window.ShadowSize;
                 if (shadowColor != FCColor.None && shadowSize > 0 && window.IsDialog && window.Frame == this)
                 {
                     FCRect bounds     = window.Bounds;
                     FCRect leftShadow = new FCRect(bounds.left - shadowSize, bounds.top - shadowSize, bounds.left, bounds.bottom + shadowSize);
                     paint.fillRect(shadowColor, leftShadow);
                     FCRect rightShadow = new FCRect(bounds.right, bounds.top - shadowSize, bounds.right + shadowSize, bounds.bottom + shadowSize);
                     paint.fillRect(shadowColor, rightShadow);
                     FCRect topShadow = new FCRect(bounds.left, bounds.top - shadowSize, bounds.right, bounds.top);
                     paint.fillRect(shadowColor, topShadow);
                     FCRect bottomShadow = new FCRect(bounds.left, bounds.bottom, bounds.right, bounds.bottom + shadowSize);
                     paint.fillRect(shadowColor, bottomShadow);
                     break;
                 }
             }
         }
     }
 }
Example #31
0
        /// <summary>
        /// 获取最后节点的索引
        /// </summary>
        /// <param name="nodes">节点</param>
        /// <returns>索引</returns>
        protected FCTreeNode getLastNode(ArrayList <FCTreeNode> nodes)
        {
            int size = nodes.size();

            if (size > 0)
            {
                for (int i = size - 1; i >= 0; i--)
                {
                    FCTreeNode lastNode = nodes.get(i);
                    if (lastNode.Row != null)
                    {
                        ArrayList <FCTreeNode> childNodes  = lastNode.getChildNodes();
                        FCTreeNode             subLastNode = getLastNode(childNodes);
                        if (subLastNode != null)
                        {
                            return(subLastNode);
                        }
                        else
                        {
                            return(lastNode);
                        }
                    }
                }
            }
            return(null);
        }
Example #32
0
 /// <summary>
 /// 触摸按下方法
 /// </summary>
 /// <param name="touchInfo">触摸信息</param>
 public override void onTouchDown(FCTouchInfo touchInfo)
 {
     base.onTouchDown(touchInfo);
     if (touchInfo.m_firstTouch && touchInfo.m_clicks == 1)
     {
         if (m_allowResize)
         {
             ArrayList <FCGridBand> bands = null;
             if (m_parentBand != null)
             {
                 bands = m_parentBand.getBands();
             }
             else
             {
                 bands = m_grid.getBands();
             }
             int bandsSize = bands.size();
             if (m_index > 0 && touchInfo.m_firstPoint.x < 5)
             {
                 m_resizeState = 1;
                 m_beginWidth  = bands[m_index - 1].Width;
             }
             else if ((m_parentBand == null || m_index < bandsSize - 1) && touchInfo.m_firstPoint.x > Width - 5)
             {
                 m_resizeState = 2;
                 m_beginWidth  = Width;
             }
             m_touchDownPoint = Native.TouchPoint;
         }
     }
 }
Example #33
0
        /// <summary>
        /// 获取所有的子表格列
        /// </summary>
        /// <returns>列头集合</returns>
        public ArrayList <FCBandedFCGridColumn> getAllChildColumns()
        {
            ArrayList <FCBandedFCGridColumn> columns = new ArrayList <FCBandedFCGridColumn>();
            int columnsSize = m_columns.size();

            for (int i = 0; i < columnsSize; i++)
            {
                FCBandedFCGridColumn column = m_columns.get(i);
                columns.add(column);
            }
            int bandsSize = m_bands.size();

            for (int i = 0; i < bandsSize; i++)
            {
                FCGridBand band = m_bands.get(i);
                ArrayList <FCBandedFCGridColumn> childColumns = band.getAllChildColumns();
                int childColumnsSize = childColumns.size();
                for (int j = 0; j < childColumnsSize; j++)
                {
                    FCBandedFCGridColumn childColumn = childColumns[j];
                    columns.add(childColumn);
                }
            }
            return(columns);
        }
	public void testComplexBoardSuccessorGenerator() {
		List<Action> actions = new ArrayList<Action>(af.actions(eightBoard));
		Assert.assertEquals(8, actions.size());
		NQueensBoard next = (NQueensBoard) rf
				.result(eightBoard, actions.get(0));
		Assert.assertEquals(1, next.getNumberOfQueensOnBoard());

		actions = new ArrayList<Action>(af.actions(next));
		Assert.assertEquals(6, actions.size());
	}
	public void testGenerateCorrectWhenGapMovedRightward() {
		board.moveGapLeft();// gives { 1, 2, 5, 3, 0, 4, 6, 7, 8 }
		Assert.assertEquals(new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4,
				6, 7, 8 }), board);

		List<Action> actions = new ArrayList<Action>(EightPuzzleFunctionFactory
				.getActionsFunction().actions(board));
		Assert.assertEquals(4, actions.size());

		EightPuzzleBoard expectedFourth = new EightPuzzleBoard(new int[] { 1,
				2, 5, 3, 4, 0, 6, 7, 8 });
		EightPuzzleBoard actualFourth = (EightPuzzleBoard) (EightPuzzleBoard) EightPuzzleFunctionFactory
				.getResultFunction().result(board, actions.get(3));
		Assert.assertEquals(expectedFourth, actualFourth);
		Assert.assertEquals(EightPuzzleBoard.RIGHT, actions.get(3));
	}
Example #36
0
 private void initFunctionsList()
 {
     Collection c = gui.Engine.AllFunctions;
     Function[] func = (Function[]) c.toArray(new Function[0]);
     List funcs = new ArrayList();
     bool larger = false;
     funcs.add(0, func[0]);
     for (int idx = 1; idx <= func.Length - 1; idx++)
     {
         int bound = funcs.size();
         larger = true;
         for (int indx = 0; indx < bound; indx++)
         {
             int cmpvalue = func[idx].Name.CompareTo(((Function) funcs.get(indx)).Name);
             if (cmpvalue < 0)
             {
                 funcs.add(indx, func[idx]);
                 indx = bound;
                 larger = false;
             }
             else if (cmpvalue == 0)
             {
                 indx = bound;
                 larger = false;
             }
         }
         if (larger)
         {
             funcs.add(func[idx]);
         }
     }
     dataModel.setFunctions(funcs);
     functionsTable.ColumnModel.getColumn(0).setPreferredWidth(50);
 }
Example #37
0
        //Function to cross all informations added to this face and evaluate the best values
        public void Evaluate()
        {
            //Evaluate mouth
            evaluatedMouth = new Rect(0, 0, 0, 0);
            //Random randomizer = new Random();

            //evaluatedMouth = mouths[randomizer.Next(0, mouths.Count - 1)];

            //must work a few on the mouth to choose the best one and proceed to histogram check for try to determinate skin color, eye color, hair color etc..

            foreach (Rect mouth in mouths)
            {
                if (mouth.y < face.y + face.height / 2)
                    continue;

                if (evaluatedMouth.width > mouth.width)
                    continue;

                evaluatedMouth = mouth;
            }

            //Evaluate eyes
            evaluatedEyes = new ArrayList<Rect>();
            ArrayList<Rect> rightCandidates = new ArrayList<Rect>();
            ArrayList<Rect> leftCandidates = new ArrayList<Rect>();

            foreach (Rect eye in eyes)
            {
                //Ensure the eyes are in the upper half of the img region
                if (eye.y + eye.height / 2 > face.y + face.height / 2)
                    continue;

                if (eye.x + eye.width / 2 < face.x + face.width / 2)
                    rightCandidates.add(eye);
                else
                    leftCandidates.add(eye);
            }

            //get centers for each side weighted by their areas
            int totalAreas = 0;
            int totalX = 0;
            int totalY = 0;

            if (rightCandidates.size() > 0)
            {
                foreach (Rect eye in rightCandidates)
                {
                    int eyeArea = eye.width * eye.height;
                    totalAreas += eyeArea;

                    totalX += (eye.x + eye.width / 2) * eyeArea;
                    totalY += (eye.y + eye.height / 2) * eyeArea;
                }

                Point rightPoint = new Point(totalX / totalAreas, totalY / totalAreas);

                int rightEyeSide = (int)Math.Sqrt((double)totalAreas / (double)rightCandidates.size());

                Rect rightEye = new Rect(
                    rightPoint.x - rightEyeSide / 2,
                    rightPoint.y - rightEyeSide / 2,
                    rightEyeSide,
                    rightEyeSide);

                //rightEye.Offset(-rightEye.Width / 2, -rightEye.Height / 2);

                evaluatedEyes.add(rightEye);
            }

            if (leftCandidates.size() > 0)
            {
                totalAreas = 0;
                totalX = 0;
                totalY = 0;

                foreach (Rect eye in leftCandidates)
                {
                    int eyeArea = eye.width * eye.height;
                    totalAreas += eyeArea;

                    totalX += (eye.x + eye.width / 2) * eyeArea;
                    totalY += (eye.y + eye.height / 2) * eyeArea;
                }

                Point leftPoint = new Point(totalX / totalAreas, totalY / totalAreas);

                int leftEyeSide = (int)Math.Sqrt((double)totalAreas / (double)leftCandidates.size());

                Rect leftEye = new Rect(
                    leftPoint.x - leftEyeSide / 2,
                    leftPoint.y - leftEyeSide / 2,
                    leftEyeSide,
                    leftEyeSide);

                //leftEye.Offset(-leftEye.Width / 2, -leftEye.Height / 2);

                evaluatedEyes.add(leftEye);
            }

            //Check if it is valid
            isValid = false;

            if (evaluatedEyes.size() > 2)
                throw new Exception("Eyes count must be equal or less than two");

            if (evaluatedEyes.size() == 2)
            {
                isValid = true;

                //Get the face line data

                Point eye1Center = new Point(evaluatedEyes.get(0).x + evaluatedEyes.get(0).width / 2,
                    evaluatedEyes.get(0).y + evaluatedEyes.get(0).height / 2);

                Point eye2Center = new Point(evaluatedEyes.get(1).x + evaluatedEyes.get(1).width / 2,
                    evaluatedEyes.get(1).y + evaluatedEyes.get(1).height / 2);

                int xOffset = (eye2Center.x - eye1Center.x) / 2;
                int yOffset = (eye2Center.y - eye1Center.y) / 2;

                Point eyeLineCenter = new Point(eye1Center.x + xOffset, eye1Center.y + yOffset);

                int zeroDivFac = eye1Center.x == eye2Center.x ? 1 : 0;

                //Generate face line slope and offset
                double aFact = (double)(eye1Center.y - eye2Center.y) /
                    (double)(eye1Center.x - eye2Center.x + zeroDivFac);

                aFact = Math.Atan(aFact) + Math.PI / 2;
                aFact = Math.Tan(aFact);

                double bFact = eyeLineCenter.y - aFact * eyeLineCenter.x;

                faceLineSlope = aFact;
                faceLineOffset = bFact;

                //If the mouth is invalid, project a new based on the face line
                if (evaluatedMouth.width == 0)
                {
                    PointGenerator faceLinePoint = new PointGenerator(aFact, bFact);

                    Point projMouthPos = faceLinePoint.GetFromY(face.y + face.height * 0.8);

                    evaluatedMouth = new Rect(
                        projMouthPos.x - (face.width / 3) / 2,
                        projMouthPos.y - (face.height / 5) / 2,
                        face.width / 3,
                        face.height / 5);

                    //evaluatedMouth.Offset(-evaluatedMouth.Width / 2, -evaluatedMouth.Height / 2);
                }
            }

            if (evaluatedEyes.size() == 1 && evaluatedMouth.width > 0)
            {
                isValid = true;

                //Project the other eye based on the mouth

                //Get the bottom mouth coords
                Point mouthBottomCenter = new Point(
                    evaluatedMouth.x + evaluatedMouth.width / 2,
                    evaluatedMouth.y + evaluatedMouth.height);

                //get the facetop coords
                Point faceTopCenter = new Point(face.width / 2 +
                    face.x, face.y);

                //Apply an experimental correct factor to the values
                int correctFact = mouthBottomCenter.x - faceTopCenter.x;
                //correctFact = (int)(correctFact * 0.5);

                mouthBottomCenter.x += correctFact;
                faceTopCenter.x -= correctFact;

                //Get the slope of the faceline

                //In case they are the same value, add a pixel to prevent division by 0
                int zeroDivFac = mouthBottomCenter.x == faceTopCenter.x ? 1 : 0;

                double a = (double)(mouthBottomCenter.y - faceTopCenter.y) /
                        (double)(mouthBottomCenter.x - faceTopCenter.x + zeroDivFac);

                //Get the offset of the face line
                double b = mouthBottomCenter.y - a * mouthBottomCenter.x;

                faceLineSlope = a;
                faceLineOffset = b;

                //Get the line function of the face
                PointGenerator faceLinePoint = new PointGenerator(a, b);

                //Get the reference of the existing eye and its center point
                Rect eyeRef = evaluatedEyes.get(0);
                Point eyeCenter = new Point(eyeRef.x + eyeRef.width / 2, eyeRef.y + eyeRef.height / 2);

                //Get the slope of the eye line (it must be normal to the face line, so we turn it Pi/2
                double aEyeFact = Math.Atan(a) + Math.PI / 2;
                aEyeFact = Math.Tan(aEyeFact);

                //Get the eye line offset
                double bEyeFact = eyeCenter.y - aEyeFact * eyeCenter.x;

                //Get the line function of the eye
                PointGenerator eyeLinePoint = new PointGenerator(aEyeFact, bEyeFact);

                //Get the horizontal difference between the center of the existing eye and the face line
                int diff = faceLinePoint.GetFromY(eyeCenter.y).x - eyeCenter.x;

                //Get the project eye coords
                Point projEyePoint = eyeLinePoint.GetFromX(eyeCenter.x + diff * 2);

                //Get the project eye rectangle
                Rect projEyeRect = new Rect(
                    projEyePoint.x - eyeRef.width / 2,
                    projEyePoint.y - eyeRef.height / 2,
                    eyeRef.width,
                    eyeRef.height);
                //projEyeRect.Offset(-eyeRef.Width / 2, -eyeRef.Height / 2);

                evaluatedEyes.add(projEyeRect);
            }

            //If the face keep invalid, put the face line on the middle of the face square
            if (!isValid)
            {
                faceLineSlope = -face.height / 0.01;
                faceLineOffset = face.y - faceLineSlope * face.x + face.width / 2;
            }
        }
Example #38
0
	//
	// PRIVATE METHODS
	//
	private void checkSuccessorList(ArrayList successorList,
			String playerToMove, int sizeOfSuccessors) {
		for (int i = 0; i < successorList.size(); i++) {
			GameState h = (GameState) successorList.get(i);

			ArrayList successors2 = new TicTacToe().getSuccessorStates(h);
			Assert.assertEquals(sizeOfSuccessors, successors2.size());
			Assert.assertEquals(playerToMove, new TicTacToe()
					.getPlayerToMove(h));
		}
	}
Example #39
0
	public void testRandomGeneration() {
		ArrayList<String> locations = new ArrayList<String>();
		locations.add("A");
		locations.add("B");
		locations.add("C");
		locations.add("D");
		locations.add("E");

		for (int i = 0; i < locations.size(); i++) {
			Assert.assertTrue(locations.contains(aMap
					.randomlyGenerateDestination()));
		}
	}
Example #40
0
 public override void clear()
 {
     ArrayList toRemove = new ArrayList();
     for (Iterator iter = backend.iterator(); iter.hasNext(); )
     {
         DcmElement el = (DcmElement) iter.next();
         if (filter(el.tag()))
         {
             toRemove.add(el);
         }
     }
      for (int i = 0, n = toRemove.size(); i < n; ++i)
     {
         backend.remove(((DcmElement) toRemove.get(i)).tag());
     }
 }
 public FileStatus[] listStatus(Path path) {
   path = path.makeQualified(this);
   List<FileStatus> result = new ArrayList<FileStatus>();
   String pathname = path.toString();
   String pathnameAsDir = pathname + "/";
   Set<String> dirs = new TreeSet<String>();
   for(MockFile file: files) {
     String filename = file.path.toString();
     if (pathname.equals(filename)) {
       return new FileStatus[]{createStatus(file)};
     } else if (filename.startsWith(pathnameAsDir)) {
       String tail = filename.substring(pathnameAsDir.length());
       int nextSlash = tail.indexOf('/');
       if (nextSlash > 0) {
         dirs.add(tail.substring(0, nextSlash));
       } else {
         result.add(createStatus(file));
       }
     }
   }
   // for each directory add it once
   for(String dir: dirs) {
     result.add(createDirectory(new MockPath(this, pathnameAsDir + dir)));
   }
   return result.toArray(new FileStatus[result.size()]);
 }
 public BlockLocation[] getFileBlockLocations(FileStatus stat,
                                              long start, long len) {
   List<BlockLocation> result = new ArrayList<BlockLocation>();
   for(MockFile file: files) {
     if (file.path.equals(stat.getPath())) {
       for(MockBlock block: file.blocks) {
         if (OrcInputFormat.SplitGenerator.getOverlap(block.offset,
             block.length, start, len) > 0) {
           String[] topology = new String[block.hosts.length];
           for(int i=0; i < topology.length; ++i) {
             topology[i] = "/rack/ " + block.hosts[i];
           }
           result.add(new BlockLocation(block.hosts, block.hosts,
               topology, block.offset, block.length));
         }
       }
       return result.toArray(new BlockLocation[result.size()]);
     }
   }
   return new BlockLocation[0];
 }