Formatting

This commit is contained in:
Roman Inflianskas 2016-06-02 18:52:33 +03:00
parent 46ddaf64a8
commit 5aa970bd73
3 changed files with 78 additions and 72 deletions

View file

@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -96,26 +95,24 @@ public abstract class MapObject implements Comparable<MapObject> {
}
public void copyNames(Map<String, String> snames) {
if (snames != null && snames.containsKey("name:en")) {
enName = snames.get("name:en");
if (Algorithms.isEmpty(snames)) {
return;
}
if (snames != null && snames.containsKey("en")) {
if (snames.containsKey("name:en")) {
enName = snames.get("name:en");
} else if (snames.containsKey("en")) {
enName = snames.get("en");
}
if (snames != null) {
Iterator<Entry<String, String>> it = snames.entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> e = it.next();
String key = e.getKey();
if (key.startsWith("name:")) {
key = key.substring("name:".length());
}
if (names == null) {
names = new HashMap<String, String>();
}
if (Algorithms.isEmpty(names.get(key))) {
names.put(key, e.getValue());
}
for (Entry<String, String> e : snames.entrySet()) {
String key = e.getKey();
if (key.startsWith("name:")) {
key = key.substring("name:".length());
}
if (names == null) {
names = new HashMap<String, String>();
}
if (Algorithms.isEmpty(names.get(key))) {
names.put(key, e.getValue());
}
}
}

View file

@ -18,30 +18,30 @@ public abstract class Entity implements Serializable {
WAY,
RELATION,
WAY_BOUNDARY;
public static EntityType valueOf(Entity e){
if(e instanceof Node){
public static EntityType valueOf(Entity e) {
if (e instanceof Node) {
return NODE;
} else if(e instanceof Way){
} else if (e instanceof Way) {
return WAY;
} else if(e instanceof Relation){
} else if (e instanceof Relation) {
return RELATION;
}
return null;
}
}
public static class EntityId {
private final EntityType type;
private final Long id;
public EntityId(EntityType type, Long id){
public EntityId(EntityType type, Long id) {
this.type = type;
this.id = id;
}
public static EntityId valueOf(Entity e){
public static EntityId valueOf(Entity e) {
return new EntityId(EntityType.valueOf(e), e.getId());
}
@ -53,16 +53,16 @@ public abstract class Entity implements Serializable {
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public String toString() {
return type + " " + id; //$NON-NLS-1$
}
public EntityType getType() {
return type;
}
public Long getId() {
return id;
}
@ -97,9 +97,9 @@ public abstract class Entity implements Serializable {
return false;
return true;
}
}
// lazy initializing
private Map<String, String> tags = null;
private final long id;
@ -110,12 +110,11 @@ public abstract class Entity implements Serializable {
public static final int MODIFY_DELETED = -1;
public static final int MODIFY_MODIFIED = 1;
public static final int MODIFY_CREATED = 2;
public Entity(long id) {
this.id = id;
}
public Entity(Entity copy, long id) {
this.id = id;
@ -124,11 +123,11 @@ public abstract class Entity implements Serializable {
}
this.dataLoaded = copy.dataLoaded;
}
public int getModify() {
return modify;
}
public void setModify(int modify) {
this.modify = modify;
}
@ -136,39 +135,39 @@ public abstract class Entity implements Serializable {
public long getId() {
return id;
}
public String removeTag(String key){
if(tags != null) {
public String removeTag(String key) {
if (tags != null) {
return tags.remove(key);
}
return null;
}
public void removeTags(String... keys){
if (tags != null){
for (String key : keys){
public void removeTags(String... keys) {
if (tags != null) {
for (String key : keys) {
tags.remove(key);
}
}
}
public String putTag(String key, String value){
if(tags == null){
public String putTag(String key, String value) {
if (tags == null) {
tags = new LinkedHashMap<String, String>();
}
return tags.put(key.toLowerCase(), value);
}
public void replaceTags(Map<String, String> toPut){
public void replaceTags(Map<String, String> toPut) {
tags = new LinkedHashMap<String, String>(toPut);
}
public String getTag(OSMTagKey key){
public String getTag(OSMTagKey key) {
return getTag(key.getValue());
}
public String getTag(String key){
if(tags == null){
public String getTag(String key) {
if (tags == null) {
return null;
}
return tags.get(key);
@ -177,39 +176,39 @@ public abstract class Entity implements Serializable {
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public Map<String, String> getTags() {
if(tags == null){
if (tags == null) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(tags);
}
public Collection<String> getTagKeySet(){
if(tags == null){
public Collection<String> getTagKeySet() {
if (tags == null) {
return Collections.emptyList();
}
return tags.keySet();
}
public abstract void initializeLinks(Map<EntityId, Entity> entities);
/**
* @return middle point for entity
*/
public abstract LatLon getLatLon();
public boolean isVirtual(){
public boolean isVirtual() {
return id < 0;
}
public String getOsmUrl() {
return EntityId.valueOf(this).getOsmUrl();
}
@ -218,6 +217,7 @@ public abstract class Entity implements Serializable {
public String toString() {
return EntityId.valueOf(this).toString();
}
@Override
public int hashCode() {
if (id < 0) {
@ -238,7 +238,7 @@ public abstract class Entity implements Serializable {
if (id != other.id)
return false;
// virtual are not equal
if(id < 0){
if (id < 0) {
return false;
}
return true;
@ -263,13 +263,13 @@ public abstract class Entity implements Serializable {
public void entityDataLoaded() {
this.dataLoaded = true;
}
public boolean isDataLoaded() {
return dataLoaded;
}
public Map<String, String> getModifiableTags() {
if(tags == null){
if (tags == null) {
return Collections.emptyMap();
}
return tags;

View file

@ -16,6 +16,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@ -32,6 +33,14 @@ public class Algorithms {
private static final int BUFFER_SIZE = 1024;
private static final Log log = PlatformUtil.getLog(Algorithms.class);
public static boolean isEmpty(Collection c) {
return c == null || c.size() == 0;
}
public static boolean isEmpty(Map map) {
return map == null || map.size() == 0;
}
public static boolean isEmpty(String s) {
return s == null || s.length() == 0;
}