/// <summary>
        /// erzeugt einen WEKA-kompatiblen Datensatz
        /// </summary>
        /// <param name="classNames">Aufzählung der Klassennamen die im Datensatz verwendet werden sollen</param>
        /// <param name="featureNames">Namen der Merkmale</param>
        /// <param name="name">Name des Datensatzes</param>
        /// <param name="classAttributeName">>Name für das Klassenattribut</param>
        /// <returns></returns>
        public static Instances CreateInstances(IEnumerable <string> classNames, IEnumerable <string> featureNames, string name = "data", string classAttributeName = "class")
        {
            var features = new ArrayList();

            foreach (var featureName in featureNames)
            {
                var attribute = new Attribute(featureName);
                features.add(attribute);
            }
            Attribute classAttribute = null;

            if (null != classNames)
            {
                var classNamesList = new List <string>(classNames);
                classNamesList.Sort();
                var classValues = new ArrayList();
                foreach (var className in classNamesList)
                {
                    classValues.add(className);
                }
                classAttribute = new Attribute(classAttributeName, classValues);
                features.add(classAttribute);
            }
            var dataset = new Instances(name, features, 1);

            if (null != classAttribute)
            {
                dataset.setClass(classAttribute);
            }
            return(dataset);
        }
 /**
  * Adds a temp variable.
  */
 public void addTempVar(String name)
 {
     if (!_tempVarList.contains(name))
     {
         _tempVarList.add(name);
     }
 }
 protected void InitializeColumnInfoList()
 {
     _columnInfoList = new ArrayList <ColumnInfo>();
     _columnInfoList.add(Column職位コード);
     _columnInfoList.add(Column職位名称);
     _columnInfoList.add(Column職位英字名称);
 }
Example #4
0
        private int buildTests()
        {
            System.out.println();
            System.out.println("Tests");
            System.out.println("--------------------------");

            var args = new ArrayList <string>();

            args.add("-al:bin/stabal.jar");
            args.add("-cp:bin/stabrt.jar;bin/junit-4.8.1.jar;bin/asm-3.3.jar;compiler/stabc.jar");
            args.add("-out:tests/tests.jar");
            addSourceFiles(new File("tests/sources"), args);

            int code = Compiler.runWith(args);

            if (code == 0)
            {
                System.out.println();
                System.out.println("Tests Launcher");
                args = new ArrayList <string>();
                args.add("-al:bin/stabal.jar");
                args.add("-cp:bin/stabrt.jar;bin/junit-4.8.1.jar");
                args.add("-manifest:tools/tests/MANIFEST.MF");
                args.add("-out:bin/tests.jar");
                addSourceFiles(new File("tools/tests"), args);

                code = Compiler.runWith(args);
            }
            return(code);
        }
Example #5
0
        private void BotonRandom_Click(object sender, EventArgs e)
        {
            var    keypadArrayList = new ArrayList();
            Random rnd             = new Random();

            keypadArrayList.add(0);
            keypadArrayList.add(1);
            keypadArrayList.add(2);
            keypadArrayList.add(3);
            keypadArrayList.add(4);
            keypadArrayList.add(5);
            keypadArrayList.add(6);
            keypadArrayList.add(7);
            keypadArrayList.add(8);
            keypadArrayList.add(9);


            for (int i = 0; i < keypadArrayList.Lenght; i++)
            {
                for (int i = array.Length - 1; i > 0; i--)
                {
                    int j = rnd.Next(i);
                    int k = array[j];
                    array[j]     = array[i - 1];
                    array[i - 1] = k;
                }
            }
        }
Example #6
0
        /**
         * Convenience method to get the positions defined by either {@code LatLonBox} or {@code gx:LatLonQuad}. If the
         * overlay includes a {@code LatLonBox} element, this method returns the corners of the sector defined by the {@code
         * LatLonBox}. Otherwise, if the overlay contains a {@code gx:LatLonQuad}, this method returns the positions defined
         * by the quad.
         *
         * @return A list of the positions that define the corner points of the overlay.
         */
        public Position.PositionList getPositions()
        {
            double altitude = this.getAltitude() != null?this.getAltitude() : 0.0;

            // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad
            List <Position> corners = new ArrayList <Position>(4);
            KMLLatLonBox    box     = this.getLatLonBox();

            if (box != null)
            {
                Sector sector = KMLUtil.createSectorFromLatLonBox(box);
                foreach (LatLon ll in sector.getCorners())
                {
                    corners.add(new Position(ll, altitude));
                }
            }
            else
            {
                GXLatLongQuad latLonQuad = this.getLatLonQuad();
                if (latLonQuad != null && latLonQuad.getCoordinates() != null)
                {
                    foreach (Position position in latLonQuad.getCoordinates().list)
                    {
                        corners.add(new Position(position, altitude));
                    }
                }
            }

            return(new Position.PositionList(corners));
        }
