xhtml.startElement("ul"); xhtml.newline(); for (MLArray element : mlStructure.getAllFields()){ xhtml.startElement("li"); xhtml.characters(String.valueOf(element));
private MLStructure generatorsDataAsMLStructure(ArrayList<GeneratorData> generatorsData) { MLStructure generators = null; generators = new MLStructure("generatore", new int[]{1, generatorsData.size()}); int i = 0; for (GeneratorData generatorData : generatorsData) { putGeneratorDataIntoMLStructure(generatorData, generators, i); i++; } return generators; }
public String contentToString() { StringBuffer sb = new StringBuffer(); sb.append(name + " = \n"); if ( getM()*getN() == 1 ) { for ( String key : keys ) { sb.append("\t" + key + " : " + getField(key) + "\n" ); } } else { sb.append("\n"); sb.append(getM() + "x" + getN() ); sb.append(" struct array with fields: \n"); for ( String key : keys) { sb.append("\t" + key + "\n"); } } return sb.toString(); }
/** * Gets a value of the field described by name from (m,n)'th struct * in struct array or null if the field doesn't exist. * * @param name name * @param m m * @param n n * @return value of the field */ public MLArray getField(String name, int m, int n) { return getField(name, getIndex(m,n) ); } /**
MLStructure struct = new MLStructure(name, dims, type, attributes); for ( int index = 0; index < struct.getM()*struct.getN(); index++ ) struct.setField(fieldNames[i], fieldValue, index); struct.setField(fieldNames[i], new MLEmptyArray(), index); struct = new MLStructure(name, dims, type, attributes); struct.setField( fieldNames[i], fieldValue, index ); struct.setField(fieldNames[i], new MLEmptyArray(), index);
dos.writeInt( ((MLStructure)array).getMaxFieldLenth() ); tag = new OSArrayTag(MatDataTypes.miINT8, ((MLStructure)array).getKeySetToByteArray() ); tag.writeTo( dos ); for ( MLArray a : ((MLStructure)array).getAllFields() )
MLChar mlChar = new MLChar(null, "I am dummy"); MLStructure mlStruct = new MLStructure("str", new int[]{1, 1}); mlStruct.setField("f1", mlDouble); mlStruct.setField("f2", mlChar); MLStructure mlArrayRetrived = (MLStructure) mfr.getMLArray("str"); assertEquals(mlDouble, mlArrayRetrived.getField("f1")); assertEquals(mlChar, mlArrayRetrived.getField("f2"));
/** * Gets a value of the field described by name from current structe * in struc array. * * @param name * @return */ public MLArray getField(String name) { return getField(name, currentIndex); } /**
@Test public void testMLStructureFieldNames() throws IOException { // test column-packed vector double[] src = new double[]{1.3, 2.0, 3.0, 4.0, 5.0, 6.0}; // create 3x2 double matrix // [ 1.0 4.0 ; // 2.0 5.0 ; // 3.0 6.0 ] MLDouble mlDouble = new MLDouble(null, src, 3); MLChar mlChar = new MLChar(null, "I am dummy"); MLStructure mlStruct = new MLStructure("str", new int[]{1, 1}); mlStruct.setField("f1", mlDouble); mlStruct.setField("f2", mlChar); Collection<String> fieldNames = mlStruct.getFieldNames(); assertEquals(2, fieldNames.size()); assertTrue(fieldNames.contains("f1")); assertTrue(fieldNames.contains("f2")); }
/** * Sets field for current structure * * @param name - name of the field * @param value - <code>MLArray</code> field value */ public void setField(String name, MLArray value) { //fields.put(name, value); setField(name, value, currentIndex); } /**
assertThat(settings.getAllFields().size(), equalTo(5)); assertThat(((MLDouble) settings.getField("set")).get(0), equalTo(1.0)); assertThat((settings.getField("inputs")), instanceOf(MLDouble.class)); assertThat(((MLDouble) settings.getField("count")).get(0), equalTo(1000.0)); assertThat(((MLDouble) settings.getField("range")).get(0), equalTo(100.0)); assertThat(((MLDouble) settings.getField("except")).get(0), equalTo(0.0));
MLCell mcosInfo = (MLCell) ((MLStructure) mcosContent.get("@0")).getField("MCOS"); ByteBuffer mcosDataBuf = ((MLUInt8) mcosInfo.get(0)).getRealByteBuffer(); for (MatMCOSObjectInformation it : objectInfoList.values()) { MLStructure attributes = (MLStructure) attribBag.get(it.classId); Collection<String> attributeNames = attributes.getFieldNames(); Map<String, MLArray> objAttributes = it.structure; for (String attributeName : attributeNames) { if (objAttributes.get(attributeName) == null) { objAttributes.put(attributeName, attributes.getField(attributeName));
/** * Dumps field names to byte array. Field names are written as Zero End Strings * * @return byte array */ public byte[] getKeySetToByteArray() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); char[] buffer = new char[getMaxFieldLenth()]; try { for ( String s : keys ) { Arrays.fill(buffer, (char)0); System.arraycopy( s.toCharArray(), 0, buffer, 0, s.length() ); dos.writeBytes( new String(buffer) ); } } catch (IOException e) { System.err.println("Could not write Structure key set to byte array: " + e ); return new byte[0]; } return baos.toByteArray(); } /**
MLStructure struct = new MLStructure(name, dims, type, attributes); for ( int index = 0; index < struct.getM()*struct.getN(); index++ ) struct.setField(fieldNames[i], fieldValue, index); struct.setField(fieldNames[i], new MLEmptyArray(), index); struct = new MLStructure(name, dims, type, attributes); struct.setField( fieldNames[i], fieldValue, index ); struct.setField(fieldNames[i], new MLEmptyArray(), index);
dos.writeInt( ((MLStructure)array).getMaxFieldLenth() ); tag = new OSArrayTag(MatDataTypes.miINT8, ((MLStructure)array).getKeySetToByteArray() ); tag.writeTo( dos ); for ( MLArray a : ((MLStructure)array).getAllFields() )
/** * Gets a value of the field described by name from current struct * in struct array or null if the field doesn't exist. * * @param name * @return */ public MLArray getField(String name) { return getField(name, currentIndex); } /**
/** * Sets field for current structure * * @param name - name of the field * @param value - <code>MLArray</code> field value */ public void setField(String name, MLArray value) { //fields.put(name, value); setField(name, value, currentIndex); } /**