1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.class2greylist; 18 19 import java.util.Locale; 20 21 public class Status { 22 23 // Highlight "Error:" in red. 24 private static final String ERROR = "\u001B[31mError: \u001B[0m"; 25 26 private final boolean mDebug; 27 private boolean mHasErrors; 28 Status(boolean debug)29 public Status(boolean debug) { 30 mDebug = debug; 31 } 32 debug(String msg, Object... args)33 public void debug(String msg, Object... args) { 34 if (mDebug) { 35 System.err.println(String.format(Locale.US, msg, args)); 36 } 37 } 38 error(Throwable t)39 public void error(Throwable t) { 40 System.err.print(ERROR); 41 t.printStackTrace(System.err); 42 mHasErrors = true; 43 } 44 error(String message, Object... args)45 public void error(String message, Object... args) { 46 System.err.print(ERROR); 47 System.err.println(String.format(Locale.US, message, args)); 48 mHasErrors = true; 49 } 50 ok()51 public boolean ok() { 52 return !mHasErrors; 53 } 54 } 55