Example #7
0
        static void Main(String[] args)
        {
            ArrayList al = new ArrayList();//ArrayList () is a default construtor . that collection interface have been provided

            //There is one more constructor that is avaliable with parameter i.e ArrayList(Initial Capacity)
            //Ex:- ArrayList al=new ArrayList(20); Where we can spesify initial size of an arraylist.
            Console.WriteLine(al.Capacity);
            //Internally there wont be any size for this array list .So Lets try to insert few elements and see the size.
            al.add(10);
            Console.WriteLine(al.Capacity);
            //Now if we check the size of arrayList we will find the value 4 so we can store 3 more Items into ArrayList.
            al.add(20);
            al.add(30);
            al.add(40);
            //Now If we try to add one more element into the arrayList
            al.add(50);
            Console.WriteLine(al.Capacity);
            //Now the capacity will be 8

            foreach (Object obj in al)
            {
                Console.WriteLine(obj);
            }
            //Now if we want to Insert a value in the middle of an arraylist, We can use Insert method it takes two parameters (index and value)

            al.Insert(3, 60);

            //Now if we want to remove an Item in the middle of an arraylist , we can use Remove mthod takes the parameter as value what we want to remove.

            al.Remove(30);
            //We can remove the value based on the index position also
            al.Remove(2);
            al.RemoveAt(30);
        }
Example #8
0
    public void givenAListWith3Elements_whenInsertAtBeginningBefore_thenElementIsInsertedIncorrectReference()
    {
        // Given:
        ArrayList <Student> arrayList = new ArrayList <Student>();
        Student             reference = new Student("Ivan");

        try
        {
            arrayList.add(new Student("Edilberto"));
            arrayList.add(new Student("Israel"));
            arrayList.add(new Student("Francisco"));

            // When:
            arrayList.insert(reference, new Student("Lupita"), ArrayList <Student> .InsertPosition.BEFORE);
        }
        catch (NullReferenceException) { }


        // Then:
        Assert.Equal(3, arrayList.size());
        Assert.Equal(arrayList.getAt(0).getName(), "Edilberto");
        Assert.Equal(arrayList.getAt(1).getName(), "Israel");
        Assert.Equal(arrayList.getAt(2).getName(), "Francisco");
        Assert.Throws <NullReferenceException>(() => arrayList.insert(reference, new Student("Lupita"), ArrayList <Student> .InsertPosition.BEFORE));
    }
Example #9
0
 /// <summary> Copy constructor (deep)
 ///
 /// </summary>
 /// <param name="data">
 /// </param>
 public GeoShapeData(GeoShapeData data)
 {
     for (GeoPointData p: data.points)
     {
         points.add(new GeoPointData(p));
     }
 }
Example #10
0
        private object[] compile(string text)
        {
            if (text == null)
            {
                return(new object[0]);
            }
            ArrayList       arrayList       = new ArrayList();
            StringTokenizer stringTokenizer = new StringTokenizer(text, ":.");

            while (stringTokenizer.hasMoreTokens())
            {
                string text2    = stringTokenizer.nextToken();
                OpEnum instance = OpEnum.getInstance(text2);
                if (instance == null)
                {
                    string text3 = new StringBuilder().append("Bad path compiled ").append(text).toString();

                    throw new Error(text3);
                }
                arrayList.add(instance);
                if (instance == OpEnum.RELATION)
                {
                    arrayList.add(stringTokenizer.nextToken());
                }
            }
            return(arrayList.toArray());
        }
