Java tutorial
/* Swisscom Safe Connect Copyright (C) 2014 Swisscom This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.swisscom.safeconnect.model; import org.json.JSONObject; import java.util.Locale; /** * Created by vadim on 15.07.14. */ public class PlumberStatsResponse extends PlumberResponse { private String phone; private String username; private String deviceId; private TrafficStats currentStats; private TrafficStats todayStats; private TrafficStats monthStats; private TrafficStats totalStats; public PlumberStatsResponse() { fromJson((JSONObject) null); } public PlumberStatsResponse(String json) { super(json); } public PlumberStatsResponse(JSONObject json) { super(json); } @Override public String toString() { return String.format(Locale.getDefault(), "PlumberStatsResponse {" + "\nphone: %s" + "\nusername: %s" + "\ncurrent: %s" + "\ntoday: %s" + "\nmonth: %s" + "\ntotal: %s" + "\n}", phone, username, currentStats.toString(), todayStats.toString(), monthStats.toString(), totalStats.toString()); } public boolean isUserActive() { return username != null && !username.isEmpty(); } @Override protected void fromJson(JSONObject json) { if (json == null) { currentStats = new TrafficStats(); todayStats = new TrafficStats(); monthStats = new TrafficStats(); totalStats = new TrafficStats(); phone = username = null; return; } phone = json.optString("phone"); username = json.optString("user_name"); deviceId = json.optString("device_id"); currentStats = new TrafficStats(json.optJSONObject("session_stat")); todayStats = new TrafficStats(json.optJSONObject("day_stat")); monthStats = new TrafficStats(json.optJSONObject("month_stat")); totalStats = new TrafficStats(json.optJSONObject("total_stat")); } public String getPhone() { return phone; } public String getUsername() { return username; } public String getDeviceId() { return deviceId; } public TrafficStats getCurrentStats() { return currentStats; } public TrafficStats getTodayStats() { return todayStats; } public TrafficStats getMonthStats() { return monthStats; } public TrafficStats getTotalStats() { return totalStats; } }