Skip to content

Commit

Permalink
Reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed May 4, 2017
1 parent 16a9ab9 commit b99394e
Show file tree
Hide file tree
Showing 20 changed files with 414 additions and 812 deletions.
22 changes: 7 additions & 15 deletions runner/src/main/java/com/widen/tabitha/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@
import java.io.IOException;
import java.io.InputStream;

public class Runner
{
public class Runner {
private static File scriptFile;

public static void main(String[] args) throws IOException
{
for (String arg : args)
{
if (arg.equals("-h") || arg.equals("--help") || arg.equals("-?") || arg.equals("/?"))
{
public static void main(String[] args) throws IOException {
for (String arg : args) {
if (arg.equals("-h") || arg.equals("--help") || arg.equals("-?") || arg.equals("/?")) {
printHelp();
return;
}
else
{
} else {
scriptFile = new File(arg);
break;
}
Expand All @@ -32,15 +26,13 @@ public static void main(String[] args) throws IOException
execute();
}

private static void printHelp() throws IOException
{
private static void printHelp() throws IOException {
InputStream inputStream = Runner.class.getClassLoader().getResourceAsStream("Help.txt");
String text = IOUtils.toString(inputStream, "UTF-8");
System.out.println(text);
}

private static void execute() throws IOException
{
private static void execute() throws IOException {
ImportCustomizer importCustomizer = new ImportCustomizer();
importCustomizer.addStarImports("com.widen.tabitha");
importCustomizer.addStarImports("com.widen.tabitha.formats");
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/widen/tabitha/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/**
* A column in a schema.
*/
public final class Column
{
public final class Column {
/**
* The name of the column.
*/
Expand All @@ -15,19 +14,16 @@ public final class Column
*
* @param name The column name.
*/
Column(String name)
{
if (name == null)
{
Column(String name) {
if (name == null) {
throw new NullPointerException();
}

this.name = name.intern();
}

@Override
public String toString()
{
public String toString() {
return name;
}
}
87 changes: 28 additions & 59 deletions src/main/java/com/widen/tabitha/DataFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* contain different columns than each other and there is no way for a data frame to know all the possible columns it
* may contain.
*/
public class DataFrame implements Iterable<Row>, Closeable
{
public class DataFrame implements Iterable<Row>, Closeable {
private final RingBuffer<Row> rows;
private RowReader rowReader;

Expand All @@ -30,8 +29,7 @@ public class DataFrame implements Iterable<Row>, Closeable
* @param rowReader The row reader used to stream in data.
* @return A new data frame.
*/
public static DataFrame streaming(RowReader rowReader)
{
public static DataFrame streaming(RowReader rowReader) {
DataFrame dataFrame = new DataFrame();
dataFrame.rowReader = rowReader;

Expand All @@ -41,8 +39,7 @@ public static DataFrame streaming(RowReader rowReader)
/**
* Create a new in-memory data frame.
*/
public DataFrame()
{
public DataFrame() {
rows = new RingBuffer<>();
rowReader = null;
}
Expand All @@ -52,8 +49,7 @@ public DataFrame()
*
* @param rows The rows to put in the data frame.
*/
public DataFrame(Row... rows)
{
public DataFrame(Row... rows) {
this.rows = new RingBuffer<>(rows);
rowReader = null;
}
Expand All @@ -63,8 +59,7 @@ public DataFrame(Row... rows)
*
* @return True if this is a streaming data frame.
*/
public boolean isStreaming()
{
public boolean isStreaming() {
return rowReader != null;
}

Expand All @@ -73,8 +68,7 @@ public boolean isStreaming()
*
* @return True if the data frame contains no elements.
*/
public boolean isEmpty()
{
public boolean isEmpty() {
return rows.isEmpty();
}

Expand All @@ -83,8 +77,7 @@ public boolean isEmpty()
*
* @return The data frame size.
*/
public int size()
{
public int size() {
return rows.size();
}

Expand All @@ -96,25 +89,18 @@ public int size()
* @param index The index of the row to get.
* @return The row, or none if the index does not exist.
*/
public Optional<Row> get(int index)
{
if (isStreaming())
{
while (index >= size())
{
try
{
public Optional<Row> get(int index) {
if (isStreaming()) {
while (index >= size()) {
try {
Row row = rowReader.read().orElse(null);

if (row == null)
{
if (row == null) {
break;
}

pushBack(row);
}
catch (IOException e)
{
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Expand All @@ -128,8 +114,7 @@ public Optional<Row> get(int index)
*
* @param row The row to push
*/
public void pushFront(Row row)
{
public void pushFront(Row row) {
rows.pushFront(row);
}

Expand All @@ -138,8 +123,7 @@ public void pushFront(Row row)
*
* @param row The row to push
*/
public void pushBack(Row row)
{
public void pushBack(Row row) {
rows.pushBack(row);
}

Expand All @@ -150,16 +134,11 @@ public void pushBack(Row row)
*
* @return The removed row, or none if the data frame is empty.
*/
public Optional<Row> popFront()
{
if (isEmpty() && isStreaming())
{
try
{
public Optional<Row> popFront() {
if (isEmpty() && isStreaming()) {
try {
return rowReader.read();
}
catch (IOException e)
{
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Expand All @@ -174,16 +153,11 @@ public Optional<Row> popFront()
*
* @return The removed row, or none if the data frame is empty.
*/
public Optional<Row> popBack()
{
if (isEmpty() && isStreaming())
{
try
{
public Optional<Row> popBack() {
if (isEmpty() && isStreaming()) {
try {
return rowReader.read();
}
catch (IOException e)
{
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Expand All @@ -196,8 +170,7 @@ public Optional<Row> popBack()
*
* @return The row reader.
*/
public RowReader reader()
{
public RowReader reader() {
return RowReader.from(iterator());
}

Expand All @@ -206,15 +179,13 @@ public RowReader reader()
*
* @return The row writer.
*/
public RowWriter writer()
{
public RowWriter writer() {
// This creates a row writer using a method reference as the implementation for write().
return this::pushBack;
}

@Override
public Iterator<Row> iterator()
{
public Iterator<Row> iterator() {
return rows.iterator();
}

Expand All @@ -227,10 +198,8 @@ public Iterator<Row> iterator()
* @throws IOException Thrown if an I/O error occurs.
*/
@Override
public void close() throws IOException
{
if (rowReader != null)
{
public void close() throws IOException {
if (rowReader != null) {
rowReader.close();
rowReader = null;
}
Expand Down
Loading

0 comments on commit b99394e

Please sign in to comment.