Example #11
0
        /// <summary>
        /// Función encargada de encriptar los datos del usuario
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public ArrayList encryptOutlook(string password)
        {
            string    semilla     = "0uTl@k";
            string    marcaTiempo = "";
            ArrayList resultado   = new ArrayList();
            string    encriptado  = "";

            try
            {
                // do
                // {
                byte[]          iv     = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                IvParameterSpec ivspec = new IvParameterSpec(iv);
                marcaTiempo = (new SimpleDateFormat("ddMMyyyyHHmmss")).format(new Date());

                KeySpec       clave = new PBEKeySpec(marcaTiempo.ToCharArray(), Encoding.Default.GetBytes(semilla), 65536, 256);
                SecretKey     hash  = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(clave);
                SecretKeySpec key   = new SecretKeySpec(hash.getEncoded(), "AES");

                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                cipher.init(Cipher.ENCRYPT_MODE, key, ivspec);
                encriptado = Base64.getEncoder().encodeToString(cipher.doFinal(Encoding.UTF8.GetBytes(password)));
                resultado.add(encriptado);
                resultado.add(marcaTiempo);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error en la encriptacion: " + e.ToString());
                resultado = new ArrayList();
            }
            return(resultado);
        }
Example #12
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);
        }
Example #13
0
 void enterMethod(MethodBuilder methodBuilder)
 {
     context.MemberResolver.enterMethod(methodBuilder);
     this.IsStatic = methodBuilder.IsStatic;
     methods.add(methodBuilder);
     this.YieldCount = 0;
 }
 protected void InitializeColumnInfoList()
 {
     _columnInfoList = new ArrayList <ColumnInfo>();
     _columnInfoList.add(Columnメニューコード);
     _columnInfoList.add(Columnメニュー名称);
     _columnInfoList.add(Column優先順位);
 }
Example #15
0
        public void addShapelessRecipe(ItemStack itemstack, object[] aobj)
        {
            var arraylist = new ArrayList();

            object[] aobj1 = aobj;
            int      i     = aobj1.Length;

            for (int j = 0; j < i; j++)
            {
                object obj = aobj1[j];
                if (obj is ItemStack)
                {
                    arraylist.add(((ItemStack)obj).copy());
                    continue;
                }
                if (obj is Item)
                {
                    arraylist.add(new ItemStack((Item)obj));
                    continue;
                }
                if (obj is Block)
                {
                    arraylist.add(new ItemStack((Block)obj));
                }
                else
                {
                    throw new RuntimeException("Invalid shapeless recipy!");
                }
            }

            recipes.add(new ShapelessRecipes(itemstack, arraylist));
        }
        /**
         * Reads in translated plurals forms that are separated by NULL.
         */
        private ArrayList <StringValue> readPluralForms(int length)

        {
            ArrayList <StringValue> list = new ArrayList <StringValue>();
            StringValue             sb   = new UnicodeBuilderValue();

            for (; length > 0; length--)
            {
                int ch = _in.readChar();

                if (ch > 0)
                {
                    sb.append((char)ch);
                }

                else if (ch == 0)
                {
                    list.add(sb);
                    sb = new UnicodeBuilderValue();
                }
                else
                {
                    break;
                }
            }

            list.add(sb);
            return(list);
        }
Example #17
0
        private static List getNextGrammarNodesWithWords(GrammarNode grammarNode)
        {
            ArrayList arrayList = new ArrayList();

            GrammarArc[] successors = grammarNode.getSuccessors();
            int          num        = successors.Length;

            for (int i = 0; i < num; i++)
            {
                GrammarArc  grammarArc   = successors[i];
                GrammarNode grammarNode2 = grammarArc.getGrammarNode();
                if (grammarNode2.getAlternatives().Length == 0)
                {
                    if (grammarNode2.isFinalNode())
                    {
                        arrayList.add(grammarNode2);
                    }
                    else
                    {
                        arrayList.addAll(GrammarPoint.getNextGrammarNodesWithWords(grammarNode2));
                    }
                }
                else
                {
                    arrayList.add(grammarNode2);
                }
            }
            return(arrayList);
        }
