Skip to content

Commit

Permalink
Added the fields set_name and mask_position to the Sticker object, pl…
Browse files Browse the repository at this point in the history
…us two new objects, StickerSet, and MaskPosition
  • Loading branch information
pengrad committed Jul 23, 2017
1 parent 360c5b5 commit 46fdd82
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.pengrad.telegrambot.model;

import com.google.gson.Gson;

import java.io.Serializable;

/**
* Stas Parshin
* 23 July 2017
*/
public class MaskPosition implements Serializable {
private final static long serialVersionUID = 0L;
private final static Gson gson = new Gson();

public enum Point {
forehead, eyes, mouth, chin
}

private String point;
private Float x_shift, y_shift;
private Float scale;

public MaskPosition() {
}

public MaskPosition(Point point, Float x_shift, Float y_shift, Float scale) {
this(point.name(), x_shift, y_shift, scale);
}

public MaskPosition(String point, Float xShift, Float yShift, Float scale) {
this.point = point;
this.x_shift = xShift;
this.y_shift = yShift;
this.scale = scale;
}

public String point() {
return point;
}

public Float xShift() {
return x_shift;
}

public Float yShift() {
return y_shift;
}

public Float scale() {
return scale;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

MaskPosition that = (MaskPosition) o;

if (point != null ? !point.equals(that.point) : that.point != null) return false;
if (x_shift != null ? !x_shift.equals(that.x_shift) : that.x_shift != null) return false;
if (y_shift != null ? !y_shift.equals(that.y_shift) : that.y_shift != null) return false;
return scale != null ? scale.equals(that.scale) : that.scale == null;
}

@Override
public int hashCode() {
int result = point != null ? point.hashCode() : 0;
result = 31 * result + (x_shift != null ? x_shift.hashCode() : 0);
result = 31 * result + (y_shift != null ? y_shift.hashCode() : 0);
result = 31 * result + (scale != null ? scale.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "MaskPosition{" +
"point='" + point + '\'' +
", x_shift=" + x_shift +
", y_shift=" + y_shift +
", scale=" + scale +
'}';
}
}
14 changes: 14 additions & 0 deletions library/src/main/java/com/pengrad/telegrambot/model/Sticker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Sticker implements Serializable {
private Integer height;
private PhotoSize thumb;
private String emoji;
private String set_name;
private MaskPosition mask_position;
private Integer file_size;

public String fileId() {
Expand All @@ -36,6 +38,14 @@ public String emoji() {
return emoji;
}

public String setName() {
return set_name;
}

public MaskPosition maskPosition() {
return mask_position;
}

public Integer fileSize() {
return file_size;
}
Expand All @@ -52,6 +62,8 @@ public boolean equals(Object o) {
if (height != null ? !height.equals(sticker.height) : sticker.height != null) return false;
if (thumb != null ? !thumb.equals(sticker.thumb) : sticker.thumb != null) return false;
if (emoji != null ? !emoji.equals(sticker.emoji) : sticker.emoji != null) return false;
if (set_name != null ? !set_name.equals(sticker.set_name) : sticker.set_name != null) return false;
if (mask_position != null ? !mask_position.equals(sticker.mask_position) : sticker.mask_position != null) return false;
return file_size != null ? file_size.equals(sticker.file_size) : sticker.file_size == null;
}

Expand All @@ -68,6 +80,8 @@ public String toString() {
", height=" + height +
", thumb=" + thumb +
", emoji='" + emoji + '\'' +
", set_name='" + set_name + '\'' +
", mask_position=" + mask_position +
", file_size=" + file_size +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.pengrad.telegrambot.model;

import java.io.Serializable;
import java.util.Arrays;

/**
* Stas Parshin
* 23 July 2017
*/
public class StickerSet implements Serializable {
private final static long serialVersionUID = 0L;

private String name;
private String title;
private Boolean contains_masks;
private Sticker[] stickers;

public String name() {
return name;
}

public String title() {
return title;
}

public Boolean containsMasks() {
return contains_masks;
}

public Sticker[] stickers() {
return stickers;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

StickerSet that = (StickerSet) o;

if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (title != null ? !title.equals(that.title) : that.title != null) return false;
if (contains_masks != null ? !contains_masks.equals(that.contains_masks) : that.contains_masks != null) return false;
// Probably incorrect - comparing Object[] arrays with Arrays.equals
return Arrays.equals(stickers, that.stickers);
}

@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + (contains_masks != null ? contains_masks.hashCode() : 0);
result = 31 * result + Arrays.hashCode(stickers);
return result;
}

@Override
public String toString() {
return "StickerSet{" +
"name='" + name + '\'' +
", title='" + title + '\'' +
", contains_masks=" + contains_masks +
", stickers=" + Arrays.toString(stickers) +
'}';
}
}
2 changes: 2 additions & 0 deletions library/src/test/java/com/pengrad/telegrambot/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void setClasses() {
InlineQuery.class,
Invoice.class,
Location.class,
MaskPosition.class,
Message.class,
MessageEntity.class,
OrderInfo.class,
Expand All @@ -46,6 +47,7 @@ public void setClasses() {
ShippingAddress.class,
ShippingQuery.class,
Sticker.class,
StickerSet.class,
SuccessfulPayment.class,
Update.class,
User.class,
Expand Down

0 comments on commit 46fdd82

Please sign in to comment.