All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.prezi.pride.internal.LoggedProgressAction Maven / Gradle / Ivy

There is a newer version: 0.12.3
Show newest version
package com.prezi.pride.internal;

import com.google.common.base.Strings;
import com.prezi.pride.Named;
import com.prezi.pride.Pride;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public abstract class LoggedProgressAction implements ProgressAction {
	protected static final Logger logger = LoggerFactory.getLogger(LoggedProgressAction.class);

	private final String logPrefix;
	private final String logSuffix;
	private final Named.Namer namer;

	public LoggedProgressAction(String logPrefix, Named.Namer namer) {
		this(logPrefix, null, namer);
	}

	public LoggedProgressAction(String logPrefix, String logSuffix, Named.Namer namer) {
		this.namer = namer;
		this.logPrefix = Strings.isNullOrEmpty(logPrefix) ? "" : logPrefix + " ";
		this.logSuffix = Strings.isNullOrEmpty(logSuffix) ? "" : " " + logSuffix;
	}

	@Override
	public void execute(Pride pride, T item, int index, int count) throws IOException {
		logger.info("[{}/{}] {}{}{}", index + 1, count, logPrefix, namer.getName(item), logSuffix);
		execute(pride, item);
	}

	abstract protected void execute(Pride pride, T item) throws IOException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy