Skip to content

Commit

Permalink
fixes indentation and other whitespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-wayne committed May 22, 2018
1 parent cb30d57 commit 880a556
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/main/java/edu/princeton/cs/algs4/Bipartite.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Given a graph, find either (i) a bipartition or (ii) an odd-length cycle.
* Runs in O(E + V) time.
*
*
******************************************************************************/

package edu.princeton.cs.algs4;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/princeton/cs/algs4/CollisionSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @author Kevin Wayne
*/
public class CollisionSystem {
private final static double HZ = 0.5; // number of redraw events per clock tick
private static final double HZ = 0.5; // number of redraw events per clock tick

private MinPQ<Event> pq; // the priority queue
private double t = 0.0; // simulation clock time
Expand Down
1 change: 0 additions & 1 deletion src/main/java/edu/princeton/cs/algs4/DoublingRatio.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* 4000 4.5 8.0
* 8000 35.7 8.0
* 4000 3.9 6.6
* ...
*
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/princeton/cs/algs4/GrahamScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public GrahamScan(Point2D[] points) {
if (points[i] == null)
throw new IllegalArgumentException("points[" + i + "] is null");
a[i] = points[i];
}
}

// preprocess so that a[0] has lowest y-coordinate; break ties by x-coordinate
// a[0] is an extreme point of the convex hull
Expand Down
48 changes: 32 additions & 16 deletions src/main/java/edu/princeton/cs/algs4/In.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ public char readChar() {
return ch.charAt(0);
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'char' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'char' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand Down Expand Up @@ -329,7 +330,8 @@ public String readString() {
return scanner.next();
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'String' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'String' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand All @@ -347,10 +349,12 @@ public int readInt() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read an 'int' value from input stream, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read an 'int' value from the input stream, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attemps to read an 'int' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attemps to read an 'int' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand All @@ -368,10 +372,12 @@ public double readDouble() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'double' value from input stream, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'double' value from the input stream, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attemps to read a 'double' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attemps to read a 'double' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand All @@ -389,10 +395,12 @@ public float readFloat() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'float' value from input stream, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'float' value from the input stream, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attemps to read a 'float' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attemps to read a 'float' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand All @@ -410,10 +418,12 @@ public long readLong() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'long' value from input stream, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'long' value from the input stream, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attemps to read a 'long' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attemps to read a 'long' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand All @@ -431,10 +441,12 @@ public short readShort() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'short' value from input stream, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'short' value from the input stream, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attemps to read a 'short' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attemps to read a 'short' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand All @@ -454,10 +466,12 @@ public byte readByte() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'byte' value from input stream, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'byte' value from the input stream, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attemps to read a 'byte' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attemps to read a 'byte' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand All @@ -477,10 +491,12 @@ public boolean readBoolean() {
if ("false".equalsIgnoreCase(token)) return false;
if ("1".equals(token)) return true;
if ("0".equals(token)) return false;
throw new InputMismatchException("attempts to read a 'boolean' value from input stream, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'boolean' value from the input stream, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'boolean' value from input stream, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'boolean' value from the input stream, "
+ "but no more tokens are available");
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/edu/princeton/cs/algs4/Picture.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,16 @@ public int hashCode() {
}

/**
* Saves the picture to a file in a standard image format.
* The filetype must be .png or .jpg.
* Saves the picture to a file in either PNG or JPEG format.
* The filetype extension must be either .png or .jpg.
*
* @param filename the name of the file
* @param name the name of the file
* @throws IllegalArgumentException if {@code name} is {@code null}
*/
public void save(String filename) {
if (filename == null) throw new IllegalArgumentException("argument to save() is null");
save(new File(filename));
public void save(String name) {
if (name == null) throw new IllegalArgumentException("argument to save() is null");
save(new File(name));
filename = name;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/edu/princeton/cs/algs4/Polynomial.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public String toString() {
String s = coef[degree] + "x^" + degree;
for (int i = degree - 1; i >= 0; i--) {
if (coef[i] == 0) continue;
else if (coef[i] > 0) s = s + " + " + ( coef[i]);
else if (coef[i] > 0) s = s + " + " + (coef[i]);
else if (coef[i] < 0) s = s + " - " + (-coef[i]);
if (i == 1) s = s + "x";
else if (i > 1) s = s + "x^" + i;
Expand Down Expand Up @@ -262,8 +262,7 @@ public static void main(String[] args) {
StdOut.println("p(3) = " + p.evaluate(3));
StdOut.println("p'(x) = " + p.differentiate());
StdOut.println("p''(x) = " + p.differentiate().differentiate());
}

}
}

/******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/princeton/cs/algs4/RectHV.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public RectHV(double xmin, double ymin, double xmax, double ymax) {
if (Double.isNaN(ymin) || Double.isNaN(ymax)) {
throw new IllegalArgumentException("y-coordinate is NaN: " + toString());
}
if (xmax < xmin) {
if (xmax < xmin) {
throw new IllegalArgumentException("xmax < xmin: " + toString());
}
if (ymax < ymin) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/princeton/cs/algs4/StdAudio.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static synchronized void play(final String filename) {
public void run() {
stream(filename);
}
}).start();
}).start();
}

// let's try Applet.newAudioClip() instead
Expand All @@ -298,7 +298,7 @@ private static void playApplet(String filename) {
URL url = null;
try {
File file = new File(filename);
if(file.canRead()) url = file.toURI().toURL();
if (file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) {
throw new IllegalArgumentException("could not play '" + filename + "'", e);
Expand Down
48 changes: 32 additions & 16 deletions src/main/java/edu/princeton/cs/algs4/StdIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ public static char readChar() {
return ch.charAt(0);
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'char' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'char' value from standard input, "
+ "but no more tokens are available");
}
}

Expand Down Expand Up @@ -339,7 +340,8 @@ public static String readString() {
return scanner.next();
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'String' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'String' value from standard input, "
+ "but no more tokens are available");
}
}

Expand All @@ -356,10 +358,12 @@ public static int readInt() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read an 'int' value from standard input, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read an 'int' value from standard input, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attemps to read an 'int' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attemps to read an 'int' value from standard input, "
+ "but no more tokens are available");
}

}
Expand All @@ -377,10 +381,12 @@ public static double readDouble() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'double' value from standard input, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'double' value from standard input, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'double' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'double' value from standard input, "
+ "but no more tokens are available");
}
}

Expand All @@ -397,10 +403,12 @@ public static float readFloat() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'float' value from standard input, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'float' value from standard input, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'float' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'float' value from standard input, "
+ "but there no more tokens are available");
}
}

Expand All @@ -417,10 +425,12 @@ public static long readLong() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'long' value from standard input, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'long' value from standard input, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'long' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'long' value from standard input, "
+ "but no more tokens are available");
}
}

Expand All @@ -437,10 +447,12 @@ public static short readShort() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'short' value from standard input, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'short' value from standard input, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'short' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'short' value from standard input, "
+ "but no more tokens are available");
}
}

Expand All @@ -457,10 +469,12 @@ public static byte readByte() {
}
catch (InputMismatchException e) {
String token = scanner.next();
throw new InputMismatchException("attempts to read a 'byte' value from standard input, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'byte' value from standard input, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'byte' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'byte' value from standard input, "
+ "but no more tokens are available");
}
}

Expand All @@ -481,10 +495,12 @@ public static boolean readBoolean() {
if ("false".equalsIgnoreCase(token)) return false;
if ("1".equals(token)) return true;
if ("0".equals(token)) return false;
throw new InputMismatchException("attempts to read a 'boolean' value from standard input, but the next token is \"" + token + "\"");
throw new InputMismatchException("attempts to read a 'boolean' value from standard input, "
+ "but the next token is \"" + token + "\"");
}
catch (NoSuchElementException e) {
throw new NoSuchElementException("attempts to read a 'boolean' value from standard input, but there are no more tokens available");
throw new NoSuchElementException("attempts to read a 'boolean' value from standard input, "
+ "but no more tokens are available");
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/princeton/cs/algs4/SymbolDigraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public Digraph digraph() {

// throw an IllegalArgumentException unless {@code 0 <= v < V}
private void validateVertex(int v) {
int V = graph.V();
int V = graph.V();
if (v < 0 || v >= V)
throw new IllegalArgumentException("vertex " + v + " is not between 0 and " + (V-1));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/princeton/cs/algs4/SymbolGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Graph graph() {

// throw an IllegalArgumentException unless {@code 0 <= v < V}
private void validateVertex(int v) {
int V = graph.V();
int V = graph.V();
if (v < 0 || v >= V)
throw new IllegalArgumentException("vertex " + v + " is not between 0 and " + (V-1));
}
Expand Down

0 comments on commit 880a556

Please sign in to comment.