Example #18
0
        /**
         * 一个最长分词器
         *
         * @param text 待分词文本
         * @return
         */
        public Collection <Token> tokenize(String text)
        {
            Collection <Token> tokens = new ArrayList <Token>();

            Collection <Emit> collectedEmits = parseText(text);
            // 下面是最长分词的关键
            IntervalTree intervalTree = new IntervalTree((List <Intervalable>)(List <?>) collectedEmits);

            intervalTree.removeOverlaps((List <Intervalable>)(List <?>) collectedEmits);
            // 移除结束

            int lastCollectedPosition = -1;

            for (Emit emit : collectedEmits)
            {
                if (emit.getStart() - lastCollectedPosition > 1)
                {
                    tokens.add(createFragment(emit, text, lastCollectedPosition));
                }
                tokens.add(createMatch(emit, text));
                lastCollectedPosition = emit.getEnd();
            }
            if (text.length() - lastCollectedPosition > 1)
            {
                tokens.add(createFragment(null, text, lastCollectedPosition));
            }

            return(tokens);
        }
Example #19
0
 protected void InitializeColumnInfoList()
 {
     _columnInfoList = new ArrayList <ColumnInfo>();
     _columnInfoList.add(Column客室利用台帳id);
     _columnInfoList.add(Column会員コード);
     _columnInfoList.add(Column宿泊料金);
 }
        public virtual ArrayList getSpeakerIntervals()
        {
            Iterator iterator = this.segmentSet.iterator();

            new Segment(0, 0);
            Segment segment = (Segment)iterator.next();

            segment.getStartTime();
            segment.getLength();
            int       num       = 0;
            ArrayList arrayList = new ArrayList();

            arrayList.add(segment);
            while (iterator.hasNext())
            {
                Segment segment2  = (Segment)iterator.next();
                int     startTime = ((Segment)arrayList.get(num)).getStartTime();
                int     length    = ((Segment)arrayList.get(num)).getLength();
                if (startTime + length == segment2.getStartTime())
                {
                    arrayList.set(num, new Segment(startTime, length + segment2.getLength()));
                }
                else
                {
                    num++;
                    arrayList.add(segment2);
                }
            }
            return(arrayList);
        }
Example #21
0
        private List getNextGrammarPoints(bool flag)
        {
            ArrayList arrayList = new ArrayList();

            if (this.alternativeIndex == -1 && this.node.getAlternatives().Length > 0)
            {
                for (int i = 0; i < this.node.getAlternatives().Length; i++)
                {
                    GrammarPoint grammarPoint = new GrammarPoint(this.node, i, 0, 0, 0);
                    arrayList.add(grammarPoint);
                }
            }
            else if (this.node.getAlternatives().Length == 0)
            {
                GrammarPoint.addNextGrammarPointsWithWords(this.node, arrayList);
            }
            else
            {
                GrammarPoint grammarPoint2;
                if (flag)
                {
                    grammarPoint2 = this;
                }
                else
                {
                    grammarPoint2 = new GrammarPoint(this.node, this.alternativeIndex, this.wordIndex, this.pronunciationIndex, this.unitIndex + 1);
                }
                Pronunciation[] pronunciations = this.node.getAlternatives()[this.alternativeIndex][this.wordIndex].getPronunciations();
                int             num            = pronunciations[this.pronunciationIndex].getUnits().Length;
                if (grammarPoint2.unitIndex < num)
                {
                    arrayList.add(grammarPoint2);
                }
                else
                {
                    grammarPoint2.unitIndex = 0;
                    Word[]       array         = grammarPoint2.node.getAlternatives()[this.alternativeIndex];
                    GrammarPoint grammarPoint3 = grammarPoint2;
                    int          num2          = grammarPoint3.wordIndex + 1;
                    GrammarPoint grammarPoint4 = grammarPoint3;
                    int          num3          = num2;
                    grammarPoint4.wordIndex = num2;
                    if (num3 < array.Length)
                    {
                        Word word = array[grammarPoint2.wordIndex];
                        for (int j = 0; j < word.getPronunciations().Length; j++)
                        {
                            GrammarPoint grammarPoint5 = new GrammarPoint(grammarPoint2.node, grammarPoint2.alternativeIndex, grammarPoint2.wordIndex, j, 0);
                            arrayList.add(grammarPoint5);
                        }
                    }
                    else if (!GrammarPoint.bounded)
                    {
                        GrammarPoint.addNextGrammarPointsWithWords(grammarPoint2.node, arrayList);
                    }
                }
            }
            return(arrayList);
        }
