Split files, check command-line arguments
This commit is contained in:
@@ -1,42 +1,8 @@
|
|||||||
package com.example;
|
package com.example;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
import dagger.*;
|
import dagger.*;
|
||||||
import com.acme.*;
|
import com.acme.*;
|
||||||
|
|
||||||
@Module
|
|
||||||
class YahooWeatherModule {
|
|
||||||
|
|
||||||
private final String key;
|
|
||||||
|
|
||||||
public YahooWeatherModule(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
WeatherService provideWeatherService(WebSocket socket) {
|
|
||||||
return new YahooWeather(key, socket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module
|
|
||||||
class WeatherChannelModule {
|
|
||||||
@Provides
|
|
||||||
WeatherService provideWeatherService() {
|
|
||||||
return new WeatherChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module
|
|
||||||
class GpsSensorModule {
|
|
||||||
@Provides
|
|
||||||
GpsSensor provideGpsSensor() {
|
|
||||||
GpsSensor gps = new GpsSensor();
|
|
||||||
gps.calibrate();
|
|
||||||
return gps;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component(modules = {YahooWeatherModule.class, GpsSensorModule.class})
|
@Component(modules = {YahooWeatherModule.class, GpsSensorModule.class})
|
||||||
interface AppComponent {
|
interface AppComponent {
|
||||||
WeatherReporter getWeatherReporter();
|
WeatherReporter getWeatherReporter();
|
||||||
@@ -44,8 +10,14 @@ interface AppComponent {
|
|||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
|
if(args.length < 1) {
|
||||||
|
System.out.println("You must provide an API key\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String apiKey = args[0];
|
String apiKey = args[0];
|
||||||
YahooWeatherModule yahoo = new YahooWeatherModule(apiKey);
|
YahooWeatherModule yahoo = new YahooWeatherModule(apiKey);
|
||||||
|
|
||||||
AppComponent component = DaggerAppComponent.builder()
|
AppComponent component = DaggerAppComponent.builder()
|
||||||
.yahooWeatherModule(yahoo)
|
.yahooWeatherModule(yahoo)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
13
part-2/src/main/java/com/example/GpsSensorModule.java
Normal file
13
part-2/src/main/java/com/example/GpsSensorModule.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.example;
|
||||||
|
import com.acme.*;
|
||||||
|
import dagger.*;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class GpsSensorModule {
|
||||||
|
@Provides
|
||||||
|
GpsSensor provideGpsSensor() {
|
||||||
|
GpsSensor gps = new GpsSensor();
|
||||||
|
gps.calibrate();
|
||||||
|
return gps;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
package com.example;
|
package com.example;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
import com.acme.*;
|
import com.acme.*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package com.example;
|
package com.example;
|
||||||
import javax.inject.Inject;
|
import javax.inject.*;
|
||||||
|
|
||||||
public class WeatherChannel implements WeatherService {
|
public class WeatherChannel implements WeatherService {
|
||||||
@Inject
|
@Inject
|
||||||
|
|||||||
10
part-2/src/main/java/com/example/WeatherChannelModule.java
Normal file
10
part-2/src/main/java/com/example/WeatherChannelModule.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package com.example;
|
||||||
|
import dagger.*;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class WeatherChannelModule {
|
||||||
|
@Provides
|
||||||
|
WeatherService provideWeatherService() {
|
||||||
|
return new WeatherChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
package com.example;
|
package com.example;
|
||||||
import javax.inject.*;
|
|
||||||
|
|
||||||
public interface WeatherService {
|
public interface WeatherService {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package com.example;
|
package com.example;
|
||||||
import javax.inject.Inject;
|
import javax.inject.*;
|
||||||
|
|
||||||
public class WebSocket {
|
public class WebSocket {
|
||||||
@Inject
|
@Inject
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package com.example;
|
package com.example;
|
||||||
import javax.inject.Inject;
|
import javax.inject.*;
|
||||||
|
|
||||||
public class YahooWeather implements WeatherService {
|
public class YahooWeather implements WeatherService {
|
||||||
|
|
||||||
|
|||||||
18
part-2/src/main/java/com/example/YahooWeatherModule.java
Normal file
18
part-2/src/main/java/com/example/YahooWeatherModule.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package com.example;
|
||||||
|
import dagger.*;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class YahooWeatherModule {
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public YahooWeatherModule(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
WeatherService provideWeatherService(WebSocket socket) {
|
||||||
|
return new YahooWeather(key, socket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user