1 /* 2 * #%L 3 * LongToIntCallback.java - mongodb-async-driver - Allanbank Consulting, Inc. 4 * %% 5 * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. 6 * %% 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * #L% 19 */ 20 21 package com.allanbank.mongodb.client.callback; 22 23 import com.allanbank.mongodb.Callback; 24 25 /** 26 * LongToIntCallback provides a simple callback wrapper to convert the long 27 * value to an integer. 28 * 29 * @api.no This class is <b>NOT</b> part of the drivers API. This class may be 30 * mutated in incompatible ways between any two releases of the driver. 31 * @copyright 2012-2013, Allanbank Consulting, Inc., All Rights Reserved 32 */ 33 public class LongToIntCallback implements Callback<Long> { 34 35 /** The delegate callback to forward the integer result to. */ 36 private final Callback<Integer> myDelegate; 37 38 /** 39 * Creates a new LongToIntCallback. 40 * 41 * @param delegate 42 * The delegate callback to forward the integer result to. 43 */ 44 public LongToIntCallback(final Callback<Integer> delegate) { 45 myDelegate = delegate; 46 } 47 48 /** 49 * {@inheritDoc} 50 * <p> 51 * Overridden to cast the Long to an integer and foward to the delegate 52 * callback. 53 * </p> 54 */ 55 @Override 56 public void callback(final Long result) { 57 myDelegate.callback(Integer.valueOf(result.intValue())); 58 } 59 60 /** 61 * {@inheritDoc} 62 * <p> 63 * Overridden to forward the exception to the delegate callback. 64 * </p> 65 */ 66 @Override 67 public void exception(final Throwable thrown) { 68 myDelegate.exception(thrown); 69 } 70 }