On Thu, Jan 23, 2014 at 2:03 AM, Benedikt Ritter <brit...@apache.org> wrote:
> I personally don't like alphabetically sorted classes. For example if a > public method calls a private method, I like to have the private method > beneath the public method that uses it. This way I can read through a claa > top to bottom without out to much jumping back and forth. But that's just a > matter of taste, I guess. > > What do others think? > That requires way to much thinking (! ;) when writing code IMO especially during refactoring. Whenever I create a method I have to go through some additional process to decide where in the file the method can live, bleh, depending on the visibility of the method and who uses it, yikes. What I like best about AB order is that it is predictable, and easy to maintain (by the IDE), requiring no additional work. When I used to build Smalltalk IDEs, we had a structure called the method dictionary, which is what a class definition contained, I guess I just think of a class file as a method dictionary. Later, we had an other layer in the IDE for method _categories_ which let you organize methods into groups for editing (this is different from the interface concept). Methods in classes or in categories were always in AB order. Old dog, old tricks perhaps ;) Gary > > Benedikt > > 2014/1/22 <ggreg...@apache.org> > > > Author: ggregory > > Date: Wed Jan 22 15:25:22 2014 > > New Revision: 1560382 > > > > URL: http://svn.apache.org/r1560382 > > Log: > > Sort methods. > > > > Modified: > > > > > commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java > > > > Modified: > > > commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java > > URL: > > > http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java?rev=1560382&r1=1560381&r2=1560382&view=diff > > > > > ============================================================================== > > --- > > > commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java > > (original) > > +++ > > > commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java > > Wed Jan 22 15:25:22 2014 > > @@ -68,15 +68,10 @@ public final class CSVPrinter implements > > // printing implementation > > // ====================================================== > > > > - /** > > - * Outputs the record separator. > > - * > > - * @throws IOException > > - * If an I/O error occurs > > - */ > > - public void println() throws IOException { > > - out.append(format.getRecordSeparator()); > > - newRecord = true; > > + public void close() throws IOException { > > + if (out instanceof Closeable) { > > + ((Closeable) out).close(); > > + } > > } > > > > /** > > @@ -92,77 +87,23 @@ public final class CSVPrinter implements > > } > > > > /** > > - * Prints a single line of delimiter separated values. The values > > will be quoted if needed. Quotes and newLine > > - * characters will be escaped. > > - * > > - * @param values > > - * values to output. > > - * @throws IOException > > - * If an I/O error occurs > > - */ > > - public void printRecord(final Object... values) throws IOException { > > - for (final Object value : values) { > > - print(value); > > - } > > - println(); > > - } > > - > > - /** > > - * Prints a single line of delimiter separated values. The values > > will be quoted if needed. Quotes and newLine > > - * characters will be escaped. > > - * > > - * @param values > > - * values to output. > > - * @throws IOException > > - * If an I/O error occurs > > - */ > > - public void printRecord(final Iterable<?> values) throws > IOException { > > - for (final Object value : values) { > > - print(value); > > - } > > - println(); > > - } > > - > > - /** > > - * Prints a comment on a new line among the delimiter separated > > values. Comments will always begin on a new line > > - * and occupy a least one full line. The character specified to > start > > comments and a space will be inserted at the > > - * beginning of each new line in the comment. > > - * <p/> > > - * If comments are disabled in the current CSV format this method > > does nothing. > > + * Prints the string as the next value on the line. The value will > be > > escaped or encapsulated as needed. > > * > > - * @param comment > > - * the comment to output > > + * @param value > > + * value to be output. > > * @throws IOException > > * If an I/O error occurs > > */ > > - public void printComment(final String comment) throws IOException { > > - if (!format.isCommentingEnabled()) { > > - return; > > - } > > - if (!newRecord) { > > - println(); > > - } > > - out.append(format.getCommentStart().charValue()); > > - out.append(SP); > > - for (int i = 0; i < comment.length(); i++) { > > - final char c = comment.charAt(i); > > - switch (c) { > > - case CR: > > - if (i + 1 < comment.length() && comment.charAt(i + 1) == > > LF) { > > - i++; > > - } > > - //$FALL-THROUGH$ break intentionally excluded. > > - case LF: > > - println(); > > - out.append(format.getCommentStart().charValue()); > > - out.append(SP); > > - break; > > - default: > > - out.append(c); > > - break; > > - } > > + public void print(final Object value) throws IOException { > > + // null values are considered empty > > + String strValue; > > + if (value == null) { > > + final String nullString = format.getNullString(); > > + strValue = nullString == null ? Constants.EMPTY : > nullString; > > + } else { > > + strValue = value.toString(); > > } > > - println(); > > + this.print(value, strValue, 0, strValue.length()); > > } > > > > private void print(final Object object, final CharSequence value, > > @@ -332,34 +273,99 @@ public final class CSVPrinter implements > > } > > > > /** > > - * Prints the string as the next value on the line. The value will > be > > escaped or encapsulated as needed. > > + * Prints a comment on a new line among the delimiter separated > > values. Comments will always begin on a new line > > + * and occupy a least one full line. The character specified to > start > > comments and a space will be inserted at the > > + * beginning of each new line in the comment. > > + * <p/> > > + * If comments are disabled in the current CSV format this method > > does nothing. > > * > > - * @param value > > - * value to be output. > > + * @param comment > > + * the comment to output > > * @throws IOException > > * If an I/O error occurs > > */ > > - public void print(final Object value) throws IOException { > > - // null values are considered empty > > - String strValue; > > - if (value == null) { > > - final String nullString = format.getNullString(); > > - strValue = nullString == null ? Constants.EMPTY : > nullString; > > - } else { > > - strValue = value.toString(); > > + public void printComment(final String comment) throws IOException { > > + if (!format.isCommentingEnabled()) { > > + return; > > } > > - this.print(value, strValue, 0, strValue.length()); > > + if (!newRecord) { > > + println(); > > + } > > + out.append(format.getCommentStart().charValue()); > > + out.append(SP); > > + for (int i = 0; i < comment.length(); i++) { > > + final char c = comment.charAt(i); > > + switch (c) { > > + case CR: > > + if (i + 1 < comment.length() && comment.charAt(i + 1) == > > LF) { > > + i++; > > + } > > + //$FALL-THROUGH$ break intentionally excluded. > > + case LF: > > + println(); > > + out.append(format.getCommentStart().charValue()); > > + out.append(SP); > > + break; > > + default: > > + out.append(c); > > + break; > > + } > > + } > > + println(); > > } > > > > /** > > - * Prints all the objects in the given array. > > + * Outputs the record separator. > > + * > > + * @throws IOException > > + * If an I/O error occurs > > + */ > > + public void println() throws IOException { > > + out.append(format.getRecordSeparator()); > > + newRecord = true; > > + } > > + > > + /** > > + * Prints a single line of delimiter separated values. The values > > will be quoted if needed. Quotes and newLine > > + * characters will be escaped. > > + * > > + * @param values > > + * values to output. > > + * @throws IOException > > + * If an I/O error occurs > > + */ > > + public void printRecord(final Iterable<?> values) throws > IOException { > > + for (final Object value : values) { > > + print(value); > > + } > > + println(); > > + } > > + > > + /** > > + * Prints a single line of delimiter separated values. The values > > will be quoted if needed. Quotes and newLine > > + * characters will be escaped. > > + * > > + * @param values > > + * values to output. > > + * @throws IOException > > + * If an I/O error occurs > > + */ > > + public void printRecord(final Object... values) throws IOException { > > + for (final Object value : values) { > > + print(value); > > + } > > + println(); > > + } > > + > > + /** > > + * Prints all the objects in the given collection. > > * > > * @param values > > * the values to print. > > * @throws IOException > > * If an I/O error occurs > > */ > > - public void printRecords(final Object[] values) throws IOException { > > + public void printRecords(final Iterable<?> values) throws > IOException > > { > > for (final Object value : values) { > > if (value instanceof Object[]) { > > this.printRecord((Object[]) value); > > @@ -372,14 +378,14 @@ public final class CSVPrinter implements > > } > > > > /** > > - * Prints all the objects in the given collection. > > + * Prints all the objects in the given array. > > * > > * @param values > > * the values to print. > > * @throws IOException > > * If an I/O error occurs > > */ > > - public void printRecords(final Iterable<?> values) throws > IOException > > { > > + public void printRecords(final Object[] values) throws IOException { > > for (final Object value : values) { > > if (value instanceof Object[]) { > > this.printRecord((Object[]) value); > > @@ -409,10 +415,4 @@ public final class CSVPrinter implements > > println(); > > } > > } > > - > > - public void close() throws IOException { > > - if (out instanceof Closeable) { > > - ((Closeable) out).close(); > > - } > > - } > > } > > > > > > > > > -- > http://people.apache.org/~britter/ > http://www.systemoutprintln.de/ > http://twitter.com/BenediktRitter > http://github.com/britter > -- E-Mail: garydgreg...@gmail.com | ggreg...@apache.org Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory