Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package jpaoletti.jpm.core.monitor;
 
A formatter that receives an array and returns a formatted string. This formatter has two properties separator an intem separator pads a list of # separated padding item representation. Each padding item representation hast the form [A,B,C,D] where A: Index of the array where the item will be taken B: L or R, indicates the direction of the padding (Left or right) C: Padding character D: Padding length

Author(s):
jpaoletti
public class BasicObjectArrayFormatter extends MonitorFormatter {
    @Override
    public String format(MonitorLine line) {
        Object[] objects = (Object[]) line.getValue();
        String[] pads = getConfig("pads""").split("#");
        //[0,L,0,2] = [column , L or R pad direction , fill char , pad count]
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < objects.lengthi++) {
            Object object = objects[i];
            String pad = getPad(padsi);
            if (pad == null) {
                sb.append(object.toString());
            } else {
                String[] ss = pad.split(",");
                if (ss.length == 4) {
                    boolean left = (ss[1].trim().compareTo("L") == 0);
                    char fill = ss[2].charAt(0);
                    int count = 0;
                    try {
                        count = Integer.parseInt(ss[3].trim());
                    } catch (Exception e) {
                    }
                    if (left) {
                        sb.append(Utils.padleft(object.toString(), countfill));
                    } else {
                        sb.append(Utils.padright(object.toString(), countfill));
                    }
                } else {
                    sb.append(object.toString());
                }
            }
            sb.append(getConfig("separator"" "));
        }
        return sb.toString();
    }
    private String getPad(String[] padsint i) {
        for (int j = 0; j < pads.lengthj++) {
            String pad = pads[j].trim();
            pad = pad.replace('['' ').replace(']'' ').trim();
            String[] ss = pad.split(",");
            if (ss.length == 4) {
                try {
                    if (Integer.parseInt(ss[0]) == i) {
                        return pad;
                    }
                } catch (Exception e) {
                }
            }
        }
        return null;
    }
New to GrepCode? Check out our FAQ X