Skip to content

Commit b1063f8

Browse files
authored
Merge pull request eugenp#2 from eugenp/master
Merged from base
2 parents d1f0b2e + 9f94f9f commit b1063f8

390 files changed

Lines changed: 14161 additions & 451 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎JGit/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Relevant articles:
2+
3+
- [A Guide to JGit](http://www.baeldung.com/jgit)

‎Twitter4J/pom.xml‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.mabsisa</groupId>
5+
<artifactId>Twitter4J</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>Twitter4J</name>
9+
<url>http://maven.apache.org</url>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
<java.version>1.8</java.version>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.twitter4j</groupId>
22+
<artifactId>twitter4j-core</artifactId>
23+
<version>4.0.6</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.twitter4j</groupId>
27+
<artifactId>twitter4j-stream</artifactId>
28+
<version>4.0.6</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>4.12</version>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<finalName>${project.artifactId}</finalName>
39+
<resources>
40+
<resource>
41+
<directory>src/main/resources</directory>
42+
</resource>
43+
</resources>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-surefire-plugin</artifactId>
48+
<version>2.19.1</version>
49+
<configuration>
50+
<excludes>
51+
<exclude>**/ApplicationTest.java</exclude>
52+
</excludes>
53+
</configuration>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
</project>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
*
3+
*/
4+
package com.baeldung;
5+
6+
import java.util.List;
7+
import java.util.stream.Collectors;
8+
9+
import twitter4j.DirectMessage;
10+
import twitter4j.Query;
11+
import twitter4j.QueryResult;
12+
import twitter4j.StallWarning;
13+
import twitter4j.Status;
14+
import twitter4j.StatusDeletionNotice;
15+
import twitter4j.StatusListener;
16+
import twitter4j.Twitter;
17+
import twitter4j.TwitterException;
18+
import twitter4j.TwitterFactory;
19+
import twitter4j.TwitterStream;
20+
import twitter4j.TwitterStreamFactory;
21+
import twitter4j.conf.ConfigurationBuilder;
22+
23+
public class Application {
24+
25+
public static Twitter getTwitterinstance() {
26+
/**
27+
* if not using properties file, we can set access token by following way
28+
*/
29+
// ConfigurationBuilder cb = new ConfigurationBuilder();
30+
// cb.setDebugEnabled(true)
31+
// .setOAuthConsumerKey("DPHTBsWWO42d8rzshxlK0OwSY")
32+
// .setOAuthConsumerSecret("ACLXkeRY98NiaVCG1ai8fdYt0GoEGJbFeTuxjulSCO7sLKqls1")
33+
// .setOAuthAccessToken("838080188214759428-9MSK1ddPTN5ZZHbddjFI7s75mYgmCFQ")
34+
// .setOAuthAccessTokenSecret("1eXAADpHShAzQh5hGWLBUQHLysOuAKIOapmQQ8U0OVk2c");
35+
//
36+
// TwitterFactory tf = new TwitterFactory(cb.build());
37+
// Twitter twitter = tf.getSingleton();
38+
39+
Twitter twitter = TwitterFactory.getSingleton();
40+
return twitter;
41+
42+
}
43+
44+
public static String createTweet(String tweet) throws TwitterException {
45+
Twitter twitter = getTwitterinstance();
46+
Status status = twitter.updateStatus("creating baeldung API");
47+
return status.getText();
48+
}
49+
50+
public static List<String> getTimeLine() throws TwitterException {
51+
Twitter twitter = getTwitterinstance();
52+
List<Status> statuses = twitter.getHomeTimeline();
53+
return statuses.stream().map(
54+
item -> item.getText()).collect(
55+
Collectors.toList());
56+
}
57+
58+
public static String sendDirectMessage(String recipientName, String msg) throws TwitterException {
59+
Twitter twitter = getTwitterinstance();
60+
DirectMessage message = twitter.sendDirectMessage(recipientName, msg);
61+
return message.getText();
62+
}
63+
64+
public static List<String> searchtweets() throws TwitterException {
65+
Twitter twitter = getTwitterinstance();
66+
Query query = new Query("source:twitter4j baeldung");
67+
QueryResult result = twitter.search(query);
68+
List<Status> statuses = result.getTweets();
69+
return statuses.stream().map(
70+
item -> item.getText()).collect(
71+
Collectors.toList());
72+
}
73+
74+
public static void streamFeed() {
75+
76+
StatusListener listener = new StatusListener(){
77+
78+
@Override
79+
public void onException(Exception e) {
80+
e.printStackTrace();
81+
}
82+
83+
@Override
84+
public void onDeletionNotice(StatusDeletionNotice arg) {
85+
System.out.println("Got a status deletion notice id:" + arg.getStatusId());
86+
}
87+
88+
@Override
89+
public void onScrubGeo(long userId, long upToStatusId) {
90+
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
91+
}
92+
93+
@Override
94+
public void onStallWarning(StallWarning warning) {
95+
System.out.println("Got stall warning:" + warning);
96+
}
97+
98+
@Override
99+
public void onStatus(Status status) {
100+
System.out.println(status.getUser().getName() + " : " + status.getText());
101+
}
102+
103+
@Override
104+
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
105+
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
106+
}
107+
};
108+
109+
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
110+
111+
twitterStream.addListener(listener);
112+
113+
twitterStream.sample();
114+
115+
}
116+
117+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
oauth.consumerKey=//TODO
2+
oauth.consumerSecret=//TODO
3+
oauth.accessToken=//TODO
4+
oauth.accessTokenSecret=//TODO
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import org.junit.Test;
9+
10+
import twitter4j.TwitterException;
11+
12+
public class ApplicationTest {
13+
14+
/**
15+
* In order run this jUnit test you need to configure your API details in the twitter4j.properties
16+
*/
17+
18+
String tweet = "baeldung is awsome";
19+
20+
@Test
21+
public void givenText_updateStatus() throws TwitterException {
22+
String text = Application.createTweet(tweet);
23+
assertEquals(tweet, text);
24+
}
25+
26+
@Test
27+
public void givenCredential_fetchStatus() throws TwitterException {
28+
List<String> statuses = Application.getTimeLine();
29+
List<String> expectedStatuses = new ArrayList<String>();
30+
expectedStatuses.add(tweet);
31+
assertEquals(expectedStatuses, statuses);
32+
}
33+
34+
@Test
35+
public void givenRecipientNameAndMessage_sendDirectMessage() throws TwitterException {
36+
String msg = Application.sendDirectMessage("YOUR_RECCIPIENT_ID", tweet);
37+
assertEquals(msg, tweet);
38+
}
39+
40+
}

‎algorithms/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Relevant articles:
2+
3+
- [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra)
4+
- [Introduction to Cobertura](http://www.baeldung.com/cobertura)

‎algorithms/pom.xml‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,23 @@
4141
</plugins>
4242
</pluginManagement>
4343
</build>
44-
</project>
44+
<reporting>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.codehaus.mojo</groupId>
48+
<artifactId>cobertura-maven-plugin</artifactId>
49+
<version>2.7</version>
50+
<configuration>
51+
<instrumentation>
52+
<ignores>
53+
<ignore>com/baeldung/algorithms/dijkstra/*</ignore>
54+
</ignores>
55+
<excludes>
56+
<exclude>com/baeldung/algorithms/dijkstra/*</exclude>
57+
</excludes>
58+
</instrumentation>
59+
</configuration>
60+
</plugin>
61+
</plugins>
62+
</reporting>
63+
</project>

‎apache-bval/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Relevant Articles:
2+
- [Intro to Apache BVal](http://www.baeldung.com/apache-bval)

‎apache-commons/pom.xml‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>apache-commons</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<properties>
8+
<junit.version>4.12</junit.version>
9+
<compiler.version>3.6.0</compiler.version>
10+
</properties>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<artifactId>maven-compiler-plugin</artifactId>
15+
<version>${compiler.version}</version>
16+
<configuration>
17+
<source>1.8</source>
18+
<target>1.8</target>
19+
</configuration>
20+
</plugin>
21+
</plugins>
22+
</build>
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.apache.commons</groupId>
26+
<artifactId>commons-lang3</artifactId>
27+
<version>3.5</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>junit</groupId>
31+
<artifactId>junit</artifactId>
32+
<version>${junit.version}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
</project>

0 commit comments

Comments
 (0)