Merge pull request #281 from ankurkaushal/master

Reformat according to google style guide
This commit is contained in:
Ilkka Seppälä
2015-11-02 21:39:17 +02:00
438 changed files with 8257 additions and 8382 deletions

View File

@ -4,32 +4,33 @@ import java.io.FileWriter;
import java.io.IOException;
/**
* The Execute Around idiom specifies some code to be executed before and after
* a method. Typically the idiom is used when the API has methods to be executed in
* pairs, such as resource allocation/deallocation or lock acquisition/release.
* The Execute Around idiom specifies some code to be executed before and after a method. Typically
* the idiom is used when the API has methods to be executed in pairs, such as resource
* allocation/deallocation or lock acquisition/release.
* <p>
* In this example, we have {@link SimpleFileWriter} class that opens and closes the file
* for the user. The user specifies only what to do with the file by providing the
* {@link FileWriterAction} implementation.
* In this example, we have {@link SimpleFileWriter} class that opens and closes the file for the
* user. The user specifies only what to do with the file by providing the {@link FileWriterAction}
* implementation.
*
*/
public class App {
/**
* Program entry point
* @param args command line args
* @throws IOException
*/
public static void main( String[] args ) throws IOException {
new SimpleFileWriter("testfile.txt", new FileWriterAction() {
/**
* Program entry point
*
* @param args command line args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
@Override
public void writeFile(FileWriter writer) throws IOException {
writer.write("Hello");
writer.append(" ");
writer.append("there!");
}
});
}
new SimpleFileWriter("testfile.txt", new FileWriterAction() {
@Override
public void writeFile(FileWriter writer) throws IOException {
writer.write("Hello");
writer.append(" ");
writer.append("there!");
}
});
}
}

View File

@ -10,6 +10,6 @@ import java.io.IOException;
*/
public interface FileWriterAction {
void writeFile(FileWriter writer) throws IOException;
void writeFile(FileWriter writer) throws IOException;
}

View File

@ -5,19 +5,18 @@ import java.io.IOException;
/**
*
* SimpleFileWriter handles opening and closing file for the user. The user
* only has to specify what to do with the file resource through {@link FileWriterAction}
* parameter.
* SimpleFileWriter handles opening and closing file for the user. The user only has to specify what
* to do with the file resource through {@link FileWriterAction} parameter.
*
*/
public class SimpleFileWriter {
public SimpleFileWriter(String filename, FileWriterAction action) throws IOException {
FileWriter writer = new FileWriter(filename);
try {
action.writeFile(writer);
} finally {
writer.close();
}
}
public SimpleFileWriter(String filename, FileWriterAction action) throws IOException {
FileWriter writer = new FileWriter(filename);
try {
action.writeFile(writer);
} finally {
writer.close();
}
}
}

View File

@ -15,17 +15,17 @@ import com.iluwatar.execute.around.App;
*
*/
public class AppTest {
@Test
public void test() throws IOException {
String[] args = {};
App.main(args);
}
@Before
@After
public void cleanup() {
File file = new File("testfile.txt");
file.delete();
}
@Test
public void test() throws IOException {
String[] args = {};
App.main(args);
}
@Before
@After
public void cleanup() {
File file = new File("testfile.txt");
file.delete();
}
}