Example #22
0
        private List <TypeSignature> parseFormalTypeParameters()
        {
            if (current != '<')
            {
                throw new IllegalStateException();
            }
            advance();
            var result = new ArrayList <TypeSignature>();
            int pos    = position;
            FormalTypeParameterSignature currentParameterType = null;

            for (;;)
            {
                switch (current)
                {
                case ':':
                    if (position == pos && currentParameterType == null)
                    {
                        throw new IllegalStateException();
                    }
                    if (currentParameterType == null)
                    {
                        var name = signature.substring(pos, position);
                        currentParameterType = new FormalTypeParameterSignature(name);
                        result.add(currentParameterType);
                    }
                    switch (advance())
                    {
                    case ':':
                    case '>':
                        break;

                    default:
                        currentParameterType.formalTypeParameterBounds.add(parseFieldTypeSignature());
                        pos = position;
                        break;
                    }
                    break;

                case '>':
                    if (currentParameterType == null)
                    {
                        var name = signature.substring(pos, position);
                        currentParameterType = new FormalTypeParameterSignature(name);
                        result.add(currentParameterType);
                    }
                    advance();
                    return(result);

                default:
                    currentParameterType = null;
                    advance();
                    break;

                case -1:
                    throw new IllegalStateException();
                }
            }
        }
Example #23
0
 public static void Main()
 {
     ArrayList list = new ArrayList();
     list.add(new MyClass(10,"sdg"));
     list.add(new MyClass(13,"uy,k"));
     list.add(new MyClass(14,"tho"));
     list.sort();
 }
Example #24
0
 /// <summary>
 /// 添加单元格
 /// </summary>
 /// <param name="column">列索引</param>
 /// <param name="cell">单元格</param>
 public void addCell(FCGridColumn column, FCGridCell cell)
 {
     cell.Grid   = m_grid;
     cell.Column = column;
     cell.Row    = this;
     m_cells.add(cell);
     cell.onAdd();
 }
Example #25
0
        /**
         * Returns the short names for the scripts for the engine,
         * e.g. {"javascript", "rhino"}
         */
        public List <String> getNames()
        {
            ArrayList <String> names = new ArrayList <String>();

            names.add("quercus");
            names.add("php");
            return(names);
        }
Example #26
0
        /// <summary>
        /// 获取属性名称列表
        /// </summary>
        /// <returns>属性名称列表</returns>
        public override ArrayList <String> getPropertyNames()
        {
            ArrayList <String> propertyNames = base.getPropertyNames();

            propertyNames.add("ColumnsCount");
            propertyNames.add("RowsCount");
            return(propertyNames);
        }
Example #27
0
        /// <summary>
        /// 获取属性名称列表
        /// </summary>
        /// <returns>属性名称列表</returns>
        public virtual ArrayList <String> getPropertyNames()
        {
            ArrayList <String> propertyNames = new ArrayList <String>();

            propertyNames.add("SizeType");
            propertyNames.add("Height");
            return(propertyNames);
        }
Example #28
0
        /// <summary>
        /// 获取属性名称列表
        /// </summary>
        /// <returns>属性名称列表</returns>
        public override ArrayList <String> getPropertyNames()
        {
            ArrayList <String> propertyNames = base.getPropertyNames();

            propertyNames.add("CustomFormat");
            propertyNames.add("ShowTime");
            return(propertyNames);
        }
Example #29
0
        /// <summary>
        /// 获取属性名称列表
        /// </summary>
        /// <returns>属性名称列表</returns>
        public override ArrayList <String> getPropertyNames()
        {
            ArrayList <String> propertyNames = base.getPropertyNames();

            propertyNames.add("SeletedDay");
            propertyNames.add("UseAnimation");
            return(propertyNames);
        }
Example #30
0
    public ArrayList <string> getInfo()
    {
        ArrayList provider = new ArrayList <string>();

        provider.add(this.id.toString());
        provider.add(this.sname);
        provider.add(this.type.sname());
        return(provider);
    }
 protected void InitializeColumnInfoList()
 {
     _columnInfoList = new ArrayList <ColumnInfo>();
     _columnInfoList.add(Column客室コード);
     _columnInfoList.add(Column客室番号);
     _columnInfoList.add(Column客室タイプコード);
     _columnInfoList.add(Column喫煙);
     _columnInfoList.add(Column備考);
 }
	public static string test() {
		var list = new ArrayList<string>();
		list.add("a");
		list.add("b");
		list.add("c");
		
		var sb = new StringBuilder();
		foreach (var s in list) {
			sb.append(s);
		}
		
		return sb.toString();
	}
