-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding twitter interface to public repo
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package edu.mit.d54; | ||
|
||
public class TwitterClient { | ||
|
||
private static boolean enableTwitter = false; | ||
private static TwitterClient instance; | ||
|
||
public static boolean enableTwitter() | ||
{ | ||
enableTwitter = getInstance().doEnableTwitter(); | ||
return enableTwitter; | ||
} | ||
|
||
public static void disableTwitter() | ||
{ | ||
enableTwitter = false; | ||
} | ||
|
||
public static boolean isEnabled() | ||
{ | ||
return enableTwitter; | ||
} | ||
|
||
public static void setInstance(TwitterClient instance) | ||
{ | ||
enableTwitter = false; | ||
TwitterClient.instance = instance; | ||
} | ||
|
||
protected static TwitterClient getInstance() | ||
{ | ||
if (instance == null) | ||
instance = new TwitterClient(); | ||
return instance; | ||
} | ||
|
||
public static void tweet(String tweet) | ||
{ | ||
getInstance().doTweet(tweet); | ||
} | ||
|
||
public TwitterClient() | ||
{ | ||
} | ||
|
||
protected boolean doEnableTwitter() | ||
{ | ||
return true; | ||
} | ||
|
||
protected void doTweet(String tweet) { | ||
if (enableTwitter) | ||
{ | ||
System.out.printf("(SIM) Tweeted: %s\n", tweet); | ||
} | ||
else | ||
{ | ||
System.out.printf("(SIM - Twitter not enabled) Would have tweeted: %s\n", tweet); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters