001/* 002 * Copyright 2006-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.core.step.item; 018 019import org.springframework.lang.Nullable; 020 021/** 022 * Wrapper for an item and its exception if it failed processing. 023 * 024 * @author Dave Syer 025 * @author Mahmoud Ben Hassine 026 * 027 */ 028public class SkipWrapper<T> { 029 030 final private Throwable exception; 031 032 final private T item; 033 034 /** 035 * @param item the item being wrapped. 036 */ 037 public SkipWrapper(T item) { 038 this(item, null); 039 } 040 041 /** 042 * @param e instance of {@link Throwable} that being wrapped. 043 */ 044 public SkipWrapper(Throwable e) { 045 this(null, e); 046 } 047 048 049 public SkipWrapper(T item, @Nullable Throwable e) { 050 this.item = item; 051 this.exception = e; 052 } 053 054 /** 055 * Public getter for the exception. 056 * @return the exception 057 */ 058 @Nullable 059 public Throwable getException() { 060 return exception; 061 } 062 063 /** 064 * Public getter for the item. 065 * @return the item 066 */ 067 public T getItem() { 068 return item; 069 } 070 071 @Override 072 public String toString() { 073 return String.format("[exception=%s, item=%s]", exception, item); 074 } 075 076}