@Test public void testImportMappings() { List<String> in = Arrays.asList("@HYPERPERIOD 300", "@COMMUN_QUANT 0 {", "# type quantity", "0 5", "1 6", "}", "@TASK_GRAPH 0 {", "PERIOD 300", "TASK t0_0 TYPE 1", "TASK t0_1 TYPE 2", "TASK t0_2 TYPE 2", "TASK t0_3 TYPE 2", "ARC a0_0 FROM t0_0 TO t0_1 TYPE 0", "ARC a0_1 FROM t0_1 TO t0_2 TYPE 0", "ARC a0_2 FROM t0_0 TO t0_3 TYPE 1", "HARD_DEADLINE d0_0 ON t0_2 AT 300", "SOFT_DEADLINE d0_1 ON t0_3 AT 200", "}", "@CORE 0 {", "# price area", "79.0597 0.219023", "#-----------", "# type version valid task_time", "0 0 1 10", "1 0 1 7", "2 0 1 11", "}", "@CORE 1 {", "# price area", "72.405 0.166029", "#-----------", "# type version valid task_time", "0 0 1 8", "1 0 0 9", "2 0 1 11", "}", "@CORE 2 {", "# price area", "97.0382 0.185649", "#-----------", "# type version valid task_time", "0 0 1 10", "1 0 0 8", "2 0 1 12", "}", "@WIRING 0", "{", "# max_buffer_size", "491", "}"); ReaderTGFF reader = new ReaderTGFF(); reader.toApplication(in); ResourceTypes<Resource> resourceTypes = reader.toResourceTypes(in); List<String> core = Arrays.asList("# price area", "79.0597 0.219023", "#-----------", "# type version valid task_time", "0 0 1 10", "1 0 1 7", "2 0 1 11", "}", "@CORE 1", "{", "# price area", "72.405 0.166029", "#-----------", "# type version valid task_time", "0 0 1 8", "1 0 0 9", "2 0 1 11", "}", "@CORE 2", "{", "# price area", "97.0382 0.185649", "#-----------", "# type version valid task_time", "0 0 1 10", "1 0 0 8", "2 0 1 12", "}", "@WIRING 0", "{", "# max_buffer_size", "491", "}"); Iterator<String> it = core.iterator(); Mappings<Task, Resource> mappings = new Mappings<Task, Resource>(); String name = "@CORE 0 test"; reader.importMappings(name, it, resourceTypes, mappings); Assert.assertEquals(4, mappings.size()); List<String> ids = new ArrayList<String>( Arrays.asList("m_t0_0_0_r0", "m_t0_1_0_r0", "m_t0_2_0_r0", "m_t0_3_0_r0")); List<Double> times = new ArrayList<Double>(Arrays.asList(7.0, 11.0)); for (Mapping<Task, Resource> mapping : mappings) { Assert.assertTrue(ids.contains(mapping.getId())); Assert.assertTrue(times.contains(mapping.getAttribute("task_time"))); } }
protected void importMappings(String name, Iterator<String> it, ResourceTypes<Resource> resourceTypes, Mappings<Task, Resource> mappings) { String id = "r" + name.split(SEPARATOR)[1]; Resource res = resourceTypes.get(id); while (skip(it.next())) { } String line; List<String> attributes = new LinkedList<String>(); while (!isClosing((line = it.next()))) { if (line.contains(TYPE)) { attributes = new LinkedList<String>(Arrays.asList(line.replace(COMMENT, "").trim().split(SEPARATOR))); } else if (!isComment(line) && line.length() > 0) { String[] values = line.trim().split(SEPARATOR); assert values.length == attributes.size() : "tgff-file \"" + CORE + "\": number of values is not " + "equal to required number of attributes"; String tgffType = values[0]; boolean validMapping = false; if (attributes.contains(VALID)) { validMapping = values[attributes.indexOf(VALID)].equals("1") ? true : false; } if (validMapping && tgffTypeMap.containsKey(tgffType)) { for (Task task : tgffTypeMap.get(tgffType)) { String mappingID = "m" + CONNECTOR + task.getId() + CONNECTOR + res.getId(); Mapping<Task, Resource> mapping = new Mapping<Task, Resource>(mappingID, task, res); for (int i = 0; i < values.length; i++) { mapping.setAttribute(attributes.get(i), Double.valueOf(values[i])); } mappings.add(mapping); } } } } }
ReaderTGFF { protected void importMappings(String name, Iterator<String> it, ResourceTypes<Resource> resourceTypes, Mappings<Task, Resource> mappings) { String id = "r" + name.split(SEPARATOR)[1]; Resource res = resourceTypes.get(id); while (skip(it.next())) { } String line; List<String> attributes = new LinkedList<String>(); while (!isClosing((line = it.next()))) { if (line.contains(TYPE)) { attributes = new LinkedList<String>(Arrays.asList(line.replace(COMMENT, "").trim().split(SEPARATOR))); } else if (!isComment(line) && line.length() > 0) { String[] values = line.trim().split(SEPARATOR); assert values.length == attributes.size() : "tgff-file \"" + CORE + "\": number of values is not " + "equal to required number of attributes"; String tgffType = values[0]; boolean validMapping = false; if (attributes.contains(VALID)) { validMapping = values[attributes.indexOf(VALID)].equals("1") ? true : false; } if (validMapping && tgffTypeMap.containsKey(tgffType)) { for (Task task : tgffTypeMap.get(tgffType)) { String mappingID = "m" + CONNECTOR + task.getId() + CONNECTOR + res.getId(); Mapping<Task, Resource> mapping = new Mapping<Task, Resource>(mappingID, task, res); for (int i = 0; i < values.length; i++) { mapping.setAttribute(attributes.get(i), Double.valueOf(values[i])); } mappings.add(mapping); } } } } } }
ReaderTGFF { protected void importMappings(String name, Iterator<String> it, ResourceTypes<Resource> resourceTypes, Mappings<Task, Resource> mappings) { String id = "r" + name.split(SEPARATOR)[1]; Resource res = resourceTypes.get(id); while (skip(it.next())) { } String line; List<String> attributes = new LinkedList<String>(); while (!isClosing((line = it.next()))) { if (line.contains(TYPE)) { attributes = new LinkedList<String>(Arrays.asList(line.replace(COMMENT, "").trim().split(SEPARATOR))); } else if (!isComment(line) && line.length() > 0) { String[] values = line.trim().split(SEPARATOR); assert values.length == attributes.size() : "tgff-file \"" + CORE + "\": number of values is not " + "equal to required number of attributes"; String tgffType = values[0]; boolean validMapping = false; if (attributes.contains(VALID)) { validMapping = values[attributes.indexOf(VALID)].equals("1") ? true : false; } if (validMapping && tgffTypeMap.containsKey(tgffType)) { for (Task task : tgffTypeMap.get(tgffType)) { String mappingID = "m" + CONNECTOR + task.getId() + CONNECTOR + res.getId(); Mapping<Task, Resource> mapping = new Mapping<Task, Resource>(mappingID, task, res); for (int i = 0; i < values.length; i++) { mapping.setAttribute(attributes.get(i), Double.valueOf(values[i])); } mappings.add(mapping); } } } } }  }
ReaderTGFF { protected void importMappings(String name, Iterator<String> it, ResourceTypes<Resource> resourceTypes, Mappings<Task, Resource> mappings) { String id = "r" + name.split(SEPARATOR)[1]; Resource res = resourceTypes.get(id); while (skip(it.next())) { } String line; List<String> attributes = new LinkedList<String>(); while (!isClosing((line = it.next()))) { if (line.contains(TYPE)) { attributes = new LinkedList<String>(Arrays.asList(line.replace(COMMENT, "").trim().split(SEPARATOR))); } else if (!isComment(line) && line.length() > 0) { String[] values = line.trim().split(SEPARATOR); assert values.length == attributes.size() : "tgff-file \"" + CORE + "\": number of values is not " + "equal to required number of attributes"; String tgffType = values[0]; boolean validMapping = false; if (attributes.contains(VALID)) { validMapping = values[attributes.indexOf(VALID)].equals("1") ? true : false; } if (validMapping && tgffTypeMap.containsKey(tgffType)) { for (Task task : tgffTypeMap.get(tgffType)) { String mappingID = "m" + CONNECTOR + task.getId() + CONNECTOR + res.getId(); Mapping<Task, Resource> mapping = new Mapping<Task, Resource>(mappingID, task, res); for (int i = 0; i < values.length; i++) { mapping.setAttribute(attributes.get(i), Double.valueOf(values[i])); } mappings.add(mapping); } } } } }  SpecificationTypeBased read(String filename); SpecificationTypeBased read(File file); SpecificationTypeBased read(InputStream in); SpecificationTypeBased toSpecification(List<String> in); }
ReaderTGFF { protected void importMappings(String name, Iterator<String> it, ResourceTypes<Resource> resourceTypes, Mappings<Task, Resource> mappings) { String id = "r" + name.split(SEPARATOR)[1]; Resource res = resourceTypes.get(id); while (skip(it.next())) { } String line; List<String> attributes = new LinkedList<String>(); while (!isClosing((line = it.next()))) { if (line.contains(TYPE)) { attributes = new LinkedList<String>(Arrays.asList(line.replace(COMMENT, "").trim().split(SEPARATOR))); } else if (!isComment(line) && line.length() > 0) { String[] values = line.trim().split(SEPARATOR); assert values.length == attributes.size() : "tgff-file \"" + CORE + "\": number of values is not " + "equal to required number of attributes"; String tgffType = values[0]; boolean validMapping = false; if (attributes.contains(VALID)) { validMapping = values[attributes.indexOf(VALID)].equals("1") ? true : false; } if (validMapping && tgffTypeMap.containsKey(tgffType)) { for (Task task : tgffTypeMap.get(tgffType)) { String mappingID = "m" + CONNECTOR + task.getId() + CONNECTOR + res.getId(); Mapping<Task, Resource> mapping = new Mapping<Task, Resource>(mappingID, task, res); for (int i = 0; i < values.length; i++) { mapping.setAttribute(attributes.get(i), Double.valueOf(values[i])); } mappings.add(mapping); } } } } }  SpecificationTypeBased read(String filename); SpecificationTypeBased read(File file); SpecificationTypeBased read(InputStream in); SpecificationTypeBased toSpecification(List<String> in); static final String TGFF_TYPE; static final String PERIOD; static final String MSG_SIZE; static final String RES_ATTRIBUTES; static final String RES_VALUES; static final String HARD_DEADLINE; static final String SOFT_DEADLINE; static final String WIRE; }