private static void boundsCheck(final byte[] buffer, final int index, final int length) { if (SHOULD_BOUNDS_CHECK) { ArrayUtils.boundsCheck(buffer.length, index, length); } } }
public static boolean isUnalignedAccessAllowed() { String currentArchitecture = System.getProperty("os.arch"); return ArrayUtils.contains(ARCHITECTURES_KNOWN_TO_ALLOW_UNALIGNED_ACCESS, currentArchitecture); } }
public ClassWhitelistFilter(String... whitelisted) { whitelist = ArrayUtils.createCopy(whitelisted); }
@Override public OutboundPipeline addLast(OutboundHandler... addedHandlers) { checkNotNull(addedHandlers, "addedHandlers can't be null"); for (OutboundHandler addedHandler : addedHandlers) { addedHandler.setChannel(channel).handlerAdded(); } updatePipeline(append(handlers, addedHandlers)); return this; }
@Override public OutboundPipeline replace(OutboundHandler oldHandler, OutboundHandler... addedHandlers) { checkNotNull(oldHandler, "oldHandler can't be null"); checkNotNull(addedHandlers, "newHandler can't be null"); OutboundHandler[] newHandlers = replaceFirst(handlers, oldHandler, addedHandlers); if (newHandlers == handlers) { throw new IllegalArgumentException("handler " + oldHandler + " isn't part of the pipeline"); } for (OutboundHandler addedHandler : addedHandlers) { addedHandler.setChannel(channel).handlerAdded(); } updatePipeline(newHandlers); return this; }
/** * Removes an item from the array. * * If the item has been found, a new array is returned where this item is removed. Otherwise the original array is returned. * * @param src the src array * @param object the object to remove * @param <T> the type of the array * @return the resulting array */ public static <T> T[] remove(T[] src, T object) { int index = indexOf(src, object); if (index == -1) { return src; } T[] dst = (T[]) Array.newInstance(src.getClass().getComponentType(), src.length - 1); System.arraycopy(src, 0, dst, 0, index); if (index < src.length - 1) { System.arraycopy(src, index + 1, dst, index, src.length - index - 1); } return dst; }
private Object getItemAtPositionOrNull(Object object, int position) { if (object == null) { return null; } else if (object instanceof Collection) { return CollectionUtil.getItemAtPositionOrNull((Collection) object, position); } else if (object instanceof Object[]) { return ArrayUtils.getItemAtPositionOrNull((Object[]) object, position); } else if (object.getClass().isArray()) { return Array.get(object, position); } throw new IllegalArgumentException("Cannot extract an element from class of type" + object.getClass() + " Collections and Arrays are supported only"); }
/** * Return a {@link CompoundPredicate}, possibly flattened if one or both arguments is an instance of * {@code CompoundPredicate}. */ static <T extends CompoundPredicate> T flattenCompound(Predicate predicateLeft, Predicate predicateRight, Class<T> klass) { // The following could have been achieved with {@link com.hazelcast.query.impl.predicates.FlatteningVisitor}, // however since we only care for 2-argument flattening, we can avoid constructing a visitor and its internals // for each token pass at the cost of the following explicit code. Predicate[] predicates; if (klass.isInstance(predicateLeft) || klass.isInstance(predicateRight)) { Predicate[] left = getSubPredicatesIfClass(predicateLeft, klass); Predicate[] right = getSubPredicatesIfClass(predicateRight, klass); predicates = new Predicate[left.length + right.length]; ArrayUtils.concat(left, right, predicates); } else { predicates = new Predicate[]{predicateLeft, predicateRight}; } try { CompoundPredicate compoundPredicate = klass.newInstance(); compoundPredicate.setPredicates(predicates); return (T) compoundPredicate; } catch (InstantiationException e) { throw new RuntimeException(String.format("%s should have a public default constructor", klass.getName())); } catch (IllegalAccessException e) { throw new RuntimeException(String.format("%s should have a public default constructor", klass.getName())); } }
private Predicate[] removeEliminatedPredicates(Predicate[] originalPredicates, int toBeRemoved) { if (toBeRemoved == 0) { return originalPredicates; } int newSize = originalPredicates.length - toBeRemoved; Predicate[] newPredicates = new Predicate[newSize]; ArrayUtils.copyWithoutNulls(originalPredicates, newPredicates); return newPredicates; }
@Override public OutboundPipeline addLast(OutboundHandler... addedHandlers) { checkNotNull(addedHandlers, "addedHandlers can't be null"); for (OutboundHandler addedHandler : addedHandlers) { addedHandler.setChannel(channel).handlerAdded(); } updatePipeline(append(handlers, addedHandlers)); return this; }
@Override public OutboundPipeline replace(OutboundHandler oldHandler, OutboundHandler... addedHandlers) { checkNotNull(oldHandler, "oldHandler can't be null"); checkNotNull(addedHandlers, "newHandler can't be null"); OutboundHandler[] newHandlers = replaceFirst(handlers, oldHandler, addedHandlers); if (newHandlers == handlers) { throw new IllegalArgumentException("handler " + oldHandler + " isn't part of the pipeline"); } for (OutboundHandler addedHandler : addedHandlers) { addedHandler.setChannel(channel).handlerAdded(); } updatePipeline(newHandlers); return this; }
/** * Removes an item from the array. * * If the item has been found, a new array is returned where this item is removed. Otherwise the original array is returned. * * @param src the src array * @param object the object to remove * @param <T> the type of the array * @return the resulting array */ public static <T> T[] remove(T[] src, T object) { int index = indexOf(src, object); if (index == -1) { return src; } T[] dst = (T[]) Array.newInstance(src.getClass().getComponentType(), src.length - 1); System.arraycopy(src, 0, dst, 0, index); if (index < src.length - 1) { System.arraycopy(src, index + 1, dst, index, src.length - index - 1); } return dst; }
private Object getItemAtPositionOrNull(Object object, int position) { if (object == null) { return null; } else if (object instanceof Collection) { return CollectionUtil.getItemAtPositionOrNull((Collection) object, position); } else if (object instanceof Object[]) { return ArrayUtils.getItemAtPositionOrNull((Object[]) object, position); } else if (object.getClass().isArray()) { return Array.get(object, position); } throw new IllegalArgumentException("Cannot extract an element from class of type" + object.getClass() + " Collections and Arrays are supported only"); }
/** * Return a {@link CompoundPredicate}, possibly flattened if one or both arguments is an instance of * {@code CompoundPredicate}. */ static <T extends CompoundPredicate> T flattenCompound(Predicate predicateLeft, Predicate predicateRight, Class<T> klass) { // The following could have been achieved with {@link com.hazelcast.query.impl.predicates.FlatteningVisitor}, // however since we only care for 2-argument flattening, we can avoid constructing a visitor and its internals // for each token pass at the cost of the following explicit code. Predicate[] predicates; if (klass.isInstance(predicateLeft) || klass.isInstance(predicateRight)) { Predicate[] left = getSubPredicatesIfClass(predicateLeft, klass); Predicate[] right = getSubPredicatesIfClass(predicateRight, klass); predicates = new Predicate[left.length + right.length]; ArrayUtils.concat(left, right, predicates); } else { predicates = new Predicate[]{predicateLeft, predicateRight}; } try { CompoundPredicate compoundPredicate = klass.newInstance(); compoundPredicate.setPredicates(predicates); return (T) compoundPredicate; } catch (InstantiationException e) { throw new RuntimeException(String.format("%s should have a public default constructor", klass.getName())); } catch (IllegalAccessException e) { throw new RuntimeException(String.format("%s should have a public default constructor", klass.getName())); } }
public ClassBlacklistFilter(String... blacklisted) { blacklist = ArrayUtils.createCopy(blacklisted); }
private static void boundsCheck(final byte[] buffer, final int index, final int length) { if (SHOULD_BOUNDS_CHECK) { ArrayUtils.boundsCheck(buffer.length, index, length); } } }
@Override public InboundPipeline addLast(InboundHandler... addedHandlers) { checkNotNull(addedHandlers, "handlers can't be null"); for (InboundHandler addedHandler : addedHandlers) { fixDependencies(addedHandler); addedHandler.setChannel(channel).handlerAdded(); } updatePipeline(append(handlers, addedHandlers)); return this; }
@Override public InboundPipeline replace(InboundHandler oldHandler, InboundHandler... addedHandlers) { checkNotNull(oldHandler, "oldHandler can't be null"); checkNotNull(addedHandlers, "addedHandlers can't be null"); InboundHandler[] newHandlers = replaceFirst(handlers, oldHandler, addedHandlers); if (newHandlers == handlers) { throw new IllegalArgumentException("handler " + oldHandler + " isn't part of the pipeline"); } for (InboundHandler addedHandler : addedHandlers) { fixDependencies(addedHandler); addedHandler.setChannel(channel).handlerAdded(); } updatePipeline(newHandlers); return this; }
/** * Replaces the first occurrence of the oldValue by the newValue. * * If the item is found, a new array is returned. Otherwise the original array is returned. * * @param src * @param oldValue the value to look for * @param newValues the value that is inserted. * @param <T> the type of the array * @return */ public static <T> T[] replaceFirst(T[] src, T oldValue, T[] newValues) { int index = indexOf(src, oldValue); if (index == -1) { return src; } T[] dst = (T[]) Array.newInstance(src.getClass().getComponentType(), src.length - 1 + newValues.length); // copy the first part till the match System.arraycopy(src, 0, dst, 0, index); // copy the second part from the match System.arraycopy(src, index + 1, dst, index + newValues.length, src.length - index - 1); // copy the newValues into the dst System.arraycopy(newValues, 0, dst, index, newValues.length); return dst; }
public static boolean isUnalignedAccessAllowed() { String currentArchitecture = System.getProperty("os.arch"); return ArrayUtils.contains(ARCHITECTURES_KNOWN_TO_ALLOW_UNALIGNED_ACCESS, currentArchitecture); } }