Skip to content

Commit

Permalink
Merge pull request #11 from EXH3Y/DataMapping
Browse files Browse the repository at this point in the history
Data mapping (0.1.1 preparations)
  • Loading branch information
EXH3Y authored Nov 14, 2016
2 parents 63db9e5 + df55db0 commit 1bad9c7
Show file tree
Hide file tree
Showing 15 changed files with 471 additions and 399 deletions.
46 changes: 22 additions & 24 deletions src/main/java/exh3y/telebot/data/TelegramAudio.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package exh3y.telebot.data;

import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Optional;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
Expand All @@ -11,13 +9,13 @@

public class TelegramAudio {

private String file_id;
private Integer duration;
private String file_id;
private Integer duration;

private Optional<String> performer = Optional.empty();
private Optional<String> title = Optional.empty();
private Optional<String> mime_type = Optional.empty();
private Optional<Integer> file_size = Optional.empty();
private String performer = null;
private String title = null;
private String mime_type = null;
private Integer file_size = null;

public static TelegramAudio create(JSONObject json) throws JsonParseException, JsonMappingException, IOException {

Expand Down Expand Up @@ -61,15 +59,15 @@ public void setDuration(Integer duration) {

public boolean hasPerformer() {

return this.performer.isPresent();
return performer != null;
}

/**
* @return the performer
*/
public String getPerformer() throws NoSuchElementException {
public String getPerformer() {

return performer.get();
return performer;
}

/**
Expand All @@ -78,20 +76,20 @@ public String getPerformer() throws NoSuchElementException {
*/
public void setPerformer(String performer) {

this.performer = Optional.of(performer);
this.performer = performer;
}

public boolean hasTitle() {

return this.title.isPresent();
return title != null;
}

/**
* @return the title
*/
public String getTitle() throws NoSuchElementException {
public String getTitle() {

return title.get();
return title;
}

/**
Expand All @@ -100,20 +98,20 @@ public String getTitle() throws NoSuchElementException {
*/
public void setTitle(String title) {

this.title = Optional.of(title);
this.title = title;
}

public boolean hasMime_type() {

return this.mime_type.isPresent();
return mime_type != null;
}

/**
* @return the mime_type
*/
public String getMime_type() throws NoSuchElementException {
public String getMime_type() {

return mime_type.get();
return mime_type;
}

/**
Expand All @@ -122,20 +120,20 @@ public String getMime_type() throws NoSuchElementException {
*/
public void setMime_type(String mime_type) {

this.mime_type = Optional.of(mime_type);
this.mime_type = mime_type;
}

public boolean hasFile_size() {

return this.file_size.isPresent();
return file_size != null;
}

/**
* @return the file_size
*/
public Integer getFile_size() throws NoSuchElementException {
public Integer getFile_size() {

return file_size.get();
return file_size;
}

/**
Expand All @@ -144,7 +142,7 @@ public Integer getFile_size() throws NoSuchElementException {
*/
public void setFile_size(Integer file_size) {

this.file_size = Optional.of(file_size);
this.file_size = file_size;
}

}
72 changes: 41 additions & 31 deletions src/main/java/exh3y/telebot/data/TelegramChat.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package exh3y.telebot.data;

import java.io.IOException;
import java.util.Optional;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.JSONObject;
Expand All @@ -15,11 +15,11 @@ public class TelegramChat {
private int id;
private ETelegramChatType type;

private Optional<String> title = Optional.empty();
private Optional<String> username = Optional.empty();
private Optional<String> first_name = Optional.empty();
private Optional<String> last_name = Optional.empty();
private Optional<Boolean> all_members_are_administrators = Optional.empty();
private String title = null;
private String username = null;
private String first_name = null;
private String last_name = null;
private Boolean all_members_are_administrators = false;

public static TelegramChat create(JSONObject json) throws JsonParseException, JsonMappingException, IOException {

Expand Down Expand Up @@ -63,17 +63,36 @@ public int getId() {
return this.id;
}

/**
* @param id
* the id to set
*/
public void setId(int id) {

this.id = id;
}

/**
* @param type
* the type to set
*/
@JsonProperty
public void setType(String type) {

this.type = ETelegramChatType.getEnumByName(type);
}

public boolean hasTitle() {

return this.title.isPresent();
return title != null;
}

/**
* @return the title
*/
public String getTitle() {

return title.get();
return title;
}

/**
Expand All @@ -82,20 +101,20 @@ public String getTitle() {
*/
public void setTitle(String title) {

this.title = Optional.of(title);
this.title = title;
}

public boolean hasUsername() {

return this.username.isPresent();
return username != null;
}

/**
* @return the username
*/
public String getUsername() {

return username.get();
return username;
}

/**
Expand All @@ -104,20 +123,20 @@ public String getUsername() {
*/
public void setUsername(String username) {

this.username = Optional.of(username);
this.username = username;
}

public boolean hasFirst_name() {

return this.first_name.isPresent();
return first_name != null;
}

/**
* @return the first_name
*/
public String getFirst_name() {

return first_name.get();
return first_name;
}

/**
Expand All @@ -126,20 +145,20 @@ public String getFirst_name() {
*/
public void setFirst_name(String first_name) {

this.first_name = Optional.of(first_name);
this.first_name = first_name;
}

public boolean hasLast_name() {

return this.last_name.isPresent();
return last_name != null;
}

/**
* @return the last_name
*/
public String getLast_name() {

return last_name.get();
return last_name;
}

/**
Expand All @@ -148,15 +167,15 @@ public String getLast_name() {
*/
public void setLast_name(String last_name) {

this.last_name = Optional.of(last_name);
this.last_name = last_name;
}

/**
* @return the all_members_are_administrators
*/
public Boolean getAll_members_are_administrators() {

return all_members_are_administrators.orElse(false);
return all_members_are_administrators;
}

/**
Expand All @@ -165,25 +184,16 @@ public Boolean getAll_members_are_administrators() {
*/
public void setAll_members_are_administrators(Boolean all_members_are_administrators) {

this.all_members_are_administrators = Optional.of(all_members_are_administrators);
}

/**
* @param id
* the id to set
*/
public void setId(int id) {

this.id = id;
this.all_members_are_administrators = all_members_are_administrators;
}

/**
* @param type
* the type to set
*/
public void setType(String type) {
public void setType(ETelegramChatType type) {

this.type = ETelegramChatType.getEnumByName(type);
this.type = type;
}

}
40 changes: 26 additions & 14 deletions src/main/java/exh3y/telebot/data/TelegramContact.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package exh3y.telebot.data;

import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Optional;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
Expand All @@ -11,11 +9,11 @@

public class TelegramContact {

private String phone_number;
private String first_name;
private String phone_number;
private String first_name;

private Optional<String> last_name = Optional.empty();
private Optional<Integer> user_id = Optional.empty();
private String last_name = null;
private Integer user_id = null;

public static TelegramContact create(JSONObject json) throws JsonParseException, JsonMappingException, IOException {

Expand Down Expand Up @@ -45,32 +43,46 @@ public void setFirst_name(String first_name) {

public boolean hasLast_name() {

return this.last_name.isPresent();
return last_name != null;
}

public String getLast_name() throws NoSuchElementException {
/**
* @return the last_name
*/
public String getLast_name() {

return last_name.get();
return last_name;
}

/**
* @param last_name
* the last_name to set
*/
public void setLast_name(String last_name) {

this.last_name = Optional.of(last_name);
this.last_name = last_name;
}

public boolean hasUser_id() {

return this.user_id.isPresent();
return user_id != null;
}

public Integer getUser_id() throws NoSuchElementException {
/**
* @return the user_id
*/
public Integer getUser_id() {

return user_id.get();
return user_id;
}

/**
* @param user_id
* the user_id to set
*/
public void setUser_id(Integer user_id) {

this.user_id = Optional.of(user_id);
this.user_id = user_id;
}

}
Loading

0 comments on commit 1bad9c7

Please sign in to comment.