|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| NotificationListEvent.java | 70% | 83.3% | 100% | 83% |
|
||||||||||||||
| 1 | /* | |
| 2 | * Copyright (c) 1998, 2005 Gargoyle Software Inc. All rights reserved. | |
| 3 | * | |
| 4 | * Redistribution and use in source and binary forms, with or without | |
| 5 | * modification, are permitted provided that the following conditions are met: | |
| 6 | * | |
| 7 | * 1. Redistributions of source code must retain the above copyright notice, | |
| 8 | * this list of conditions and the following disclaimer. | |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 10 | * this list of conditions and the following disclaimer in the documentation | |
| 11 | * and/or other materials provided with the distribution. | |
| 12 | * 3. The end-user documentation included with the redistribution, if any, must | |
| 13 | * include the following acknowledgment: | |
| 14 | * | |
| 15 | * "This product includes software developed by Gargoyle Software Inc. | |
| 16 | * (http://www.GargoyleSoftware.com/)." | |
| 17 | * | |
| 18 | * Alternately, this acknowledgment may appear in the software itself, if | |
| 19 | * and wherever such third-party acknowledgments normally appear. | |
| 20 | * 4. The name "Gargoyle Software" must not be used to endorse or promote | |
| 21 | * products derived from this software without prior written permission. | |
| 22 | * For written permission, please contact info@GargoyleSoftware.com. | |
| 23 | * 5. Products derived from this software may not be called "GSBase", nor may | |
| 24 | * "GSBase" appear in their name, without prior written permission of | |
| 25 | * Gargoyle Software Inc. | |
| 26 | * | |
| 27 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |
| 28 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 29 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE | |
| 30 | * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 33 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 36 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 37 | */ | |
| 38 | package com.gargoylesoftware.base.collections; | |
| 39 | ||
| 40 | import com.gargoylesoftware.base.util.DetailedIllegalArgumentException; | |
| 41 | import com.gargoylesoftware.base.util.DetailedNullPointerException; | |
| 42 | import java.util.Collections; | |
| 43 | import java.util.EventObject; | |
| 44 | import java.util.List; | |
| 45 | ||
| 46 | /** | |
| 47 | * An event that is fired when a NotificationList changes. | |
| 48 | * | |
| 49 | * @version $Revision: 1.5 $ | |
| 50 | * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> | |
| 51 | */ | |
| 52 | public class NotificationListEvent extends EventObject { | |
| 53 | private static final long serialVersionUID = -1402888290373923581L; | |
| 54 | /** | |
| 55 | * Action indicating that an item was inserted into the list. | |
| 56 | */ | |
| 57 | public static final int INSERT = 1; | |
| 58 | /** | |
| 59 | * Action indicating that an item was removed from the list. | |
| 60 | */ | |
| 61 | public static final int REMOVE = 2; | |
| 62 | /** | |
| 63 | * Action indicating that an item in the list was change. | |
| 64 | */ | |
| 65 | public static final int CHANGE = 3; | |
| 66 | ||
| 67 | private final int startIndex_; | |
| 68 | private final int endIndex_; | |
| 69 | private final int action_; | |
| 70 | private final List oldValues_; | |
| 71 | private final List newValues_; | |
| 72 | ||
| 73 | /** | |
| 74 | * Create a new event. | |
| 75 | * @param source The NotificationList | |
| 76 | * @param action The action that occured. This will be one of INSERT, REMOVE or CHANGE. | |
| 77 | * @param startIndex The index of the first item that is affected. | |
| 78 | * @param endIndex The index of the last item that is affected. | |
| 79 | * @param oldValues The original values. | |
| 80 | * @param newValues The new values. | |
| 81 | */ | |
| 82 | 18 | public NotificationListEvent( final NotificationList source, |
| 83 | final int action, | |
| 84 | final int startIndex, | |
| 85 | final int endIndex, | |
| 86 | final List oldValues, | |
| 87 | final List newValues) { | |
| 88 | 18 | super(source); |
| 89 | 18 | startIndex_ = startIndex; |
| 90 | 18 | endIndex_ = endIndex; |
| 91 | 18 | if( oldValues.size() == 0 ) { |
| 92 | 16 | oldValues_ = Collections.EMPTY_LIST; |
| 93 | } | |
| 94 | else { | |
| 95 | 2 | oldValues_ = Collections.unmodifiableList(oldValues); |
| 96 | } | |
| 97 | ||
| 98 | 18 | if( newValues.size() == 0 ) { |
| 99 | 1 | newValues_ = Collections.EMPTY_LIST; |
| 100 | } | |
| 101 | else { | |
| 102 | 17 | newValues_ = Collections.unmodifiableList(newValues); |
| 103 | } | |
| 104 | ||
| 105 | 18 | action_ = action; |
| 106 | ||
| 107 | 18 | switch( action ) { |
| 108 | 16 | case INSERT: |
| 109 | 1 | case REMOVE: |
| 110 | 1 | case CHANGE: |
| 111 | // Normal | |
| 112 | 18 | break; |
| 113 | ||
| 114 | 0 | default: |
| 115 | 0 | throw new DetailedIllegalArgumentException("action", new Integer(action), "Unexpected value"); |
| 116 | } | |
| 117 | ||
| 118 | 18 | if( startIndex < 0 ) { |
| 119 | 0 | throw new DetailedIllegalArgumentException("startIndex", new Integer(startIndex), "less than zero"); |
| 120 | } | |
| 121 | ||
| 122 | 18 | if( endIndex < startIndex ) { |
| 123 | 0 | throw new IllegalArgumentException("endIndex<startIndex: " |
| 124 | + endIndex | |
| 125 | + "<" | |
| 126 | + startIndex); | |
| 127 | } | |
| 128 | ||
| 129 | 18 | assertNotNull("oldValues", oldValues); |
| 130 | 18 | assertNotNull("newValues", newValues); |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Return the start index. | |
| 135 | * @return The start index. | |
| 136 | */ | |
| 137 | 12 | public int getStartIndex() { |
| 138 | 12 | return startIndex_; |
| 139 | } | |
| 140 | ||
| 141 | /** | |
| 142 | * Return the end index. | |
| 143 | * @return The end index. | |
| 144 | */ | |
| 145 | 12 | public int getEndIndex() { |
| 146 | 12 | return endIndex_; |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * Return the action which will be one of INSERT, REMOVE, CHANGE. | |
| 151 | * @return The action. | |
| 152 | */ | |
| 153 | 8 | public int getAction() { |
| 154 | 8 | return action_; |
| 155 | } | |
| 156 | ||
| 157 | /** | |
| 158 | * Return the new values | |
| 159 | * @return The new values. | |
| 160 | */ | |
| 161 | 13 | public List getNewValues() { |
| 162 | 13 | return newValues_; |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * Return the old values. | |
| 167 | * @return The old values. | |
| 168 | */ | |
| 169 | 9 | public List getOldValues() { |
| 170 | 9 | return oldValues_; |
| 171 | } | |
| 172 | ||
| 173 | ||
| 174 | /** | |
| 175 | * Throw an exception if the specified object is null | |
| 176 | * @param fieldName The name of the paremeter we are checking | |
| 177 | * @param object The value of the parameter we are checking | |
| 178 | */ | |
| 179 | 36 | protected final void assertNotNull( final String fieldName, final Object object ) { |
| 180 | 36 | if( object == null ) { |
| 181 | 0 | throw new DetailedNullPointerException(fieldName); |
| 182 | } | |
| 183 | } | |
| 184 | } | |
| 185 | ||
| 186 | ||
| 187 |
|
||||||||||