@Override final public void write(ObjectOutput out) throws IOException { super.write(out); Map<String, ? extends Number> map = getPayload(); if (map != null) { out.writeInt(map.size()); for (Map.Entry<String, ? extends Number> e : map.entrySet()) { out.writeUTF(e.getKey()); out.writeObject(e.getValue()); } } else { out.writeInt(0); } }
@Override final public void read(ObjectInput in) throws IOException, ClassNotFoundException { super.read(in); Map<String, Number> map = new HashMap<String, Number>(); int sz = in.readInt(); for (int i = 0; i < sz; i++) { map.put(in.readUTF(), (Number) in.readObject()); } this.setPayload(map); } }
public void execute(Lookup ctx, NumberMapDataCommand cmd) { PrintWriter pw = ctx.lookup(PrintWriter.class); if (pw != null) { pw.println("Number map [" + cmd.getName() + "]"); StringBuilder sb = new StringBuilder(); int maxSize = 0; for(Map.Entry<String, ? extends Number> e : cmd.getPayload().entrySet()) { sb.append(e.getKey()).append(" = ").append(e.getValue()).append("\n"); maxSize = Math.max(maxSize, e.getKey().length() + e.getValue().toString().length() + 3); } sb.insert(0, "\n"); for(int i=0;i<maxSize;i++) { sb.insert(0, "="); } pw.print(sb); pw.flush(); } } }
public void execute(Lookup ctx, NumberMapDataCommand cmd) { PrintWriter pw = ctx.lookup(PrintWriter.class); if (pw != null) { pw.println("Number map [" + cmd.getName() + "]"); StringBuilder sb = new StringBuilder(); int maxSize = 0; for(Map.Entry<String, ? extends Number> e : cmd.getPayload().entrySet()) { sb.append(e.getKey()).append(" = ").append(e.getValue()).append("\n"); maxSize = Math.max(maxSize, e.getKey().length() + e.getValue().toString().length() + 3); } sb.insert(0, "\n"); for(int i=0;i<maxSize;i++) { sb.insert(0, "="); } pw.print(sb); pw.flush(); } } }
@Override final public void write(ObjectOutput out) throws IOException { super.write(out); Map<String, ? extends Number> map = getPayload(); if (map != null) { out.writeInt(map.size()); for (Map.Entry<String, ? extends Number> e : map.entrySet()) { out.writeUTF(e.getKey()); out.writeObject(e.getValue()); } } else { out.writeInt(0); } }
@Override final public void read(ObjectInput in) throws IOException, ClassNotFoundException { super.read(in); Map<String, Number> map = new HashMap<String, Number>(); int sz = in.readInt(); for (int i = 0; i < sz; i++) { map.put(in.readUTF(), (Number) in.readObject()); } this.setPayload(map); } }