Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from LeonardoDemartino/master
Browse files Browse the repository at this point in the history
Integers-to-Long
  • Loading branch information
marzn authored Jul 20, 2016
2 parents 8b363f3 + b45b461 commit df82be5
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 31 deletions.
10 changes: 7 additions & 3 deletions src/main/java/de/vivistra/telegrambot/client/BotResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public Message[] getMessages() {

for (int i = 0; i < length; i++) {
JSONObject result = resultArray.getJSONObject(i);

messages[i] = MessageFactory.fromJSON(result.getJSONObject("message"));

try{
messages[i] = MessageFactory.fromJSON(result.getJSONObject("message"));
}
catch(Exception e){
messages[i] = MessageFactory.fromJSON(new JSONObject());
}

if (this.updateID < result.getInt("update_id")) {
this.updateID = result.getInt("update_id");
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/vivistra/telegrambot/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class User {
// Unique identifier for this user or bot
private Integer id;
private Long id;
// User's or bot's first name
private String firstName;
// Optional. User's or bot's last name
Expand All @@ -26,7 +26,7 @@ public class User {
* @param lastName
* @param userName
*/
public User(Integer id, String firstName, String lastName, String userName) {
public User(Long id, String firstName, String lastName, String userName) {
Assert.notNull(id);
Assert.notEmpty(firstName);

Expand All @@ -44,7 +44,7 @@ public User(Integer id, String firstName, String lastName, String userName) {
*/
public static User fromJSON(JSONObject userObject) {
//
Integer id = userObject.getInt("id");
Long id = userObject.getLong("id");
String firstName = userObject.getString("first_name");

// Optional
Expand All @@ -59,7 +59,7 @@ public static User fromJSON(JSONObject userObject) {
*
* @return
*/
public Integer getId() {
public Long getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AudioMessage extends Message {
* @param recipient
* @param message
*/
public AudioMessage(Integer recipient, File message) {
public AudioMessage(Long recipient, File message) {
super(recipient, message);
}

Expand All @@ -25,7 +25,7 @@ public AudioMessage(Integer recipient, File message) {
* @param recipient
* @param message
*/
public AudioMessage(Integer recipient, Audio message) {
public AudioMessage(Long recipient, Audio message) {
super(recipient, message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ContactMessage extends Message {
* @param recipient
* @param message
*/
public ContactMessage(Integer recipient, Contact contact) {
public ContactMessage(Long recipient, Contact contact) {
super(recipient, contact);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DocumentMessage extends Message {
* @param recipient
* @param message
*/
public DocumentMessage(Integer recipient, File message) {
public DocumentMessage(Long recipient, File message) {
super(recipient, message);
}

Expand All @@ -25,7 +25,7 @@ public DocumentMessage(Integer recipient, File message) {
* @param recipient
* @param message
*/
public DocumentMessage(Integer recipient, Document message) {
public DocumentMessage(Long recipient, Document message) {
super(recipient, message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ImageMessage extends Message {
* @param recipient
* @param message
*/
public ImageMessage(Integer recipient, File message) {
public ImageMessage(Long recipient, File message) {
super(recipient, message);
}

Expand All @@ -25,7 +25,7 @@ public ImageMessage(Integer recipient, File message) {
* @param recipient
* @param message
*/
public ImageMessage(Integer recipient, PhotoSize[] message) {
public ImageMessage(Long recipient, PhotoSize[] message) {
super(recipient, message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LocationMessage extends Message {
* @param recipient
* @param message
*/
public LocationMessage(Integer recipient, Location message) {
public LocationMessage(Long recipient, Location message) {
super(recipient, message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class Message {
private static final Logger LOG = LogManager.getLogger();

// The recipient of the message
protected Integer recipient;
protected Long recipient;
// The content of the message
protected Object message;
// Type of the message
Expand Down Expand Up @@ -39,7 +39,7 @@ public abstract class Message {
* @param recipient
* @param message
*/
public Message(Integer recipient, Object message) {
public Message(Long recipient, Object message) {
this.recipient = recipient;
this.message = message;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public Message(Integer recipient, Object message) {
*
* @return
*/
public Integer getRecipient() {
public Long getRecipient() {
return this.recipient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MessageFactory {
*/
public static Message fromJSON(JSONObject messageObject) {

Integer recipient = null;
Long recipient = null;
Message message = null;

// Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class StickerMessage extends Message {
* @param recipient
* @param message
*/
public StickerMessage(Integer recipient, File message) {
public StickerMessage(Long recipient, File message) {
super(recipient, message);
}

Expand All @@ -25,7 +25,7 @@ public StickerMessage(Integer recipient, File message) {
* @param recipient
* @param message
*/
public StickerMessage(Integer recipient, Sticker message) {
public StickerMessage(Long recipient, Sticker message) {
super(recipient, message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TextMessage extends Message {
* @param recipient
* @param message
*/
public TextMessage(Integer recipient, String message) {
public TextMessage(Long recipient, String message) {
super(recipient, message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class UnhandledMessage extends Message {
* @param message
*/
public UnhandledMessage(Object message) {
super(0, message);
super((long) 0, message);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class VideoMessage extends Message {
* @param recipient
* @param message
*/
public VideoMessage(Integer recipient, File message) {
public VideoMessage(Long recipient, File message) {
super(recipient, message);
}

Expand All @@ -23,7 +23,7 @@ public VideoMessage(Integer recipient, File message) {
* @param recipient
* @param message
*/
public VideoMessage(Integer recipient, String message) {
public VideoMessage(Long recipient, String message) {
super(recipient, message);
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/de/vivistra/telegrambot/model/TestUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class TestUser {

@Test
public void testConstructorAndGetter() {
User peter = new User(1, "Peter", "Mueller", "PeMu");
User peter = new User(1L, "Peter", "Mueller", "PeMu");

assertTrue(1 == peter.getId());
assertEquals("Peter", peter.getFirstName());
assertEquals("Mueller", peter.getLastName());
assertEquals("PeMu", peter.getUserName());

User bot = new User(-1, "Bot", null, null);
User bot = new User(-1L, "Bot", null, null);

assertTrue(-1 == bot.getId());
assertEquals("Bot", bot.getFirstName());
Expand All @@ -25,7 +25,7 @@ public void testConstructorAndGetter() {

@Test(expected = IllegalArgumentException.class)
public void testConstructorWithIllegalFirstName() {
new User(0, null, null, null);
new User(0L, null, null, null);
}

@Test(expected = IllegalArgumentException.class)
Expand All @@ -35,11 +35,11 @@ public void testConstructorWithIllegalId() {

@Test
public void testToString() {
User peter = new User(1, "Peter", "Mueller", "PeMu");
User peter = new User(1L, "Peter", "Mueller", "PeMu");

assertEquals("Peter Mueller [PeMu@1]", peter.toString());

User bot = new User(-1, "Bot", null, null);
User bot = new User(-1L, "Bot", null, null);

assertEquals("Bot [-1]", bot.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testFromJSON() {

assertNull(message.getGroupChat());

User sender = new User(7872355, "Marcel", "", "Marcn");
User sender = new User(7872355L, "Marcel", "", "Marcn");

assertEquals(sender, message.getSender());
}
Expand Down

0 comments on commit df82be5

Please sign in to comment.