/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  android.util.Log
 *  java.lang.IllegalArgumentException
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.lang.Throwable
 *  java.util.Vector
 */
package com.google.code.microlog4android.format;

import android.util.Log;
import com.google.code.microlog4android.Level;
import com.google.code.microlog4android.format.Formatter;
import com.google.code.microlog4android.format.command.CategoryFormatCommand;
import com.google.code.microlog4android.format.command.ClientIdFormatCommand;
import com.google.code.microlog4android.format.command.DateFormatCommand;
import com.google.code.microlog4android.format.command.FormatCommandInterface;
import com.google.code.microlog4android.format.command.MessageFormatCommand;
import com.google.code.microlog4android.format.command.NoFormatCommand;
import com.google.code.microlog4android.format.command.PriorityFormatCommand;
import com.google.code.microlog4android.format.command.ThreadFormatCommand;
import com.google.code.microlog4android.format.command.ThrowableFormatCommand;
import com.google.code.microlog4android.format.command.TimeFormatCommand;
import java.util.Vector;

public class PatternFormatter
implements Formatter {
    public static final char CATEGORY_CONVERSION_CHAR = 'c';
    public static final char CLIENT_ID_CONVERSION_CHAR = 'i';
    public static final char DATE_CONVERSION_CHAR = 'd';
    public static final String DEFAULT_CONVERSION_PATTERN = "%r %c{1} [%P] %m %T";
    public static final char MESSAGE_CONVERSION_CHAR = 'm';
    public static final String PATTERN_PROPERTY = "pattern";
    public static final char PERCENT_CONVERSION_CHAR = '%';
    public static final char PRIORITY_CONVERSION_CHAR = 'P';
    private static final String[] PROPERTY_NAMES = new String[]{"pattern"};
    public static final char RELATIVE_TIME_CONVERSION_CHAR = 'r';
    private static final String TAG = "Microlog.PatternFormatter";
    public static final char THREAD_CONVERSION_CHAR = 't';
    public static final char THROWABLE_CONVERSION_CHAR = 'T';
    private FormatCommandInterface[] commandArray;
    private String pattern = "%r %c{1} [%P] %m %T";
    private boolean patternParsed = false;

    /*
     * Enabled aggressive block sorting
     */
    private void parsePattern(String string2) {
        int n = 0;
        int n2 = string2.length();
        Vector vector = new Vector(20);
        do {
            if (n >= n2) {
                this.commandArray = new FormatCommandInterface[vector.size()];
                vector.copyInto(this.commandArray);
                this.patternParsed = true;
                return;
            }
            if (string2.charAt(n) == '%') {
                int n3 = n + 1;
                char c = string2.charAt(n3);
                switch (c) {
                    default: {
                        Log.e((String)"Microlog.PatternFormatter", (String)("Unrecognized conversion character " + c));
                        break;
                    }
                    case 'i': {
                        vector.addElement((Object)new ClientIdFormatCommand());
                        break;
                    }
                    case 'c': {
                        CategoryFormatCommand categoryFormatCommand = new CategoryFormatCommand();
                        String string3 = this.extraxtSpecifier(string2, n3);
                        int n4 = string3.length();
                        if (n4 > 0) {
                            categoryFormatCommand.init(string3);
                            n3 = 2 + (n3 + n4);
                        }
                        vector.addElement((Object)categoryFormatCommand);
                        break;
                    }
                    case 'd': {
                        DateFormatCommand dateFormatCommand = new DateFormatCommand();
                        String string4 = this.extraxtSpecifier(string2, n3);
                        int n5 = string4.length();
                        if (n5 > 0) {
                            dateFormatCommand.init(string4);
                            n3 = 2 + (n3 + n5);
                        }
                        vector.addElement((Object)dateFormatCommand);
                        break;
                    }
                    case 'm': {
                        vector.addElement((Object)new MessageFormatCommand());
                        break;
                    }
                    case 'P': {
                        vector.addElement((Object)new PriorityFormatCommand());
                        break;
                    }
                    case 'r': {
                        vector.addElement((Object)new TimeFormatCommand());
                        break;
                    }
                    case 't': {
                        vector.addElement((Object)new ThreadFormatCommand());
                        break;
                    }
                    case 'T': {
                        vector.addElement((Object)new ThrowableFormatCommand());
                        break;
                    }
                    case '%': {
                        NoFormatCommand noFormatCommand = new NoFormatCommand();
                        noFormatCommand.init("%");
                        vector.addElement((Object)noFormatCommand);
                    }
                }
                n = n3 + 1;
                continue;
            }
            int n6 = string2.indexOf("%", n);
            String string5 = n6 != -1 ? string2.substring(n, n6) : string2.substring(n, n2);
            NoFormatCommand noFormatCommand = new NoFormatCommand();
            noFormatCommand.init(string5);
            vector.addElement((Object)noFormatCommand);
            n += string5.length();
        } while (true);
    }

    String extraxtSpecifier(String string2, int n) {
        String string3 = "";
        int n2 = string2.indexOf(123, n);
        int n3 = string2.indexOf(125, n);
        if (n2 > 0 && n3 > n2) {
            string3 = string2.substring(n2 + 1, n3);
        }
        return string3;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    @Override
    public String format(String string2, String string3, long l, Level level, Object object, Throwable throwable) {
        if (!this.patternParsed && this.pattern != null) {
            this.parsePattern(this.pattern);
        }
        StringBuffer stringBuffer = new StringBuffer(64);
        if (this.commandArray == null) return stringBuffer.toString();
        int n = this.commandArray.length;
        int n2 = 0;
        while (n2 < n) {
            FormatCommandInterface formatCommandInterface = this.commandArray[n2];
            if (formatCommandInterface != null) {
                stringBuffer.append(formatCommandInterface.execute(string2, string3, l, level, object, throwable));
            }
            ++n2;
        }
        return stringBuffer.toString();
    }

    public String getPattern() {
        return this.pattern;
    }

    @Override
    public String[] getPropertyNames() {
        return PROPERTY_NAMES;
    }

    public void setPattern(String string2) throws IllegalArgumentException {
        if (string2 == null) {
            throw new IllegalArgumentException("The pattern must not be null.");
        }
        this.pattern = string2;
        super.parsePattern(this.pattern);
    }

    @Override
    public void setProperty(String string2, String string3) {
        if (string2.equals((Object)"pattern")) {
            this.setPattern(string3);
        }
    }
}

