/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.tribes.util; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import org.apache.catalina.tribes.ChannelMessage; import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.UniqueId; import org.apache.catalina.tribes.group.AbsoluteOrder; import org.apache.catalina.tribes.membership.Membership; /** * @version 1.0 */ public class Arrays { protected static final StringManager sm = StringManager.getManager(Arrays.class); public static boolean contains(byte[] source, int srcoffset, byte[] key, int keyoffset, int length) { if ( srcoffset < 0 || srcoffset >= source.length) throw new ArrayIndexOutOfBoundsException(sm.getString("arrays.srcoffset.outOfBounds")); if ( keyoffset < 0 || keyoffset >= key.length) throw new ArrayIndexOutOfBoundsException(sm.getString("arrays.keyoffset.outOfBounds")); if ( length > (key.length-keyoffset) ) throw new ArrayIndexOutOfBoundsException(sm.getString("arrays.length.outOfBounds")); //we don't have enough data to validate it if ( length > (source.length-srcoffset) ) return false; boolean match = true; int pos = keyoffset; for ( int i=srcoffset; match && i 0 ) { int i = offset; if (unsigned) { buf.append(data[i++] & 0xff); for (; i < length; i++) { buf.append(", ").append(data[i] & 0xff); } } else { buf.append(data[i++]); for (; i < length; i++) { buf.append(", ").append(data[i]); } } } buf.append("}"); return buf.toString(); } public static String toString(Object[] data) { return toString(data,0,data!=null?data.length:0); } public static String toString(Object[] data, int offset, int length) { StringBuilder buf = new StringBuilder("{"); if ( data != null && length > 0 ) { buf.append(data[offset++]); for (int i = offset; i < length; i++) { buf.append(", ").append(data[i]); } } buf.append("}"); return buf.toString(); } public static String toNameString(Member[] data) { return toNameString(data,0,data!=null?data.length:0); } public static String toNameString(Member[] data, int offset, int length) { StringBuilder buf = new StringBuilder("{"); if ( data != null && length > 0 ) { buf.append(data[offset++].getName()); for (int i = offset; i < length; i++) { buf.append(", ").append(data[i].getName()); } } buf.append("}"); return buf.toString(); } public static int add(int[] data) { int result = 0; for (int i=0;i list = new ArrayList<>(java.util.Arrays.asList(m1)); for (int i=0; i result = new ArrayList<>(); Member[] comp = complete.getMembers(); for ( int i=0; i alist = java.util.Arrays.asList(all); ArrayList list = new ArrayList<>(alist); for (int i=0; i= members.length ) idx = ((members.length>0)?0:-1); return idx; } public static int hashCode(byte a[]) { if (a == null) return 0; int result = 1; for (int i=0; i