001/* 002 * Copyright 2006-2014 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.sample.domain.trade; 018 019import java.util.HashMap; 020import java.util.Map; 021 022/** 023 * Enum representing on of 3 possible actions on a customer update: 024 * Add, update, or delete 025 * 026 * @author Lucas Ward 027 * 028 */ 029public enum CustomerOperation { 030 ADD('A'), UPDATE('U'), DELETE('D'); 031 032 private final char code; 033 private static final Map<Character,CustomerOperation> CODE_MAP; 034 035 private CustomerOperation(char code) { 036 this.code = code; 037 } 038 039 static{ 040 CODE_MAP = new HashMap<Character,CustomerOperation>(); 041 for(CustomerOperation operation:values()){ 042 CODE_MAP.put(operation.getCode(), operation); 043 } 044 } 045 046 public static CustomerOperation fromCode(char code){ 047 if(CODE_MAP.containsKey(code)){ 048 return CODE_MAP.get(code); 049 } 050 else{ 051 throw new IllegalArgumentException("Invalid code: [" + code + "]"); 052 } 053 } 054 055 public char getCode() { 056 return code; 057 } 058}