Example #33
0
        static void Main(string[] args)
        {
            Vehicle vCar = new Car("Diesel","Fiat","600");
			Vehicle vMoto = new Motorbike("1500","Ducatti","1500");
			Vehicle vBoat = new Boat("10000","Vasque","3",3);
			
			ArrayList Vehicles = new ArrayList();
			Vehicles.add(vCar);
			Vehicles.add(vMoto);
			Vehicles.add(vBoat);
			
			list(Vehicles);
			
		}
    static void Main()
    {
        /*int firstNum = int.Parse(Console.ReadLine());
        float secondNum = float.Parse(Console.ReadLine());
        float thirdNum = float.Parse(Console.ReadLine());

        string hexOutput = String.Format("{0:X}", firstNum);
        string formattedText = "{0, -1} | {1, 10} | {2, 10:0.00} | {3, -1:0.000} |";

        if (firstNum >= 0 && firstNum <= 500)
        {
            Console.WriteLine(formattedText, hexOutput, Convert.ToString(firstNum, 2), secondNum, thirdNum);
        }
        else
        {
            Console.WriteLine("First number should be >= 0 and <= 500!");
            return;
        }*/
        int[] test = { 10212, 10202, 11000, 11000, 11010 };
        ArrayList<Integer> test2 = new ArrayList<Integer>();


        for (int i = test.length - 1; i >= 0; i--)
        {
            int temp = test[i];
            while (temp > 0)
            {
                test2.add(0, temp % 10);  //place low order digit in array
                temp = temp / 10;        //remove low order digit from temp;
            }
        }
    }
 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 #36
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 #37
0
 //$goals 18
 //$benchmark
 public void addTest(ArrayList arrayList, Object o)
 {
     if (arrayList != null) {
         {/*$goal 0 reachable*/}
         boolean ret_val = arrayList.add(o);
     } else {
         {/*$goal 1 reachable*/}
     }
 }
Example #38
0
        public void EnumerableTest()
        {
            const string expectedStringBase = "str1ng";

            var list = new ArrayList<String>();
            list.add(expectedStringBase + "0");
            list.add(expectedStringBase + "1");
            list.add(expectedStringBase + "2");

            var currentIndex = -1;
            foreach (var item in list)
            {
                currentIndex++;
                Assert.AreEqual(expectedStringBase + currentIndex, (string)item);
            }

            Assert.AreEqual(2, currentIndex);
        }
	public void testGetPositions() {
		List<XYLocation> expected = new ArrayList<XYLocation>();
		expected.add(new XYLocation(0, 2));
		expected.add(new XYLocation(1, 1));
		expected.add(new XYLocation(2, 2));
		expected.add(new XYLocation(2, 1));
		expected.add(new XYLocation(0, 1));
		expected.add(new XYLocation(0, 0));
		expected.add(new XYLocation(1, 0));
		expected.add(new XYLocation(2, 0));
		expected.add(new XYLocation(1, 2));

		List<XYLocation> actual = board.getPositions();
		Assert.assertEquals(expected, actual);
	}
	public void testSuccessors() {
		ArrayList<String> locations = new ArrayList<String>();

		// A
		locations.clear();
		locations.add("B");
		locations.add("C");
		for (Action a : af.actions("A")) {
			Assert.assertTrue(locations.contains(((MoveToAction) a)
					.getToLocation()));
			Assert.assertTrue(locations.contains(rf.result("A", a)));
		}

		// B
		locations.clear();
		locations.add("A");
		locations.add("C");
		locations.add("E");
		for (Action a : af.actions("B")) {
			Assert.assertTrue(locations.contains(((MoveToAction) a)
					.getToLocation()));
			Assert.assertTrue(locations.contains(rf.result("B", a)));
		}

		// C
		locations.clear();
		locations.add("A");
		locations.add("B");
		locations.add("D");
		for (Action a : af.actions("C")) {
			Assert.assertTrue(locations.contains(((MoveToAction) a)
					.getToLocation()));
			Assert.assertTrue(locations.contains(rf.result("C", a)));
		}

		// D
		locations.clear();
		locations.add("C");
		for (Action a : af.actions("D")) {
			Assert.assertTrue(locations.contains(((MoveToAction) a)
					.getToLocation()));
			Assert.assertTrue(locations.contains(rf.result("D", a)));
		}
		// E
		locations.clear();
		Assert.assertTrue(0 == af.actions("E").size());
	}
	public void testSetBoard() {
		List<XYLocation> passedIn = new ArrayList<XYLocation>();
		passedIn.add(new XYLocation(1, 1));
		passedIn.add(new XYLocation(0, 2));
		passedIn.add(new XYLocation(2, 2));
		passedIn.add(new XYLocation(2, 1));
		passedIn.add(new XYLocation(0, 1));
		passedIn.add(new XYLocation(0, 0));
		passedIn.add(new XYLocation(1, 0));
		passedIn.add(new XYLocation(2, 0));
		passedIn.add(new XYLocation(1, 2));
		board.setBoard(passedIn);
		Assert.assertEquals(new XYLocation(1, 1), board.getLocationOf(0));
		Assert.assertEquals(new XYLocation(0, 2), board.getLocationOf(1));
	}
