Android Open Source - PrepayCredit Item Factory

From Project

Back to project page PrepayCredit.


The source code is released under:

GNU General Public License

If you think the Android project PrepayCredit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

 * This file is part of Prepay Credit for Android
 */*  ww  w .  j  a  v  a 2  s.c  o  m*/
 * Copyright  2013  Damien O'Reilly
 * Prepay Credit for Android 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.
 * Prepay Credit for Android is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Prepay Credit for Android.  If not, see <>.
 * Report bugs or new features at:
 * Contact the author at:


import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;

 * Our usage factory.
public class ItemFactory {

    public static UsageItem createItem(JSONObject item) throws ParseException, JSONException, PrepayException {

        String type = item.getString("item");
        UsageItem usage;

        if (type.equals("Free internet allowance")) {
            usage = new Data(item.getString("value1"), item.getString("value2"));
        } else if (type.equals("Free Texts")) {
            usage = new Texts(item.getString("value1"), item.getString("value2"));
        } else if (type.equals("Talk and Text weekend minutes")) {
            usage = new WeekendVoiceMinutes(item.getString("value1"), item.getString("value2"));
        } else if (type.equals("Free cash")) {
            usage = new FreeCash(item.getString("value1"), item.getString("value2"));
        } else if (type.equals("Internet Add-on")) {
            usage = new InternetAddon(item.getString("value1"), item.getString("value2"));
        } else if (type.startsWith("Internet")) {
            usage = new OutOfBundle(item.getString("item"), item.getString("value1"), item.getString("value2"),
        } else if (type.equals("Skype Calls")) {
            usage = new SkypeCalls(item.getString("value1"), item.getString("value2"));
        } else if (type.equals("3 to 3 Calls")) {
            usage = new Three2ThreeCalls(item.getString("value1"), item.getString("value2"));
        } else if (type.equals("Top-up")) {
            usage = new TopUp(item.getString("value1"), item.getString("value2"));
        } else {
            throw new PrepayException("Unknown item: " + item.toString());
        return usage;

Java Source Code List