weibo4j.model.School Maven / Gradle / Ivy
/*
* Copyright © 2021 pengjianqiang
* All rights reserved.
* 项目名称:微博开放平台API-JAVA SDK
* 项目描述:基于微博开放平台官网的weibo4j-oauth2-beta3.1.1包及新版接口做二次开发
* 项目地址:https://github.com/qqxadyy/weibo-openapi-4java
* 许可证信息:见下文
*
* ======================================================================
*
* src/main/java/weibo4j下的文件是从weibo4j-oauth2-beta3.1.1.zip中复制出来的
* 本项目对这个目录下的部分源码做了重新改造
* 但是许可信息和"https://github.com/sunxiaowei2014/weibo4j-oauth2-beta3.1.1"或源码中已存在的保持一致
*/
package weibo4j.model;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import weibo4j.http.Response;
import weibo4j.org.json.JSONArray;
import weibo4j.org.json.JSONException;
import weibo4j.org.json.JSONObject;
public class School extends WeiboResponse {
private static final long serialVersionUID = -5991828656755790609L;
private @Getter int id; // 学校id
private @Getter String name; // 学校名称
public School(Response res) throws WeiboException {
super(res);
JSONObject json = res.asJSONObject();
try {
id = json.getInt("id");
name = json.getString("name");
} catch (JSONException je) {
throw new WeiboException(je.getMessage() + ":" + json.toString(), je);
}
}
public School(JSONObject json) throws WeiboException {
try {
id = json.getInt("id");
name = json.getString("name");
} catch (JSONException je) {
throw new WeiboException(je.getMessage() + ":" + json.toString(), je);
}
}
public static List constructSchool(Response res) throws WeiboException {
try {
JSONArray list = res.asJSONArray();
int size = list.length();
List schools = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
schools.add(new School(list.getJSONObject(i)));
}
return schools;
} catch (JSONException jsone) {
throw new WeiboException(jsone);
} catch (WeiboException te) {
throw te;
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
School other = (School)obj;
if (id != other.id) {
return false;
}
return true;
}
@Override
public String toString() {
return "School [id=" + id + ", name=" + name + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy