/** * Overloads the left shift operator to provide an easy way to append * objects to a Set. * <pre class="groovyTestCase">def set = [1,2] as Set * set << 3 * assert set == [1,2,3] as Set</pre> * * @param self a Set * @param value an Object to be added to the Set. * @return same Set, after the value was added to it. * @since 2.4.0 */ public static <T> Set<T> leftShift(Set<T> self, T value) { return (Set<T>) leftShift((Collection<T>) self, value); }
/** * Overloads the left shift operator to provide an easy way to append * objects to a List. * <pre class="groovyTestCase">def list = [1,2] * list << 3 * assert list == [1,2,3]</pre> * * @param self a List * @param value an Object to be added to the List. * @return same List, after the value was added to it. * @since 2.4.0 */ public static <T> List<T> leftShift(List<T> self, T value) { return (List<T>) leftShift((Collection<T>) self, value); }
/** * Overloads the left shift operator to provide an easy way to append * objects to a SortedSet. * <pre class="groovyTestCase">def set = [1,2] as SortedSet * set << 3 * assert set == [1,2,3] as SortedSet</pre> * * @param self a SortedSet * @param value an Object to be added to the SortedSet. * @return same SortedSet, after the value was added to it. * @since 2.4.0 */ public static <T> SortedSet<T> leftShift(SortedSet<T> self, T value) { return (SortedSet<T>) leftShift((Collection<T>) self, value); }
DefaultGroovyMethods.leftShift(buffer, (InputStream) parsedData); parsedData = new ByteArrayInputStream(buffer.toByteArray()); } else if (parsedData instanceof Reader) { StringWriter buffer = new StringWriter(); DefaultGroovyMethods.leftShift(buffer, (Reader) parsedData); parsedData = new StringReader(buffer.toString()); } else if (parsedData instanceof Closeable)
private static <K, V> void addEntry(Map<K, V> result, Object newEntry) { if (newEntry instanceof Map) { leftShift(result, (Map)newEntry); } else if (newEntry instanceof List) { List list = (List) newEntry; // def (key, value) == list Object key = list.isEmpty() ? null : list.get(0); Object value = list.size() <= 1 ? null : list.get(1); leftShift(result, new MapEntry(key, value)); } else if (newEntry.getClass().isArray()) { Object[] array = (Object[]) newEntry; // def (key, value) == array.toList() Object key = array.length == 0 ? null : array[0]; Object value = array.length <= 1 ? null : array[1]; leftShift(result, new MapEntry(key, value)); } else { // TODO: enforce stricter behavior? // given Map.Entry is an interface, we get a proxy which gives us lots // of flexibility but sometimes the error messages might be unexpected leftShift(result, asType(newEntry, Map.Entry.class)); } }
DefaultGroovyMethods.leftShift(out, (BufferedReader) data);
DefaultGroovyMethods.leftShift(out, (BufferedReader) data);
/** * Overloads the left shift operator to provide an append mechanism to * add things to the output stream of a socket * * @param self a Socket * @param value a value to append * @return a Writer * @throws IOException if an IOException occurs. */ public static Writer leftShift(Socket self, Object value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator to provide an append mechanism * to add bytes to the output stream of a socket * * @param self a Socket * @param value a value to append * @return an OutputStream * @throws IOException if an IOException occurs. */ public static OutputStream leftShift(Socket self, byte[] value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator (<<) to provide an append mechanism * to pipe data to a Process. * * @param self a Process instance * @param value a value to append * @return a Writer * @throws IOException if an IOException occurs. */ public static Writer leftShift(Process self, Object value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator to provide an append mechanism * to pipe into a Process * * @param self a Process instance * @param value data to append * @return an OutputStream * @throws IOException if an IOException occurs. */ public static OutputStream leftShift(Process self, byte[] value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator (<<) to provide an append mechanism * to pipe data to a Process. * * @param self a Process instance * @param value a value to append * @return a Writer * @throws IOException if an IOException occurs. * @since 1.0 */ public static Writer leftShift(Process self, Object value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator to provide an append mechanism to * add things to the output stream of a socket * * @param self a Socket * @param value a value to append * @return a Writer * @throws IOException if an IOException occurs. * @since 1.0 */ public static Writer leftShift(Socket self, Object value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator to provide an append mechanism * to add bytes to the output stream of a socket * * @param self a Socket * @param value a value to append * @return an OutputStream * @throws IOException if an IOException occurs. * @since 1.0 */ public static OutputStream leftShift(Socket self, byte[] value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator to provide an append mechanism * to pipe into a Process * * @param self a Process instance * @param value data to append * @return an OutputStream * @throws java.io.IOException if an IOException occurs. * @since 1.0 */ public static OutputStream leftShift(Process self, byte[] value) throws IOException { return DefaultGroovyMethods.leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator to provide an append mechanism * to add bytes to the output stream of a socket * * @param self a Socket * @param value a value to append * @return an OutputStream * @throws IOException if an IOException occurs. * @since 1.0 */ public static OutputStream leftShift(Socket self, byte[] value) throws IOException { return leftShift(self.getOutputStream(), value); }
/** * Overloads the left shift operator to provide an append mechanism * to add bytes to the output stream of a socket * * @param self a Socket * @param value a value to append * @return an OutputStream * @throws IOException if an IOException occurs. * @since 1.0 */ public static OutputStream leftShift(Socket self, byte[] value) throws IOException { return leftShift(self.getOutputStream(), value); }
private static <K, V> void addEntry(Map<K, V> result, Object newEntry) { if (newEntry instanceof Map) { leftShift(result, (Map)newEntry); } else if (newEntry instanceof List && ((List)newEntry).size() == 2) { List list = (List) newEntry; leftShift(result, new MapEntry(list.get(0), list.get(1))); } else { // TODO: enforce stricter behavior? // given Map.Entry is an interface, we get a proxy which gives us lots // of flexibility but sometimes the error messages might be unexpected leftShift(result, asType(newEntry, Map.Entry.class)); } }
/** * Overloads the leftShift operator to provide an append mechanism to add values to a stream. * * @param self an OutputStream * @param value a value to append * @return a Writer * @throws IOException if an I/O error occurs. */ public static Writer leftShift(OutputStream self, Object value) throws IOException { OutputStreamWriter writer = new FlushingStreamWriter(self); leftShift(writer, value); return writer; }