Example #42
0
	public void testLocationsLinkedTo() {
		ArrayList<String> locations = new ArrayList<String>();
		List<String> linkedTo;

		linkedTo = aMap.getLocationsLinkedTo("A");
		locations.clear();
		locations.add("B");
		locations.add("C");
		Assert.assertTrue(locations.containsAll(linkedTo)
				&& linkedTo.size() == 2);

		linkedTo = aMap.getLocationsLinkedTo("B");
		locations.clear();
		locations.add("A");
		locations.add("C");
		locations.add("E");
		Assert.assertTrue(locations.containsAll(linkedTo)
				&& linkedTo.size() == 3);

		linkedTo = aMap.getLocationsLinkedTo("C");
		locations.clear();
		locations.add("A");
		locations.add("B");
		locations.add("D");
		Assert.assertTrue(locations.containsAll(linkedTo)
				&& linkedTo.size() == 3);

		linkedTo = aMap.getLocationsLinkedTo("D");
		locations.clear();
		locations.add("C");
		Assert.assertTrue(locations.containsAll(linkedTo)
				&& linkedTo.size() == 1);

		linkedTo = aMap.getLocationsLinkedTo("E");
		Assert.assertTrue(linkedTo.size() == 0);
	}
Example #43
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 #44
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 #45
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 #46
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];
 }
Example #49
0
        public ArrayList<PersonFace> Detect(Mat image)
        {
            ArrayList<PersonFace> personFaces = new ArrayList<PersonFace>();

            using (UMat ugray = new UMat())
            {
                CvInvoke.CvtColor(image, ugray, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);

                //normalizes brightness and increases contrast of the image
                CvInvoke.EqualizeHist(ugray, ugray);

                foreach (CascadeClassifier faceCascade in frontFaceCascades)
                {
                    Rect[] detectedFaces = faceCascade.detectMultiScale(ugray, 1.1, 3, 0, new Size(20, 20));

                    //faces.AddRange(detectedFaces);

                    foreach (Rect face in detectedFaces)
                    {
                        PersonFace personFace = new PersonFace(face);

                        personFaces.add(personFace);

                        //personFace.FaceRect = face;

                        //Get the region of interest on the faces

                        using (UMat faceRegion = new UMat(ugray, new System.Drawing.Rectangle(
                            face.x,
                            face.y,
                            face.width,
                            face.height)))
                        {
                            //Detect eyes
                            foreach (CascadeClassifier eyeCascade in eyesCascades)
                            {
                                Rect[] detectedEyes = eyeCascade.detectMultiScale(
                                    faceRegion,
                                    1.1,
                                    3,
                                    0,
                                    new Size(10, 10));

                                //List<Rectangle> eyes = new List<Rectangle>();

                                foreach (Rect eye in detectedEyes)
                                {
                                    //Ensure the eyes are in the upper half of the img region
                                    //if (eye.Y + eye.Height > faceRegion.Size.Height / 2)
                                    //continue;

                                    //eye.Offset(face.X, face.Y);
                                    personFace.AddEye(new Rect(eye.x + face.x, eye.y + face.y,
                                        eye.width, eye.height));
                                    //eyes.Add(eye);
                                }

                                //personFace.EyesRects = eyes.ToArray();

                            }

                            //Detect mouths
                            foreach (CascadeClassifier mouthCascade in mouthsCascades)
                            {
                                /*UMat mouthRegion = new UMat(ugray, new Rectangle(
                                     face.X,
                                     face.Y + face.Height / 2,
                                     face.Width,
                                     face.Height/2));*/

                                Rect[] detectedMouths = mouthCascade.detectMultiScale(
                                    faceRegion,
                                    1.1,
                                    3,
                                    0,
                                    new Size(25, 15));

                                foreach (Rect mouth in detectedMouths)
                                {
                                    //mouth.Offset(face.X, face.Y);
                                    //personFace.AddMouth(mouth);
                                    personFace.AddMouth(new Rect(mouth.x + face.x, mouth.y + face.y,
                                        mouth.width, mouth.height));
                                }
                            }

                            //Detect noses
                            ArrayList<Rect> noses = new ArrayList<Rect>();
                            foreach (CascadeClassifier noseCascade in nosesCascades)
                            {
                                Rect[] detectedNoses = noseCascade.detectMultiScale(
                                    faceRegion,
                                    1.1,
                                    10,
                                    0,
                                    new Size(25, 15));

                                foreach (Rect nose in detectedNoses)
                                {
                                    //nose.Offset(face.X, face.Y);
                                    noses.add(new Rect(nose.x + face.x, nose.y + face.y,
                                        nose.width, nose.height));
                                }

                            }

                            //personFace.NoseRects = noses.ToArray();

                        }
                    }

                }

            }

            return personFaces;
        }
