1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.doxia.sink.impl; 20 21 import java.util.Arrays; 22 import java.util.Objects; 23 24 /** 25 * A single sink event, used for testing purposes in order to check 26 * the order and effect of some parser events. 27 * 28 * @author ltheussl 29 * @since 1.1 30 */ 31 public class SinkEventElement { 32 /** The name of the sink event, ie the sink method name. */ 33 private final String methodName; 34 35 /** The array of arguments to the sink method. */ 36 private final Object[] args; 37 38 /** 39 * A SinkEventElement is characterized by the method name and associated array of arguments. 40 * 41 * @param name The name of the sink event, ie the sink method name. 42 * @param arguments The array of arguments to the sink method. 43 * For a no-arg element this may be null or an empty array. 44 */ 45 public SinkEventElement(String name, Object[] arguments) { 46 Objects.requireNonNull(name, "name cannot be null"); 47 48 this.methodName = name; 49 this.args = arguments; 50 } 51 52 /** 53 * Return the name of the this event. 54 * 55 * @return The name of the sink event. 56 */ 57 public String getName() { 58 return this.methodName; 59 } 60 61 /** 62 * Return the array of arguments to the sink method. 63 * 64 * @return the array of arguments to the sink method. 65 */ 66 public Object[] getArgs() { 67 return this.args; 68 } 69 70 /** 71 * {@inheritDoc} 72 * @since 1.1.1 73 */ 74 @Override 75 public String toString() { 76 StringBuilder builder = new StringBuilder(); 77 builder.append(this.getClass().getSimpleName()).append('['); 78 builder.append("methodName: ").append(methodName).append(", "); 79 builder.append("args: ").append(Arrays.deepToString(args)); 80 builder.append(']'); 81 return builder.toString(); 82 } 83 84 @Override 85 public int hashCode() { 86 final int prime = 31; 87 int result = 1; 88 result = prime * result + Arrays.deepHashCode(args); 89 result = prime * result + Objects.hash(methodName); 90 return result; 91 } 92 93 @Override 94 public boolean equals(Object obj) { 95 if (this == obj) return true; 96 if (obj == null) return false; 97 if (getClass() != obj.getClass()) return false; 98 SinkEventElement other = (SinkEventElement) obj; 99 return Arrays.deepEquals(args, other.args) && Objects.equals(methodName, other.methodName); 100 } 101 }