@Test public void testLoadMap() throws Exception { OutputStream os = new PipedOutputStream(); InputStream is = new PipedInputStream(); PB840Parameters pb840 = new PB840Parameters(is,os); Map<String, PB840Parameters.Field[]> fields = new HashMap<String, PB840Parameters.Field[]>(); pb840.loadFields(fields); for(String key : fields.keySet()) { System.out.println(key); for(PB840Parameters.Field f : fields.get(key)) { System.out.println("\t"+f); } } }
protected void loadFields(Map<String, Field[]> fields) { int lineNumber = 0; try { BufferedReader br = new BufferedReader(new InputStreamReader(PB840Parameters.class.getResourceAsStream("pb840.fields"))); String line = null; List<Field> currentFields = new ArrayList<Field>(); String currentResponseType = null; while (null != (line = br.readLine())) { if(0==lineNumber++) { continue; } line = line.trim(); if ('#' != line.charAt(0)) { String v[] = line.split("\t"); if (v.length < 1) { log.warn("Bad line" + lineNumber + ":" + line); } else if(v.length < 2) { if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = v[0]; } else { String type = v[0]; String name = v[1]; String units = v.length > 2 ? v[2] : null; String field1 = v.length > 3 ? v[3] : null; String field2 = v.length > 4 ? v[4] : null; String description = v.length > 5 ? v[5] : null; if("S".equals(type)) { currentFields.add(new Setting(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("N".equals(type)) { currentFields.add(new Numeric(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("AS".equals(type)) { currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field1), "low_limit")); currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field2), "high_limit")); } else if("PA".equals(type)) { currentFields.add(new PatientAlert(name, description, Integer.parseInt(field1))); } else if("TA".equals(type)) { currentFields.add(new TechnicalAlert(name, description, Integer.parseInt(field1))); } else if("ID".equals(type)) { currentFields.add(new VentilatorId(Integer.parseInt(field1))); } else if("TM".equals(type)) { currentFields.add(new Time(Integer.parseInt(field1))); } else if("DT".equals(type)) { currentFields.add(new Date(Integer.parseInt(field1))); } else { throw new IllegalArgumentException("Unknown field type " + type + " with " + v.length + " total elements"); } } } } if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = null; } catch (Exception e) { throw new RuntimeException("Error at line " + lineNumber, e); } }
PB840Parameters extends PB840 { protected void loadFields(Map<String, Field[]> fields) { int lineNumber = 0; try { BufferedReader br = new BufferedReader(new InputStreamReader(PB840Parameters.class.getResourceAsStream("pb840.fields"))); String line = null; List<Field> currentFields = new ArrayList<Field>(); String currentResponseType = null; while (null != (line = br.readLine())) { if(0==lineNumber++) { continue; } line = line.trim(); if ('#' != line.charAt(0)) { String v[] = line.split("\t"); if (v.length < 1) { log.warn("Bad line" + lineNumber + ":" + line); } else if(v.length < 2) { if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = v[0]; } else { String type = v[0]; String name = v[1]; String units = v.length > 2 ? v[2] : null; String field1 = v.length > 3 ? v[3] : null; String field2 = v.length > 4 ? v[4] : null; String description = v.length > 5 ? v[5] : null; if("S".equals(type)) { currentFields.add(new Setting(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("N".equals(type)) { currentFields.add(new Numeric(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("AS".equals(type)) { currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field1), "low_limit")); currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field2), "high_limit")); } else if("PA".equals(type)) { currentFields.add(new PatientAlert(name, description, Integer.parseInt(field1))); } else if("TA".equals(type)) { currentFields.add(new TechnicalAlert(name, description, Integer.parseInt(field1))); } else if("ID".equals(type)) { currentFields.add(new VentilatorId(Integer.parseInt(field1))); } else if("TM".equals(type)) { currentFields.add(new Time(Integer.parseInt(field1))); } else if("DT".equals(type)) { currentFields.add(new Date(Integer.parseInt(field1))); } else { throw new IllegalArgumentException("Unknown field type " + type + " with " + v.length + " total elements"); } } } } if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = null; } catch (Exception e) { throw new RuntimeException("Error at line " + lineNumber, e); } } }
PB840Parameters extends PB840 { protected void loadFields(Map<String, Field[]> fields) { int lineNumber = 0; try { BufferedReader br = new BufferedReader(new InputStreamReader(PB840Parameters.class.getResourceAsStream("pb840.fields"))); String line = null; List<Field> currentFields = new ArrayList<Field>(); String currentResponseType = null; while (null != (line = br.readLine())) { if(0==lineNumber++) { continue; } line = line.trim(); if ('#' != line.charAt(0)) { String v[] = line.split("\t"); if (v.length < 1) { log.warn("Bad line" + lineNumber + ":" + line); } else if(v.length < 2) { if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = v[0]; } else { String type = v[0]; String name = v[1]; String units = v.length > 2 ? v[2] : null; String field1 = v.length > 3 ? v[3] : null; String field2 = v.length > 4 ? v[4] : null; String description = v.length > 5 ? v[5] : null; if("S".equals(type)) { currentFields.add(new Setting(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("N".equals(type)) { currentFields.add(new Numeric(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("AS".equals(type)) { currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field1), "low_limit")); currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field2), "high_limit")); } else if("PA".equals(type)) { currentFields.add(new PatientAlert(name, description, Integer.parseInt(field1))); } else if("TA".equals(type)) { currentFields.add(new TechnicalAlert(name, description, Integer.parseInt(field1))); } else if("ID".equals(type)) { currentFields.add(new VentilatorId(Integer.parseInt(field1))); } else if("TM".equals(type)) { currentFields.add(new Time(Integer.parseInt(field1))); } else if("DT".equals(type)) { currentFields.add(new Date(Integer.parseInt(field1))); } else { throw new IllegalArgumentException("Unknown field type " + type + " with " + v.length + " total elements"); } } } } if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = null; } catch (Exception e) { throw new RuntimeException("Error at line " + lineNumber, e); } } PB840Parameters(final InputStream in, final OutputStream out); }
PB840Parameters extends PB840 { protected void loadFields(Map<String, Field[]> fields) { int lineNumber = 0; try { BufferedReader br = new BufferedReader(new InputStreamReader(PB840Parameters.class.getResourceAsStream("pb840.fields"))); String line = null; List<Field> currentFields = new ArrayList<Field>(); String currentResponseType = null; while (null != (line = br.readLine())) { if(0==lineNumber++) { continue; } line = line.trim(); if ('#' != line.charAt(0)) { String v[] = line.split("\t"); if (v.length < 1) { log.warn("Bad line" + lineNumber + ":" + line); } else if(v.length < 2) { if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = v[0]; } else { String type = v[0]; String name = v[1]; String units = v.length > 2 ? v[2] : null; String field1 = v.length > 3 ? v[3] : null; String field2 = v.length > 4 ? v[4] : null; String description = v.length > 5 ? v[5] : null; if("S".equals(type)) { currentFields.add(new Setting(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("N".equals(type)) { currentFields.add(new Numeric(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("AS".equals(type)) { currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field1), "low_limit")); currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field2), "high_limit")); } else if("PA".equals(type)) { currentFields.add(new PatientAlert(name, description, Integer.parseInt(field1))); } else if("TA".equals(type)) { currentFields.add(new TechnicalAlert(name, description, Integer.parseInt(field1))); } else if("ID".equals(type)) { currentFields.add(new VentilatorId(Integer.parseInt(field1))); } else if("TM".equals(type)) { currentFields.add(new Time(Integer.parseInt(field1))); } else if("DT".equals(type)) { currentFields.add(new Date(Integer.parseInt(field1))); } else { throw new IllegalArgumentException("Unknown field type " + type + " with " + v.length + " total elements"); } } } } if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = null; } catch (Exception e) { throw new RuntimeException("Error at line " + lineNumber, e); } } PB840Parameters(final InputStream in, final OutputStream out); void sendReset(); void sendA(); void sendF(); boolean receive(); void receiveStartResponse(String type); void receiveEndResponse(); void receiveSetting(String name, Units units, String value); void receiveNumeric(String name, Units units, String value); void receiveAlarmLimit(String metricName, PB840.Units unitID, String value, String limitType); void receiveTechnicalAlert(String name, String value); void receivePatientAlert(String name, String value); void receiveVentilatorId(String model, String id); void receiveDate(int month, int day, int year); void receiveTime(int hour, int minute); }
PB840Parameters extends PB840 { protected void loadFields(Map<String, Field[]> fields) { int lineNumber = 0; try { BufferedReader br = new BufferedReader(new InputStreamReader(PB840Parameters.class.getResourceAsStream("pb840.fields"))); String line = null; List<Field> currentFields = new ArrayList<Field>(); String currentResponseType = null; while (null != (line = br.readLine())) { if(0==lineNumber++) { continue; } line = line.trim(); if ('#' != line.charAt(0)) { String v[] = line.split("\t"); if (v.length < 1) { log.warn("Bad line" + lineNumber + ":" + line); } else if(v.length < 2) { if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = v[0]; } else { String type = v[0]; String name = v[1]; String units = v.length > 2 ? v[2] : null; String field1 = v.length > 3 ? v[3] : null; String field2 = v.length > 4 ? v[4] : null; String description = v.length > 5 ? v[5] : null; if("S".equals(type)) { currentFields.add(new Setting(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("N".equals(type)) { currentFields.add(new Numeric(name, description, Units.valueOf(units), Integer.parseInt(field1))); } else if("AS".equals(type)) { currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field1), "low_limit")); currentFields.add(new AlarmLimit(name, description, Units.getValue(units), Integer.parseInt(field2), "high_limit")); } else if("PA".equals(type)) { currentFields.add(new PatientAlert(name, description, Integer.parseInt(field1))); } else if("TA".equals(type)) { currentFields.add(new TechnicalAlert(name, description, Integer.parseInt(field1))); } else if("ID".equals(type)) { currentFields.add(new VentilatorId(Integer.parseInt(field1))); } else if("TM".equals(type)) { currentFields.add(new Time(Integer.parseInt(field1))); } else if("DT".equals(type)) { currentFields.add(new Date(Integer.parseInt(field1))); } else { throw new IllegalArgumentException("Unknown field type " + type + " with " + v.length + " total elements"); } } } } if(null != currentResponseType) { fields.put(currentResponseType, currentFields.toArray(new Field[0])); currentFields.clear(); } if(!currentFields.isEmpty()) { log.warn(currentFields.size() + " orphaned fields:"+currentFields); currentFields.clear(); } currentResponseType = null; } catch (Exception e) { throw new RuntimeException("Error at line " + lineNumber, e); } } PB840Parameters(final InputStream in, final OutputStream out); void sendReset(); void sendA(); void sendF(); boolean receive(); void receiveStartResponse(String type); void receiveEndResponse(); void receiveSetting(String name, Units units, String value); void receiveNumeric(String name, Units units, String value); void receiveAlarmLimit(String metricName, PB840.Units unitID, String value, String limitType); void receiveTechnicalAlert(String name, String value); void receivePatientAlert(String name, String value); void receiveVentilatorId(String model, String id); void receiveDate(int month, int day, int year); void receiveTime(int hour, int minute);  }