id
stringlengths
24
24
input
stringlengths
58
605
output
stringlengths
57
725
6367676d1a6d9265ec018229
/** * Trim the elements of the given String array, calling <code>String.trim()</code> on each of them. * @param array the original String array * @return the resulting array (of the same size) with trimmed elements */ public static String[] trimArrayElements(String[] array){
public static String[] trimArrayElements(String[] array){ if (Objects.isEmpty(array)) { return new String[0]; } String[] result=new String[array.length]; for (int i=0; i < array.length; i++) { String element=array[i]; result[i]=(element != null ? element.trim() : null); } return result; }
6367670b1a6d9265ec017a00
/** * <p>Checks whether two arrays are the same length, treating <code>null</code> arrays as length <code>0</code>.</p> * @param array1 the first array, may be <code>null</code> * @param array2 the second array, may be <code>null</code> * @return <code>true</code> if length of arrays matches, treating<code>null</c...
public static boolean isSameLength(final byte[] array1,final byte[] array2){ if (array1 == null && array2 != null && array2.length > 0 || array2 == null && array1 != null && array1.length > 0 || array1 != null && array2 != null && array1.length != array2.length) { return false; } return true; }
636766a91a6d9265ec0175c2
/** * Pops an abstract type from the output frame stack and returns its value. * @return the abstract type that has been popped from the output frame stack. */ private int pop(){
private int pop(){ if (outputStackTop > 0) { return outputStack[--outputStackTop]; } else { return STACK_KIND | -(--outputStackStart); } }
636767081a6d9265ec017989
/** * <p>Converts an array of object Booleans to primitives.</p> <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * @param array a <code>Boolean</code> array, may be <code>null</code> * @return a <code>boolean</code> array, <code>null</code> if null array input * @throws NullPoint...
public static boolean[] toPrimitive(final Boolean[] array){ if (array == null) { return null; } else if (array.length == 0) { return ArrayUtils.EMPTY_BOOLEAN_ARRAY; } final boolean[] result=new boolean[array.length]; for (int i=0; i < array.length; i++) { result[i]=array[i].booleanValue(); } ...
6367672d1a6d9265ec017c73
/** * Returns true if the message should be printed in the given timestamp, otherwise returns false. If this method returns false, the message will not be printed. The timestamp is in seconds granularity. */ public boolean shouldPrintMessage(int timestamp,String message){
public boolean shouldPrintMessage(int timestamp,String message){ if (messages.containsKey(message)) { if (timestamp - messages.get(message) >= 10) { messages.put(message,timestamp); return true; } else { return false; } } else { messages.put(message,timestamp); return true; ...
636766f81a6d9265ec01775c
/** * <p>Gets the <code>toString</code> of an <code>Object</code> returning an empty string ("") if <code>null</code> input.</p> <pre> ObjectUtils.toString(null) = "" ObjectUtils.toString("") = "" ObjectUtils.toString("bat") = "bat" ObjectUtils.toString(Boolean.TRUE) = "true" </pre> * @see S...
public static String toString(Object obj){ return obj == null ? "" : obj.toString(); }
6367667f1a6d9265ec017457
/** * Decodes octets to characters using the UTF-8 decoding and appends the characters to a StringBuffer. * @return the index to the next unchecked character in the string to decode */ private static int decodeOctets(int i,ByteBuffer bb,StringBuilder sb){
private static int decodeOctets(int i,ByteBuffer bb,StringBuilder sb){ if (bb.limit() == 1 && (bb.get(0) & 0xFF) < 0x80) { sb.append((char)bb.get(0)); return i + 2; } else { CharBuffer cb=UTF_8_CHARSET.decode(bb); sb.append(cb); return i + bb.limit() * 3 - 1; } }
636766aa1a6d9265ec0175ce
/** * Starts the visit of a new stack map frame, stored in {@link #currentFrame}. * @param offset the bytecode offset of the instruction to which the frame corresponds. * @param numLocal the number of local variables in the frame. * @param numStack the number of stack elements in the frame. * @return the index...
int visitFrameStart(final int offset,final int numLocal,final int numStack){ int frameLength=3 + numLocal + numStack; if (currentFrame == null || currentFrame.length < frameLength) { currentFrame=new int[frameLength]; } currentFrame[0]=offset; currentFrame[1]=numLocal; currentFrame[2]=numStack; return...
636767191a6d9265ec017c0f
/** * Enlarges this byte vector so that it can receive 'size' more bytes. * @param size number of additional bytes that this byte vector should be able to receive. */ private void enlarge(final int size){
private void enlarge(final int size){ int doubleCapacity=2 * data.length; int minimalCapacity=length + size; byte[] newData=new byte[doubleCapacity > minimalCapacity ? doubleCapacity : minimalCapacity]; System.arraycopy(data,0,newData,0,length); data=newData; }
636767821a6d9265ec0183a0
/** * Delete's the specified file if it exists */ protected static void deleteFile(String fileName){
protected static void deleteFile(String fileName){ File file=new File(fileName); if (file.exists()) { file.delete(); } }
636767691a6d9265ec0181aa
/** * Return a hash code based on the contents of the specified array. If <code>array</code> is <code>null</code>, this method returns 0. * @param array the long array to obtain a hashcode * @return the long array's hashcode, which could be 0 if the array is null. */ public static int nullSafeHashCode(long[] array...
public static int nullSafeHashCode(long[] array){ if (array == null) { return 0; } int hash=INITIAL_HASH; int arraySize=array.length; for (int i=0; i < arraySize; i++) { hash=MULTIPLIER * hash + hashCode(array[i]); } return hash; }
636767441a6d9265ec017cc1
/** * Performs a right node rotation. * @param node a node to rotate * @return a new parent of the {@code node} */ private TreeNode<T> rotateRight(TreeNode<T> node){
private TreeNode<T> rotateRight(TreeNode<T> node){ TreeNode<T> left=node.left; left.parent=null; node.setLeftChild(left.right); left.setRightChild(node); node.updateHeightAndSubtreeSize(); left.updateHeightAndSubtreeSize(); return left; }
6367667f1a6d9265ec01745c
/** * Add all the jar files in a dir to the classpath, represented as a Vector of URLs. */ @SuppressWarnings("unchecked") public static void addToClassPath(Vector<URL> cpV,String dir){
@SuppressWarnings("unchecked") public static void addToClassPath(Vector<URL> cpV,String dir){ try { String cpComp[]=getFilesByExt(dir,".jar"); if (cpComp != null) { int jarCount=cpComp.length; for (int i=0; i < jarCount; i++) { URL url=getURL(dir,cpComp[i]); if (url != null) ...
6367677e1a6d9265ec01830f
/** * Produces a formatted string as specified by the conversion pattern. */ public String format(LoggingEvent event){
public String format(LoggingEvent event){ if (sbuf.capacity() > MAX_CAPACITY) { sbuf=new StringBuffer(BUF_SIZE); } else { sbuf.setLength(0); } PatternConverter c=head; while (c != null) { c.format(sbuf,event); c=c.next; } return sbuf.toString(); }
636767031a6d9265ec0178dd
/** * Retrieve the content length of the request. * @return The content length of the request. * @since 1.3 */ public long contentLength(){
public long contentLength(){ long size; try { size=Long.parseLong(request.getHeader(FileUpload.CONTENT_LENGTH)); } catch ( NumberFormatException e) { size=request.getContentLength(); } return size; }
636766f11a6d9265ec017658
/** * Returns the index of the last directory separator character. <p> This method will handle a file in either Unix or Windows format. The position of the last forward or backslash is returned. <p> The output will be the same irrespective of the machine that the code is running on. * @param filename the filename t...
public static int indexOfLastSeparator(String filename){ if (filename == null) { return -1; } int lastUnixPos=filename.lastIndexOf(UNIX_SEPARATOR); int lastWindowsPos=filename.lastIndexOf(WINDOWS_SEPARATOR); return Math.max(lastUnixPos,lastWindowsPos); }
636767121a6d9265ec017b0a
/** * Skips bytes until the end of the current line. * @param headerPart The headers, which are being parsed. * @param end Index of the last byte, which has yet been processed. * @return Index of the \r\n sequence, which indicates end of line. */ private int parseEndOfLine(String headerPart,int end){
private int parseEndOfLine(String headerPart,int end){ int index=end; for (; ; ) { int offset=headerPart.indexOf('\r',index); if (offset == -1 || offset + 1 >= headerPart.length()) { throw new IllegalStateException("Expected headers to be terminated by an empty line."); } if (headerPart.charAt...
636766f61a6d9265ec017701
/** * Finds the last index within a String, handling <code>null</code>. This method uses {@link String#lastIndexOf(String)}. */ public static int lastIndexOf(String str,String searchStr){
public static int lastIndexOf(String str,String searchStr){ if (StringUtils.isEmpty(str)) { return StringUtils.INDEX_NOT_FOUND; } return str.lastIndexOf(searchStr); }
6367670b1a6d9265ec0179fe
/** * Writes <code>b.length</code> bytes from the specified byte array to this output stream. * @param b The array of bytes to be written. * @exception IOException if an error occurs. */ @Override public void write(byte b[]) throws IOException {
@Override public void write(byte b[]) throws IOException { checkThreshold(b.length); getStream().write(b); written+=b.length; }
636767df1a6d9265ec01873c
/** * @return the row id */ public String id(String entityId){
public String id(String entityId){ if (entityId == null) { return String.valueOf(point); } else { return point + Const.ID_CONNECTOR + entityId; } }
636766f91a6d9265ec01777f
/** * <p>Converts a Boolean to a boolean handling <code>null</code> by returning <code>false</code>.</p> <pre> BooleanUtils.toBoolean(Boolean.TRUE) = true BooleanUtils.toBoolean(Boolean.FALSE) = false BooleanUtils.toBoolean(null) = false </pre> * @param bool the boolean to convert * @return <code>true</c...
public static boolean toBoolean(Boolean bool){ if (bool == null) { return false; } return bool.booleanValue() ? true : false; }
6367675f1a6d9265ec0180d3
/** * Computes an identity automorphism (i.e. a self-mapping of a graph in which each vertex also maps to itself). * @param graph the input graph * @param < V > the graph vertex type * @param < E > the graph edge type * @return a mapping from graph to graph */ public static <V,E>IsomorphicGraphMapping<V,E> ident...
public static <V,E>IsomorphicGraphMapping<V,E> identity(Graph<V,E> graph){ Map<V,V> fMap=CollectionUtil.newHashMapWithExpectedSize(graph.vertexSet().size()); Map<V,V> bMap=CollectionUtil.newHashMapWithExpectedSize(graph.vertexSet().size()); for ( V v : graph.vertexSet()) { fMap.put(v,v); bMap.put(v,v); ...
636766fe1a6d9265ec017833
/** * Schedules a file to be deleted when JVM exits. If file is directory delete it and all sub-directories. * @param file file or directory to delete, must not be {@code null} * @throws NullPointerException if the file is {@code null} * @throws IOException in case deletion is unsuccessful */ public static void ...
public static void forceDeleteOnExit(File file) throws IOException { if (file.isDirectory()) { deleteDirectoryOnExit(file); } else { file.deleteOnExit(); } }
636767791a6d9265ec018257
/** * Add a log record message to be displayed in the LogTable. This method is thread-safe as it posts requests to the SwingThread rather than processing directly. */ public void addMessage(final LogRecord lr){
public void addMessage(final LogRecord lr){ if (_isDisposed == true) { return; } SwingUtilities.invokeLater(new Runnable(){ public void run(){ _categoryExplorerTree.getExplorerModel().addLogRecord(lr); _table.getFilteredLogTableModel().addLogRecord(lr); updateStatusLabel(); } } ); ...
636767641a6d9265ec01817d
/** * Construct a complete bipartite graph */ @Override public void generateGraph(Graph<V,E> target,Map<String,V> resultMap){
@Override public void generateGraph(Graph<V,E> target,Map<String,V> resultMap){ for (int i=0; i < sizeA; i++) { partitionA.add(target.addVertex()); } for (int i=0; i < sizeB; i++) { partitionB.add(target.addVertex()); } for ( V u : partitionA) { for ( V v : partitionB) { target.addEdge(u...
636766ff1a6d9265ec017851
/** * Searches for a byte of specified value in the <code>buffer</code>, starting at the specified <code>position</code>. * @param value The value to find. * @param pos The starting position for searching. * @return The position of byte found, counting from beginning of the<code>buffer</code>, or <code>-1</code>...
protected int findByte(byte value,int pos){ for (int i=pos; i < tail; i++) { if (buffer[i] == value) { return i; } } return -1; }
636767a41a6d9265ec018582
/** * Serializes the {@code message}, prefixed with its length, into an {@link OutputStream}. * @return the size of the message */ public static <T>int writeDelimitedTo(OutputStream out,T message,Schema<T> schema,LinkedBuffer buffer) throws IOException {
public static <T>int writeDelimitedTo(OutputStream out,T message,Schema<T> schema,LinkedBuffer buffer) throws IOException { if (buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtobufOutput output=new ProtobufOutput(buffer); schema.writ...
636767001a6d9265ec01787e
/** * <p> Gets the String built by this builder. </p> * @return the built string */ public String toString(){
public String toString(){ if (this.getObject() == null) { return this.getStyle().getNullText(); } Class<?> clazz=this.getObject().getClass(); this.appendFieldsIn(clazz); while (clazz.getSuperclass() != null && clazz != this.getUpToClass()) { clazz=clazz.getSuperclass(); this.appendFieldsIn(clazz);...
636767781a6d9265ec01823d
/** * This method does actual writing */ protected void subAppend(LoggingEvent event){
protected void subAppend(LoggingEvent event){ try { File tmp=File.createTempFile(prefix,suffix,dir); Writer out=new BufferedWriter(new FileWriter(tmp)); out.write(event.message); out.close(); } catch ( Exception e) { errorHandler.error("Error during creation of temporary File!",e,1); } }
636766ef1a6d9265ec01761a
/** * Adds a type in the type table of this symbol table. Does nothing if the type table already contains a similar type. * @param value an internal class name. * @return the index of a new or already existing type Symbol with the given value. */ int addType(final String value){
int addType(final String value){ int hashCode=hash(Symbol.TYPE_TAG,value); Entry entry=get(hashCode); while (entry != null) { if (entry.tag == Symbol.TYPE_TAG && entry.hashCode == hashCode && entry.value.equals(value)) { return entry.index; } entry=entry.next; } return addTypeInternal(new En...
636766821a6d9265ec0174b6
/** * Resolves the arguments for the {@code genericType} using the type variable information for the{@code targetType}. Returns {@code null} if {@code genericType} is not parameterized or ifarguments cannot be resolved. */ public static Class<?>[] resolveArguments(Type genericType,Class<?> targetType){
public static Class<?>[] resolveArguments(Type genericType,Class<?> targetType){ Class<?>[] result=null; if (genericType instanceof ParameterizedType) { ParameterizedType paramType=(ParameterizedType)genericType; Type[] arguments=paramType.getActualTypeArguments(); result=new Class[arguments.length]; ...
636767e11a6d9265ec018781
/** * Accept the data into the cache and merge with the existing value. This method is not thread safe, should avoid concurrency calling. * @param data to be added potentially. */ @Override public void accept(final METRICS data){
@Override public void accept(final METRICS data){ final String id=data.id(); final METRICS existed=buffer.get(id); if (existed == null) { buffer.put(id,data); } else { final boolean isAbandoned=!existed.combine(data); if (isAbandoned) { buffer.remove(id); } } }
636767531a6d9265ec017efb
/** * Inserts this bucket in the data structure before the {@code bucket}. * @param bucket the bucket, that will be the next to this bucket. */ void insertBefore(Bucket bucket){
void insertBefore(Bucket bucket){ this.next=bucket; if (bucket != null) { this.prev=bucket.prev; if (bucket.prev != null) { bucket.prev.next=this; } bucket.prev=this; } else { this.prev=null; } }
636766f11a6d9265ec017641
/** * @see InputStream#available() */ @Override public int available() throws IOException {
@Override public int available() throws IOException { return this.index < this.length ? this.length - this.index : this.length >= 0 && this.reader.ready() ? 1 : 0; }
636767de1a6d9265ec018706
/** * Returns mappings with fields that not exist in the input mappings. The input mappings should be history mapping from current index. Do not return _source config to avoid current index update conflict. */ public Mappings diffStructure(String tableName,Mappings mappings){
public Mappings diffStructure(String tableName,Mappings mappings){ if (!structures.containsKey(tableName)) { return new Mappings(); } Map<String,Object> properties=mappings.getProperties(); Map<String,Object> diffProperties=structures.get(tableName).diffFields(new Fields(mappings)); return Mappings.builde...
636767dd1a6d9265ec0186e5
/** * Add a new target channels. */ public void addNewTarget(Channels channels,IConsumer consumer){
public void addNewTarget(Channels channels,IConsumer consumer){ Group group=new Group(channels,consumer); ArrayList<Group> newList=new ArrayList<Group>(); for ( Group target : consumeTargets) { newList.add(target); } newList.add(group); consumeTargets=newList; size+=channels.size(); }
636767871a6d9265ec01846d
/** * Creates the directory where the MRU file list will be written. The "lf5" directory is created in the Documents and Settings directory on Windows 2000 machines and where ever the user.home variable points on all other platforms. */ public static void createConfigurationDirectory(){
public static void createConfigurationDirectory(){ String home=System.getProperty("user.home"); String sep=System.getProperty("file.separator"); File f=new File(home + sep + "lf5"); if (!f.exists()) { try { f.mkdir(); } catch ( SecurityException e) { e.printStackTrace(); } } }
636766f81a6d9265ec01775b
/** * Reads a signed long value in this {@link ClassReader}. <i>This method is intended for {@link Attribute} sub classes, and is normally not needed by class generators or adapters.</i> * @param offset the start offset of the value to be read in this {@link ClassReader}. * @return the read value. */ public long...
public long readLong(final int offset){ long l1=readInt(offset); long l0=readInt(offset + 4) & 0xFFFFFFFFL; return (l1 << 32) | l0; }
636767a51a6d9265ec01859d
/** * Returns true if the contents of the internal array and the provided array match. */ public boolean equals(final byte[] data,int offset,final int len){
public boolean equals(final byte[] data,int offset,final int len){ final byte[] bytes=this.bytes; if (len != bytes.length) return false; for (int i=0; i < len; ) { if (bytes[i++] != data[offset++]) { return false; } } return true; }
6367670b1a6d9265ec0179ff
/** * <p>Defensive programming technique to change a <code>null</code> reference to an empty one.</p> <p>This method returns an empty array for a <code>null</code> input array.</p> <p>As a memory optimizing technique an empty array passed in will be overridden with the empty <code>public static</code> references in t...
public static Byte[] nullToEmpty(final Byte[] array){ if (array == null || array.length == 0) { return ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY; } return array; }
6367677f1a6d9265ec018347
/** * sends a message to each of the clients in telnet-friendly output. */ public synchronized void send(final String message){
public synchronized void send(final String message){ Iterator ce=connections.iterator(); for (Iterator e=writers.iterator(); e.hasNext(); ) { ce.next(); PrintWriter writer=(PrintWriter)e.next(); writer.print(message); if (writer.checkError()) { ce.remove(); e.remove(); } } }
6367670a1a6d9265ec0179e8
/** * <p>Defensive programming technique to change a <code>null</code> reference to an empty one.</p> <p>This method returns an empty array for a <code>null</code> input array.</p> <p>As a memory optimizing technique an empty array passed in will be overridden with the empty <code>public static</code> references in t...
public static Boolean[] nullToEmpty(final Boolean[] array){ if (array == null || array.length == 0) { return ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY; } return array; }
6367677f1a6d9265ec01834b
/** * Place a {@link LoggingEvent} in the buffer. If the buffer is fullthen the event is <b>silently dropped</b>. It is the caller's responsability to make sure that the buffer has free space. */ public void put(LoggingEvent o){
public void put(LoggingEvent o){ if (numElements != maxSize) { buf[next]=o; if (++next == maxSize) { next=0; } numElements++; } }
636767df1a6d9265ec018744
/** * Split time ranges to insure the start time and end time is small then {@link #FETCH_DATA_DURATION} */ protected List<TimeRange> buildTimeRanges(long start,long end){
protected List<TimeRange> buildTimeRanges(long start,long end){ if (start >= end) { return null; } end+=1; final List<TimeRange> timeRanges=new ArrayList<>(); do { long batchEnd=Math.min(start + FETCH_DATA_DURATION,end); timeRanges.add(new TimeRange(start,batchEnd)); start=batchEnd; } while...
636767031a6d9265ec0178e6
/** * <p>Converts an array of object Bytes to primitives.</p> <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * @param array a <code>Byte</code> array, may be <code>null</code> * @return a <code>byte</code> array, <code>null</code> if null array input * @throws NullPointerExcepti...
public static byte[] toPrimitive(final Byte[] array){ if (array == null) { return null; } else if (array.length == 0) { return ArrayUtils.EMPTY_BYTE_ARRAY; } final byte[] result=new byte[array.length]; for (int i=0; i < array.length; i++) { result[i]=array[i].byteValue(); } return result; }...
636767dc1a6d9265ec0186be
/** * Follow the dayStep to re-format the time bucket literal long value. Such as, in dayStep == 11, 20000105 re-formatted time bucket is 20000101, 20000115 re-formatted time bucket is 20000112, 20000123 re-formatted time bucket is 20000123 */ static long compressTimeBucket(long timeBucket,int dayStep){
static long compressTimeBucket(long timeBucket,int dayStep){ if (dayStep > 1) { DateTime time=TIME_BUCKET_FORMATTER.parseDateTime("" + timeBucket); int days=Days.daysBetween(DAY_ONE,time).getDays(); int groupBucketOffset=days % dayStep; return Long.parseLong(time.minusDays(groupBucketOffset).toString(...
636767a41a6d9265ec01856c
/** * Computes the size of the utf8 string beginning at the specified {@code index} with the specified {@code length}. */ public static int computeUTF8Size(final CharSequence str,final int index,final int len){
public static int computeUTF8Size(final CharSequence str,final int index,final int len){ int size=len; for (int i=index; i < len; i++) { final char c=str.charAt(i); if (c < 0x0080) continue; if (c < 0x0800) size++; else size+=2; } return size; }
636766f01a6d9265ec017639
/** * Array to List. <p> Works like {@link Arrays#asList(Object)}, but handles null arrays. * @return a list backed by the array. */ public static <T>List<T> asList(T[] a){
public static <T>List<T> asList(T[] a){ if (a == null) return Collections.emptyList(); return Arrays.asList(a); }
6367672d1a6d9265ec017c74
/** * Removes a value from the set. Returns true if the set contained the specified element. */ public boolean remove(int val){
public boolean remove(int val){ if (map.containsKey(val)) { map.remove(val); values.remove(values.indexOf(val)); return true; } return false; }
6367676b1a6d9265ec0181df
/** * Returns {@code true} if the given string starts with the specified case-insensitive prefix, {@code false} otherwise. * @param str the String to check * @param prefix the prefix to look for * @return {@code true} if the given string starts with the specified case-insensitive prefix, {@code false} otherwise. ...
public static boolean startsWithIgnoreCase(String str,String prefix){ if (str == null || prefix == null) { return false; } if (str.startsWith(prefix)) { return true; } if (str.length() < prefix.length()) { return false; } String lcStr=str.substring(0,prefix.length()).toLowerCase(); String lc...
6367674b1a6d9265ec017dc0
/** * Compute all vertices that have positive degree by iterating over the edges on purpose. This keeps the complexity to $O(m)$ where $m$ is the number of edges. * @return set of vertices with positive degree */ private Set<V> initVisibleVertices(){
private Set<V> initVisibleVertices(){ Set<V> visibleVertex=new HashSet<>(); for ( E e : graph.edgeSet()) { V s=graph.getEdgeSource(e); V t=graph.getEdgeTarget(e); if (!s.equals(t)) { visibleVertex.add(s); visibleVertex.add(t); } } return visibleVertex; }
636767001a6d9265ec017873
/** * <p>Reverses a String as per {@link StringBuilder#reverse()}.</p> <p>A <code>null</code> String returns <code>null</code>.</p> <pre> StringUtils.reverse(null) = null StringUtils.reverse("") = "" StringUtils.reverse("bat") = "tab" </pre> * @param str the String to reverse, may be null * @return the revers...
public static String reverse(final String str){ if (str == null) { return null; } return new StringBuilder(str).reverse().toString(); }
636766ff1a6d9265ec01783b
/** * Gets a substring from the specified String avoiding exceptions. */ public static String sub(String str,int start,int end){
public static String sub(String str,int start,int end){ return StringUtils.substring(str,start,end); }
6367671a1a6d9265ec017c15
/** * Puts an array of bytes into this byte vector. The byte vector is automatically enlarged if necessary. * @param byteArrayValue an array of bytes. May be {@literal null} to put {@code byteLength} nullbytes into this byte vector. * @param byteOffset index of the first byte of byteArrayValue that must be copied. ...
public ByteVector putByteArray(final byte[] byteArrayValue,final int byteOffset,final int byteLength){ if (length + byteLength > data.length) { enlarge(byteLength); } if (byteArrayValue != null) { System.arraycopy(byteArrayValue,byteOffset,data,length,byteLength); } length+=byteLength; return this; ...
636766821a6d9265ec0174d2
/** * Wrap an {@link HttpServletRequest}. * @param request {@link HttpServletRequest} * @return an {@link AtmosphereRequest} */ public static AtmosphereRequest wrap(HttpServletRequest request){
public static AtmosphereRequest wrap(HttpServletRequest request){ if (AtmosphereRequestImpl.class.isAssignableFrom(request.getClass())) { return (AtmosphereRequestImpl)request; } Builder b=new Builder(); Enumeration<String> e=request.getAttributeNames(); String s; while (e.hasMoreElements()) { s=e.n...
636767ab1a6d9265ec01867b
/** * Writes the utf8-encoded bytes from the string into the {@link LinkedBuffer}. */ public static LinkedBuffer writeUTF8(final CharSequence str,final WriteSession session,final LinkedBuffer lb){
public static LinkedBuffer writeUTF8(final CharSequence str,final WriteSession session,final LinkedBuffer lb){ final int len=str.length(); if (len == 0) return lb; return lb.offset + len > lb.buffer.length ? writeUTF8(str,0,len,lb.buffer,lb.offset,lb.buffer.length,session,lb) : writeUTF8(str,0,len,session,lb); ...
6367675c1a6d9265ec01805b
/** * Removes this edge from both doubly linked lists of tree edges. */ public void removeFromTreeEdgeList(){
public void removeFromTreeEdgeList(){ for (int dir=0; dir < 2; dir++) { if (prev[dir] != null) { prev[dir].next[dir]=next[dir]; } else { head[1 - dir].first[dir]=next[dir]; } if (next[dir] != null) { next[dir].prev[dir]=prev[dir]; } } head[0]=head[1]=null; }
636767791a6d9265ec01826d
/** * Find the value corresponding to <code>key</code> in <code>props</code>. Then perform variable substitution on the found value. */ public static String findAndSubst(String key,Properties props){
public static String findAndSubst(String key,Properties props){ String value=props.getProperty(key); if (value == null) return null; try { return substVars(value,props); } catch ( IllegalArgumentException e) { LogLog.error("Bad option value [" + value + "].",e); return value; } }
636767001a6d9265ec01787f
/** * <p>Append to the <code>toString</code> the detail of an <code>int</code> array.</p> * @param buffer the <code>StringBuffer</code> to populate * @param fieldName the field name, typically not used as already appended * @param array the array to add to the <code>toString</code>,not <code>null</code> */ pro...
protected void appendDetail(StringBuffer buffer,String fieldName,int[] array){ buffer.append(arrayStart); for (int i=0; i < array.length; i++) { if (i > 0) { buffer.append(arraySeparator); } appendDetail(buffer,fieldName,array[i]); } buffer.append(arrayEnd); }
636766fe1a6d9265ec017834
/** * Session ID. */ public static String sessionId(){
public static String sessionId(){ HttpSession httpSession=servletSession(); if (httpSession == null) { return null; } return httpSession.getId(); }
636766ff1a6d9265ec01784b
/** * <p>Checks whether the <code>String</code> contains only digit characters.</p> <p><code>Null</code> and empty String will return <code>false</code>.</p> * @param str the <code>String</code> to check * @return <code>true</code> if str contains only unicode numeric */ public static boolean isDigits(String str)...
public static boolean isDigits(String str){ if ((str == null) || (str.length() == 0)) { return false; } for (int i=0; i < str.length(); i++) { if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
636766fc1a6d9265ec0177da
/** * Determine whether a parameter name ends at the current position, that is, whether the given character qualifies as a separator. */ private static boolean isParameterSeparator(final char c){
private static boolean isParameterSeparator(final char c){ if (Character.isWhitespace(c)) { return true; } for ( char separator : PARAMETER_SEPARATORS) { if (c == separator) { return true; } } return false; }
6367670c1a6d9265ec017a35
/** * <p>Check if a String ends with a specified suffix (optionally case insensitive).</p> * @see String#endsWith(String) * @param str the String to check, may be null * @param suffix the suffix to find, may be null * @param ignoreCase inidicates whether the compare should ignore case(case insensitive) or not. ...
private static boolean endsWith(final String str,final String suffix,final boolean ignoreCase){ if (str == null || suffix == null) { return str == null && suffix == null; } if (suffix.length() > str.length()) { return false; } int strOffset=str.length() - suffix.length(); return str.regionMatches(ig...
6367667f1a6d9265ec01745d
/** * Decode the path component of a URI as path segments. * @param u the URI. If the path component is an absolute path componentthen the leading '/' is ignored and is not considered a delimiator of a path segment. * @param decode true if the path segments of the path componentshould be in decoded form. * @return...
public static List<PathSegmentImpl> decodePath(URI u,boolean decode){ String rawPath=u.getRawPath(); if (rawPath != null && rawPath.length() > 0 && rawPath.charAt(0) == '/') { rawPath=rawPath.substring(1); } return decodePath(rawPath,decode); }
636766f11a6d9265ec017651
/** * <p>Defensive programming technique to change a <code>null</code> reference to an empty one.</p> <p>This method returns an empty array for a <code>null</code> input array.</p> <p>As a memory optimizing technique an empty array passed in will be overridden with the empty <code>public static</code> references in t...
public static Character[] nullToEmpty(final Character[] array){ if (array == null || array.length == 0) { return ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY; } return array; }
636767821a6d9265ec0183ab
/** * @return true if getThrown().toString() is a non-empty string. */ public boolean hasThrown(){
public boolean hasThrown(){ Throwable thrown=getThrown(); if (thrown == null) { return false; } String thrownString=thrown.toString(); return thrownString != null && thrownString.trim().length() != 0; }
636767831a6d9265ec0183c9
/** * Looks at the last diagnostic context at the top of this NDC without removing it. <p>The returned value is the value that was pushed last. If no context is available, then the empty string "" is returned. * @return String The innermost diagnostic context. */ public static String peek(){
public static String peek(){ Stack stack=getCurrentStack(); if (stack != null && !stack.isEmpty()) return ((DiagnosticContext)stack.peek()).message; else return ""; }
636767de1a6d9265ec01871c
/** * Accumulate the value with existing value in the same given key. */ public void valueAccumulation(String key,Long value){
public void valueAccumulation(String key,Long value){ Long element=data.get(key); if (element == null) { element=value; } else { element+=value; } data.put(key,element); }
636766811a6d9265ec017496
/** * Return the next {@link java.io.File} object or {@code null} if no more files areavailable. */ public InputStream next() throws IOException {
public InputStream next() throws IOException { if (stack.isEmpty()) { current=null; return null; } else { current=stack.removeLast(); return current; } }
6367677e1a6d9265ec01832e
/** * Check if the named logger exists in the hierarchy. If so return its reference, otherwise returns <code>null</code>. * @param name The name of the logger to search for. */ public Logger exists(String name){
public Logger exists(String name){ Object o=ht.get(new CategoryKey(name)); if (o instanceof Logger) { return (Logger)o; } else { return null; } }
6367670a1a6d9265ec0179e7
/** * Look up and return any registered {@link Converter} for the specifieddestination class; if there is no registered Converter, return <code>null</code>. * @param clazz Class for which to return a registered Converter * @return The registered {@link Converter} or <code>null</code> if not found */ public Conver...
public Converter lookup(final Class<?> clazz){ Converter conv=(Converter)this.converters.get(clazz); if (conv != null) { return conv; } for ( Object regType : this.converters.keySet()) { if (((Class<?>)regType).isAssignableFrom(clazz)) { return (Converter)this.converters.get(regType); } } ...
636767a41a6d9265ec018572
/** * Read a raw Varint from the stream. */ public long readRawVarint64() throws IOException {
public long readRawVarint64() throws IOException { int shift=0; long result=0; while (shift < 64) { final byte b=readRawByte(); result|=(long)(b & 0x7F) << shift; if ((b & 0x80) == 0) { return result; } shift+=7; } throw ProtobufException.malformedVarint(); }
636767021a6d9265ec0178bb
/** * <p>Defensive programming technique to change a <code>null</code> reference to an empty one.</p> <p>This method returns an empty array for a <code>null</code> input array.</p> <p>As a memory optimizing technique an empty array passed in will be overridden with the empty <code>public static</code> references in t...
public static Double[] nullToEmpty(final Double[] array){ if (array == null || array.length == 0) { return ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY; } return array; }
636767021a6d9265ec0178b2
/** * Pops as many abstract types from the output frame stack as described by the given descriptor. * @param descriptor a type or method descriptor (in which case its argument types are popped). */ private void pop(final String descriptor){
private void pop(final String descriptor){ char firstDescriptorChar=descriptor.charAt(0); if (firstDescriptorChar == '(') { pop((Type.getArgumentsAndReturnSizes(descriptor) >> 2) - 1); } else if (firstDescriptorChar == 'J' || firstDescriptorChar == 'D') { pop(2); } else { pop(1); } }
636766f91a6d9265ec01776e
/** * Writes <code>len</code> bytes from the specified byte array starting at offset <code>off</code> to this byte array output stream. * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. */ @Override public void write(final byte b[],final int off,final int...
@Override public void write(final byte b[],final int off,final int len) throws IOException { if (off < 0 || off > b.length || len < 0 || off + len > b.length || off + len < 0) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } if (this.count + len > this.buf.length) { this....
636767551a6d9265ec017f3f
/** * Swaps the two elements at the specified indices in the given array. * @param < V > the type of elements in the array * @param arr the array * @param i the index of the first element * @param j the index of the second element */ public static final <V>void swap(V[] arr,int i,int j){
public static final <V>void swap(V[] arr,int i,int j){ V tmp=arr[j]; arr[j]=arr[i]; arr[i]=tmp; }
636766ae1a6d9265ec0175dc
/** * Check if the actual response is a Partial Content (HTTP 206 code) * @return is partial content or not */ public Boolean isPartialContentResponse(){
public Boolean isPartialContentResponse(){ Integer limit=drc.getLimit() == null ? 0 : drc.getLimit(); Long count=drc.getCount() == null ? 0 : drc.getCount(); return !((limit + 1) >= count); }
636766f01a6d9265ec01762e
/** * <p>Checks if an array of primitive doubles is empty or <code>null</code>.</p> * @param array the array to test * @return <code>true</code> if the array is empty or <code>null</code> * @since 2.1 */ public static boolean isEmpty(final double[] array){
public static boolean isEmpty(final double[] array){ return array == null || array.length == 0; }
6367667e1a6d9265ec01743a
/** * The last time, in milliseconds, a write operation occurred. * @return this */ public long lastWriteTimeStampInMilliseconds(){
public long lastWriteTimeStampInMilliseconds(){ return lastWrite == -1 ? System.currentTimeMillis() : lastWrite; }
636767601a6d9265ec0180fd
/** * Add an edge to the index. * @param sourceVertex the source vertex * @param targetVertex the target vertex * @param e the edge */ protected void addToIndex(V sourceVertex,V targetVertex,E e){
protected void addToIndex(V sourceVertex,V targetVertex,E e){ Pair<V,V> vertexPair=new Pair<>(sourceVertex,targetVertex); Set<E> edgeSet=touchingVerticesToEdgeMap.get(vertexPair); if (edgeSet != null) edgeSet.add(e); else { edgeSet=edgeSetFactory.createEdgeSet(sourceVertex); edgeSet.add(e); touchin...
636766821a6d9265ec0174c9
/** * Returns the class path of the current JVM instance as an array of {@link File} objects. */ private static File[] classPath(){
private static File[] classPath(){ final String[] fileNames=System.getProperty("java.class.path").split(File.pathSeparator); final File[] files=new File[fileNames.length]; for (int i=0; i < files.length; ++i) { files[i]=new File(fileNames[i]); } return files; }
636767041a6d9265ec0178f8
/** * This method creates a copy of the provided array, and ensures that all the strings in the newly created array contain only lower-case letters. <p> Using this method to copy string arrays means that changes to the src array do not modify the dst array. */ private static String[] copyStrings(final String[] src){
private static String[] copyStrings(final String[] src){ String[] dst=new String[src.length]; for (int i=0; i < src.length; ++i) { dst[i]=src[i].toLowerCase(); } return dst; }
636767521a6d9265ec017ecc
/** * Split a box along the x axis into two equal boxes. * @param box the box to split * @return a pair with the two resulting boxes */ public static Pair<Box2D,Box2D> splitAlongXAxis(Box2D box){
public static Pair<Box2D,Box2D> splitAlongXAxis(Box2D box){ double newWidth=box.getWidth() / 2d; double height=box.getHeight(); return Pair.of(Box2D.of(box.getMinX(),box.getMinY(),newWidth,height),Box2D.of(box.getMinX() + newWidth,box.getMinY(),newWidth,height)); }
636766a91a6d9265ec0175c1
/** * Enlarges this byte vector so that it can receive 'size' more bytes. * @param size number of additional bytes that this byte vector should be able to receive. */ private void enlarge(final int size){
private void enlarge(final int size){ int doubleCapacity=2 * data.length; int minimalCapacity=length + size; byte[] newData=new byte[doubleCapacity > minimalCapacity ? doubleCapacity : minimalCapacity]; System.arraycopy(data,0,newData,0,length); data=newData; }
636767781a6d9265ec018238
/** * Returns <code>true</code> if the specified appender is in the list of attached appenders, <code>false</code> otherwise. * @since 1.2 */ public boolean isAttached(Appender appender){
public boolean isAttached(Appender appender){ if (appenderList == null || appender == null) return false; int size=appenderList.size(); Appender a; for (int i=0; i < size; i++) { a=(Appender)appenderList.elementAt(i); if (a == appender) return true; } return false; }
6367674a1a6d9265ec017dab
/** * Compares two floating point values. Returns 0 if they are equal, -1 if {@literal o1 < o2}, 1 otherwise * @param o1 the first value * @param o2 the second value * @return 0 if they are equal, -1 if {@literal o1 < o2}, 1 otherwise */ @Override public int compare(Double o1,Double o2){
@Override public int compare(Double o1,Double o2){ if (Math.abs(o1 - o2) < epsilon) { return 0; } else { return Double.compare(o1,o2); } }
6367672d1a6d9265ec017c78
/** * Inserts a value to the set. Returns true if the set did not already contain the specified element. */ public boolean insert(int val){
public boolean insert(int val){ if (!map.containsKey(val)) { map.put(val,val); values.add(val); return true; } else { return false; } }
636767dc1a6d9265ec0186c6
/** * Returns ture when the input fields have already been stored in the properties. */ private boolean containsAllFields(Fields fields){
private boolean containsAllFields(Fields fields){ if (this.properties.size() < fields.properties.size()) { return false; } boolean isContains=fields.properties.entrySet().stream().allMatch(item -> Objects.equals(properties.get(item.getKey()),item.getValue())); if (!isContains) { return false; } retu...
636766821a6d9265ec0174bf
/** * Reverse of Introspector.decapitalize */ public static String capitalize(String name){
public static String capitalize(String name){ if (name == null || name.length() == 0) { return name; } char chars[]=name.toCharArray(); chars[0]=Character.toUpperCase(chars[0]); return new String(chars); }
636767aa1a6d9265ec01865a
/** * Writes the contents of the {@link LinkedBuffer} into the {@link DataOutput}. * @return the total content size of the buffer. */ public static int writeTo(final DataOutput out,LinkedBuffer node) throws IOException {
public static int writeTo(final DataOutput out,LinkedBuffer node) throws IOException { int contentSize=0, len; do { if ((len=node.offset - node.start) > 0) { out.write(node.buffer,node.start,len); contentSize+=len; } } while ((node=node.next) != null); return contentSize; }
636766f21a6d9265ec017677
/** * <p>Checks if a <code>Boolean</code> value is <i>not</i> <code>true</code>, handling <code>null</code> by returning <code>true</code>.</p> <pre> BooleanUtils.isNotTrue(Boolean.TRUE) = false BooleanUtils.isNotTrue(Boolean.FALSE) = true BooleanUtils.isNotTrue(null) = true </pre> * @param bool the boole...
public static boolean isNotTrue(Boolean bool){ return !isTrue(bool); }
6367674f1a6d9265ec017e74
/** * Returns a textual representation of the queue. * @return a textual representation of the queue. */ public String toString(){
public String toString(){ StringBuilder s=new StringBuilder(); for (int j=i; j < n; j++) s.append(vs[j]).append(" "); return s.toString(); }
6367675c1a6d9265ec018058
/** * Create a string supplier which returns unique strings. The returns strings are simply integers starting from start. * @param start where to start the sequence * @return a string supplier */ @SuppressWarnings("unchecked") public static Supplier<String> createStringSupplier(int start){
@SuppressWarnings("unchecked") public static Supplier<String> createStringSupplier(int start){ int[] container=new int[]{start}; return (Supplier<String> & Serializable)() -> String.valueOf(container[0]++); }
6367677b1a6d9265ec0182bd
/** * Formats a logging event to a writer. * @param event logging event to be formatted. */ public String format(final LoggingEvent event){
public String format(final LoggingEvent event){ StringBuffer buf=new StringBuffer(); for (PatternConverter c=head; c != null; c=c.next) { c.format(buf,event); } return buf.toString(); }
636766ff1a6d9265ec017842
/** * <p>Converts an array of object Doubles to primitives.</p> <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * @param array a <code>Double</code> array, may be <code>null</code> * @return a <code>double</code> array, <code>null</code> if null array input * @throws NullPointerE...
public static double[] toPrimitive(final Double[] array){ if (array == null) { return null; } else if (array.length == 0) { return ArrayUtils.EMPTY_DOUBLE_ARRAY; } final double[] result=new double[array.length]; for (int i=0; i < array.length; i++) { result[i]=array[i].doubleValue(); } retu...
636766fa1a6d9265ec0177a9
/** * Adds an abstract type to the list of types on which a constructor is invoked in the basic block. * @param abstractType an abstract type on a which a constructor is invoked. */ private void addInitializedType(final int abstractType){
private void addInitializedType(final int abstractType){ if (initializations == null) { initializations=new int[2]; } int initializationsLength=initializations.length; if (initializationCount >= initializationsLength) { int[] newInitializations=new int[Math.max(initializationCount + 1,2 * initialization...
6367670a1a6d9265ec0179dc
/** * Puts some abstract types of {@link #currentFrame} in {@link #stackMapTableEntries} , using theJVMS verification_type_info format used in StackMapTable attributes. * @param start index of the first type in {@link #currentFrame} to write. * @param end index of last type in {@link #currentFrame} to write (exclu...
private void putAbstractTypes(final int start,final int end){ for (int i=start; i < end; ++i) { Frame.putAbstractType(symbolTable,currentFrame[i],stackMapTableEntries); } }
636766801a6d9265ec017482
/** * Clear and fill the buffer of this {@code ClassFileBuffer} with thesupplied byte stream. The read pointer is reset to the start of the byte array. */ public void readFrom(final InputStream in) throws IOException {
public void readFrom(final InputStream in) throws IOException { pointer=0; size=0; int n; do { n=in.read(buffer,size,buffer.length - size); if (n > 0) { size+=n; } resizeIfNeeded(); } while (n >= 0); }
6367670a1a6d9265ec0179d8
/** * @see OutputStream#write(byte[]) */ @Override public void write(final byte[] b) throws IOException {
@Override public void write(final byte[] b) throws IOException { if (this.encoding == null) { this.writer.write(new String(b)); } else { this.writer.write(new String(b,this.encoding)); } }
636766a81a6d9265ec01757b
/** * Serialize to JSON {@link String} * @param features features to be enabled in serialization * @return JSON {@link String} */ @SuppressWarnings("unchecked") public String toString(JSONWriter.Feature... features){
@SuppressWarnings("unchecked") public String toString(JSONWriter.Feature... features){ try (JSONWriter writer=JSONWriter.of(features)){ if ((writer.context.features & NONE_DIRECT_FEATURES) == 0) { writer.write(this); } else { writer.setRootObject(this); if (arrayWriter == null) { ar...