Java tutorial
/* * EYWA.COM (Eywa Commerce) * This program is an integrated platform with E-Commerce and Configurator system. * Support: Please, contact the Author on http://www.smartfeeling.org. * Copyright (C) 2014 Gian Angelo Geminiani * * 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.eywa.impl.app.mongo.entities.items; import com.eywa.impl.app.IAppConstants; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; import org.ly.packages.mongo.impl.util.MongoUtils; /** * */ public class ItemOptions extends BasicDBObject { public static final String DOWNLOAD = IAppConstants.DOWNLOAD; public static final String PRINT = IAppConstants.PRINT; public static final String SHARE = IAppConstants.SHARE; public static final String COMMENT = IAppConstants.COMMENT; public static final String BUY = IAppConstants.BUY; public static final String RESTRICTED = IAppConstants.RESTRICTED; public static final String PAGE_FROM = IAppConstants.PAGE_FROM; public static final String PAGE_TO = IAppConstants.PAGE_TO; public ItemOptions(final DBObject raw) { this.init(raw); } public ItemOptions() { this.init(null); } public ItemOptions(final boolean download, final boolean share, final boolean comment) { this(download, share, true, comment, false, false, 0, 0); } public ItemOptions(final boolean download, final boolean share, final boolean print, final boolean comment, final boolean buy, final boolean restricted, final int from_page, final int to_page) { setDownload(this, download); setPrint(this, print); setShare(this, share); setComment(this, comment); setBuy(this, buy); setRestricted(this, restricted); setPageFrom(this, from_page); setPageTo(this, to_page); } // ------------------------------------------------------------------------ // p r i v a t e // ------------------------------------------------------------------------ private void init(final DBObject raw) { if (null == raw) { this.put(DOWNLOAD, true); this.put(PRINT, false); this.put(SHARE, false); this.put(COMMENT, false); this.put(BUY, false); this.put(RESTRICTED, true); this.put(PAGE_FROM, 0); this.put(PAGE_TO, 0); } else { this.put(DOWNLOAD, getDownload(raw)); this.put(PRINT, getPrint(raw)); this.put(SHARE, getShare(raw)); this.put(COMMENT, getComment(raw)); this.put(BUY, getBuy(raw)); this.put(RESTRICTED, getRestricted(raw)); this.put(PAGE_FROM, getPageFrom(raw)); this.put(PAGE_TO, getPageTo(raw)); } } public boolean canComment() { return getComment(this); } public boolean canShare() { return getShare(this); } public boolean canDownload() { return getDownload(this); } public boolean canPrint() { return getPrint(this); } public boolean canBuy() { return getBuy(this); } public boolean isRestricted() { return getRestricted(this); } public int getPageFrom() { return getPageFrom(this); } public void setPageFrom(final int value) { setPageFrom(this, value); } public int getPageTo() { return getPageTo(this); } public void setPageTo(final int value) { setPageTo(this, value); } // ------------------------------------------------------------------------ // S T A T I C // ------------------------------------------------------------------------ public static boolean getDownload(final DBObject item) { return MongoUtils.getBoolean(item, DOWNLOAD); } public static void setDownload(final DBObject item, final boolean value) { MongoUtils.put(item, DOWNLOAD, value); } public static boolean getPrint(final DBObject item) { return MongoUtils.getBoolean(item, PRINT); } public static void setPrint(final DBObject item, final boolean value) { MongoUtils.put(item, PRINT, value); } public static boolean getShare(final DBObject item) { return MongoUtils.getBoolean(item, SHARE); } public static void setShare(final DBObject item, final boolean value) { MongoUtils.put(item, SHARE, value); } public static boolean getComment(final DBObject item) { return MongoUtils.getBoolean(item, COMMENT); } public static void setComment(final DBObject item, final boolean value) { MongoUtils.put(item, COMMENT, value); } public static boolean getBuy(final DBObject item) { return MongoUtils.getBoolean(item, BUY); } public static void setBuy(final DBObject item, final boolean value) { MongoUtils.put(item, BUY, value); } public static boolean getRestricted(final DBObject item) { return MongoUtils.getBoolean(item, RESTRICTED); } public static void setRestricted(final DBObject item, final boolean value) { MongoUtils.put(item, RESTRICTED, value); } public static int getPageFrom(final DBObject item) { return MongoUtils.getInt(item, PAGE_FROM); } public static void setPageFrom(final DBObject item, final int value) { MongoUtils.put(item, PAGE_FROM, value); } public static int getPageTo(final DBObject item) { return MongoUtils.getInt(item, PAGE_TO); } public static void setPageTo(final DBObject item, final int value) { MongoUtils.put(item, PAGE_TO, value); } }