Example #50
0
		/**
     * Returns an unmodifiable copy of the {@link Item Items} in the roster packet.
     *
     * @return an unmodifable copy of the {@link Item Items} in the roster packet.
     */
		public Collection<Item> getItems() {
			Collection<Item> items = new ArrayList<Item>();
            XElement query = element.Element(XName.Get("query", "jabber:iq:roster"));
			if (query != null) {
				for (Iterator<XElement> i=query.elementIterator("item"); i.hasNext(); ) {
					Element item = i.next();
					String jid = item.attributeValue("jid");
					String name = item.attributeValue("name");
					String ask = item.attributeValue("ask");
					String subscription = item.attributeValue("subscription");
					Collection<String> groups = new ArrayList<String>();
					for (Iterator<Element> j=item.elementIterator("group"); j.hasNext(); ) {
						Element group = j.next();
						groups.add(group.getText().trim());
					}
					Ask askStatus = ask == null ? null : Ask.valueOf(ask);
					Subscription subStatus = subscription == null ?
						null : Subscription.valueOf(subscription);
					items.add(new Item(new JID(jid), name, askStatus, subStatus, groups));
				}
			}
			return Collections.unmodifiableCollection(items);
		}
 private List<String> getTypeParameterNames(List<SimpleNameTypeReferenceNode> typeParameters) {
     if (typeParameters.size() > 0) {
         var result = new ArrayList<String>();
         foreach (var t in typeParameters) {
             var name = context.getIdentifier(t.NameOffset, t.NameLength);
             result.add(name);
         }
         return result;
     }
     return Collections.emptyList();
 }
 private MethodBuilder lookupMethod(TypeBuilder typeBuilder, List<SimpleNameTypeReferenceNode> typeParameters,
         List<ParameterNode> parameters, String name) {
     var typeParams = getTypeParameterNames(typeParameters);
     foreach (var meth in typeBuilder.Methods) {
         if (!isCompatible(meth, name, typeParams, parameters)) {
             continue;
         }
         context.MemberResolver.enterMethod(meth);
         int i = 0;
         var paramTypes = new ArrayList<TypeInfo>();
         try {
             foreach (var p in parameters) {
                 var t = CompilerHelper.resolveTypeReference(context, typeBuilder.PackageName, p.Type, false, true);
                 if (t == null) {
                     break;
                 }
                 paramTypes.add(t);
                 i++;
             }
         } finally {
             context.MemberResolver.leaveMethod();
         }
         if (i < typeParams.size()) {
             continue;
         }
         var methodBuilder = (MethodBuilder)typeBuilder.getMethod(name, paramTypes);
         if (methodBuilder != null) {
             return methodBuilder;
         }
     }
     return null;
 }