Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(java): syncing java and android snippets #877

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,54 @@

import java.util.List;
import java.util.Objects;
import com.google.firebase.firestore.DocumentId;

// [START fs_class_definition]
// [START firestore_data_custom_type_definition]
/** Represents a city : name, weather, population, country, capital, geo coordinates. */
public class City {

@DocumentId
private String id;
private String name;
private String state;
private String country;
private Boolean capital;
private Long population;
private List<String> regions;

// [START firestore_data_custom_type_definition]
public City() {
// Must have a public no-argument constructor
}

// Initialize all fields of a city
public City(
String name,
String state,
String country,
Boolean capital,
Long population,
List<String> regions) {
// Initialize all fields of a city
// [START_EXCLUDE]
this.name = name;
this.state = state;
this.country = country;
this.capital = capital;
this.population = population;
this.regions = regions;
// [END_EXCLUDE]
}
// [END firestore_data_custom_type_definition]

public City(String name) {
this.name = name;
// public getters and setters for all fields
// [START_EXCLUDE]
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}
Expand Down Expand Up @@ -102,62 +113,43 @@ public List<String> getRegions() {
public void setRegions(List<String> regions) {
this.regions = regions;
}
// [END_EXCLUDE]

private String getDefinedValue(String s) {
if (s != null) {
return s;
} else {
return "";
}
}

// [START_EXCLUDE]
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (name != null) {
sb.append(name);
sb.append(" name : ").append(name).append(",");
}
if (state != null) {
sb.append(" state : ");
sb.append(state);
sb.append(",");
sb.append(" state : ").append(state).append(",");
}
if (country != null) {
sb.append(", ");
sb.append(country);
sb.append(" country : ").append(country).append(",");
}
sb.append(" : [");
if (population != null) {
sb.append(" population : ");
sb.append(population);
sb.append(",");
sb.append(" population : ").append(population).append(",");
}
if (capital != null) {
sb.append(" capital : ");
sb.append(capital);
sb.append(",");
sb.append(" capital : ").append(capital).append(",");
}
if (regions != null) {
sb.append(" regions : [");
for (String r : regions) {
sb.append(r);
sb.append(", ");
}
sb.append("],");
sb.append(" regions : ").append(regions).append(",");
}
// remove trailing comma
if (sb.lastIndexOf(",") >= sb.length() - 1) {
sb.deleteCharAt(sb.length() - 1);
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
}
sb.append(" ]");
return sb.toString();
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof City)) {
return false;
}
if (obj == this) { return true; }
if (obj == null) { return false; }
if (obj.getClass() != this.getClass()) { return false; }

City city = (City) obj;
return Objects.equals(name, city.name)
&& Objects.equals(state, city.state)
Expand All @@ -171,4 +163,7 @@ public boolean equals(Object obj) {
public int hashCode() {
return Objects.hash(name, state, country, capital, population, regions);
}
// [END_EXCLUDE]
}
// [END firestore_data_custom_type_definition]
// [END fs_class_definition]