facebook4j.TargetingParameter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of facebook4j-core Show documentation
Show all versions of facebook4j-core Show documentation
A Java library for the Facebook Graph API
/*
* Copyright 2012 Ryuji Yamashita
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package facebook4j;
import facebook4j.internal.org.json.JSONObject;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
/**
* @author Ryuji Yamashita - roundrop at gmail.com
* @since Facebook4J 2.0.0
*/
public class TargetingParameter implements java.io.Serializable {
private Set countries;
private Set cities;
private Set regions;
private Set locales;
public TargetingParameter() {
}
public void setCountries(Set countries) {
this.countries = countries;
}
public void setCities(Set cities) {
this.cities = cities;
}
public void setRegions(Set regions) {
this.regions = regions;
}
public void setLocales(Set locales) {
this.locales = new LinkedHashSet();
for (Locale locale : locales) {
this.locales.add(locale.toString());
}
}
public TargetingParameter countries(Collection countries) {
if (this.countries == null) {
this.countries = new LinkedHashSet();
}
this.countries.addAll(countries);
return this;
}
public TargetingParameter country(String country) {
if (countries == null) {
countries = new LinkedHashSet();
}
countries.add(country);
return this;
}
public TargetingParameter cities(Collection cities) {
if (this.cities == null) {
this.cities = new LinkedHashSet();
}
this.cities.addAll(cities);
return this;
}
public TargetingParameter city(String city) {
if (cities == null) {
cities = new LinkedHashSet();
}
cities.add(city);
return this;
}
public TargetingParameter regions(Collection regions) {
if (this.regions == null) {
this.regions = new LinkedHashSet();
}
this.regions.addAll(regions);
return this;
}
public TargetingParameter region(String region) {
if (regions == null) {
regions = new LinkedHashSet();
}
regions.add(region);
return this;
}
public TargetingParameter locales(Collection locales) {
if (this.locales == null) {
this.locales = new LinkedHashSet();
}
for (Locale locale : locales) {
this.locales.add(locale.toString());
}
return this;
}
public TargetingParameter locale(Locale locale) {
if (locales == null) {
locales = new LinkedHashSet();
}
locales.add(locale.toString());
return this;
}
public Set getCountries() {
return countries;
}
public Set getCities() {
return cities;
}
public Set getRegions() {
return regions;
}
public Set getLocales() {
return locales;
}
private JSONObject json = null;
public JSONObject asJSONObject() {
if (json == null) {
json = new JSONObject(this);
}
return json;
}
public String asJSONString() {
return asJSONObject().toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TargetingParameter)) return false;
TargetingParameter targetingParameter = (TargetingParameter) o;
if (cities != null ? !cities.equals(targetingParameter.cities) : targetingParameter.cities != null) return false;
if (countries != null ? !countries.equals(targetingParameter.countries) : targetingParameter.countries != null) return false;
if (locales != null ? !locales.equals(targetingParameter.locales) : targetingParameter.locales != null) return false;
if (regions != null ? !regions.equals(targetingParameter.regions) : targetingParameter.regions != null) return false;
return true;
}
@Override
public int hashCode() {
int result = countries != null ? countries.hashCode() : 0;
result = 31 * result + (cities != null ? cities.hashCode() : 0);
result = 31 * result + (regions != null ? regions.hashCode() : 0);
result = 31 * result + (locales != null ? locales.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "TargetingParameter{" +
"countries=" + countries +
", cities=" + cities +
", regions=" + regions +
", locales=" + locales +
'}';
}
}