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

@ -2,43 +2,40 @@ package com.iluwatar.resource.acquisition.is.initialization;
/**
*
* Resource Acquisition Is Initialization pattern was developed
* for exception safe resource management by C++ creator Bjarne
* Stroustrup.
* Resource Acquisition Is Initialization pattern was developed for exception safe resource
* management by C++ creator Bjarne Stroustrup.
* <p>
* In RAII resource is tied to object lifetime: resource allocation
* is done during object creation while resource deallocation is
* done during object destruction.
* In RAII resource is tied to object lifetime: resource allocation is done during object creation
* while resource deallocation is done during object destruction.
* <p>
* In Java RAII is achieved with try-with-resources statement and
* interfaces {@link Closeable} and {@link AutoCloseable}. The try-with-resources
* statement ensures that each resource is closed at the end of the
* statement. Any object that implements {@link java.lang.AutoCloseable}, which
* includes all objects which implement {@link java.io.Closeable}, can be used
* as a resource.
* In Java RAII is achieved with try-with-resources statement and interfaces {@link Closeable} and
* {@link AutoCloseable}. The try-with-resources statement ensures that each resource is closed at
* the end of the statement. Any object that implements {@link java.lang.AutoCloseable}, which
* includes all objects which implement {@link java.io.Closeable}, can be used as a resource.
*
* In this example, {@link SlidingDoor} implements {@link AutoCloseable} and
* {@link TreasureChest} implements {@link Closeable}. Running the example, we can
* observe that both resources are automatically closed.
* In this example, {@link SlidingDoor} implements {@link AutoCloseable} and {@link TreasureChest}
* implements {@link Closeable}. Running the example, we can observe that both resources are
* automatically closed.
* <p>
* http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html
*
*/
public class App {
/**
* Program entry point
* @param args command line args
* @throws Exception
*/
public static void main( String[] args ) throws Exception {
try (SlidingDoor slidingDoor = new SlidingDoor()) {
System.out.println("Walking in.");
}
try (TreasureChest treasureChest = new TreasureChest()) {
System.out.println("Looting contents.");
}
/**
* Program entry point
*
* @param args command line args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
try (SlidingDoor slidingDoor = new SlidingDoor()) {
System.out.println("Walking in.");
}
try (TreasureChest treasureChest = new TreasureChest()) {
System.out.println("Looting contents.");
}
}
}

View File

@ -7,12 +7,12 @@ package com.iluwatar.resource.acquisition.is.initialization;
*/
public class SlidingDoor implements AutoCloseable {
public SlidingDoor() {
System.out.println("Sliding door opens.");
}
@Override
public void close() throws Exception {
System.out.println("Sliding door closes.");
}
public SlidingDoor() {
System.out.println("Sliding door opens.");
}
@Override
public void close() throws Exception {
System.out.println("Sliding door closes.");
}
}

View File

@ -10,12 +10,12 @@ import java.io.IOException;
*/
public class TreasureChest implements Closeable {
public TreasureChest() {
System.out.println("Treasure chest opens.");
}
@Override
public void close() throws IOException {
System.out.println("Treasure chest closes.");
}
public TreasureChest() {
System.out.println("Treasure chest opens.");
}
@Override
public void close() throws IOException {
System.out.println("Treasure chest closes.");
}
}

View File

@ -11,9 +11,9 @@ import com.iluwatar.resource.acquisition.is.initialization.App;
*/
public class AppTest {
@Test
public void test() throws Exception {
String[] args = {};
App.main(args);
}
@Test
public void test() throws Exception {
String[] args = {};
App.main(args);
}
}