Java tutorial
/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. */ package com.bemis.portal.report.model.impl; import aQute.bnd.annotation.ProviderType; import com.bemis.portal.report.definition.ReportParameter; import com.bemis.portal.report.runtime.ReportParametersValuesSerializer; import com.bemis.portal.report.runtime.ReportParametersValuesSerializerUtil; import com.liferay.portal.kernel.json.JSONException; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.StringUtil; import java.io.Serializable; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; /** * @author Michael C. Han */ @ProviderType public class ReportPreferencesImpl extends ReportPreferencesBaseImpl { public ReportPreferencesImpl() { } @Override public Map<ReportParameter, Serializable> getReportParametersValues() { if (_reportParametersValues == null) { String paramtersValuesJSON = getParametersValues(); ReportParametersValuesSerializer reportParametersValuesSerializer = ReportParametersValuesSerializerUtil .getReportParametersValuesSerializer(); try { Map<ReportParameter, Serializable> reportParametersValues = reportParametersValuesSerializer .deserialize(paramtersValuesJSON); if (reportParametersValues == null) { reportParametersValues = Collections.emptyMap(); } _reportParametersValues = reportParametersValues; } catch (JSONException jsone) { if (_log.isWarnEnabled()) { _log.warn("Error deserializing report parameter values", jsone); } } } return _reportParametersValues; } public Set<String> getSelectedFieldsSet() { if (_selectedFieldsSet == null) { String[] selectedFieldsArray = StringUtil.split(getSelectedFields(), StringPool.COMMA); _selectedFieldsSet = new LinkedHashSet<>(Arrays.asList(selectedFieldsArray)); } return _selectedFieldsSet; } @Override public Set<String> getSortFieldsSet() { if (_sortFieldsSet == null) { String[] sortFieldsArray = StringUtil.split(getSortFields(), StringPool.COMMA); _sortFieldsSet = new LinkedHashSet<>(Arrays.asList(sortFieldsArray)); } return _sortFieldsSet; } @Override public void setParametersValues(String parametersValues) { super.setParametersValues(parametersValues); _reportParametersValues = null; } @Override public void setSelectedFields(String selectedFields) { super.setSelectedFields(selectedFields); _selectedFieldsSet = null; } @Override public void setSortFields(String sortFields) { super.setSortFields(sortFields); _sortFieldsSet = null; } private static final Log _log = LogFactoryUtil.getLog(ReportPreferencesImpl.class); private Map<ReportParameter, Serializable> _reportParametersValues; private Set<String> _selectedFieldsSet; private Set<String> _sortFieldsSet; }