From 5aa970bd731217128f46fc13b29ff5d4ebb2b8ee Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Thu, 2 Jun 2016 18:52:33 +0300 Subject: [PATCH] Formatting --- .../src/net/osmand/data/MapObject.java | 33 +++--- .../src/net/osmand/osm/edit/Entity.java | 108 +++++++++--------- .../src/net/osmand/util/Algorithms.java | 9 ++ 3 files changed, 78 insertions(+), 72 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index 3c9eae0751..5c573b1833 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -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 { } public void copyNames(Map 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> it = snames.entrySet().iterator(); - while (it.hasNext()) { - Entry e = it.next(); - String key = e.getKey(); - if (key.startsWith("name:")) { - key = key.substring("name:".length()); - } - if (names == null) { - names = new HashMap(); - } - if (Algorithms.isEmpty(names.get(key))) { - names.put(key, e.getValue()); - } + for (Entry e : snames.entrySet()) { + String key = e.getKey(); + if (key.startsWith("name:")) { + key = key.substring("name:".length()); + } + if (names == null) { + names = new HashMap(); + } + if (Algorithms.isEmpty(names.get(key))) { + names.put(key, e.getValue()); } } } diff --git a/OsmAnd-java/src/net/osmand/osm/edit/Entity.java b/OsmAnd-java/src/net/osmand/osm/edit/Entity.java index 31e154f76b..f6f30ccdbe 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/Entity.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/Entity.java @@ -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 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(); } return tags.put(key.toLowerCase(), value); } - - public void replaceTags(Map toPut){ + + public void replaceTags(Map toPut) { tags = new LinkedHashMap(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 getTags() { - if(tags == null){ + if (tags == null) { return Collections.emptyMap(); } return Collections.unmodifiableMap(tags); } - - public Collection getTagKeySet(){ - if(tags == null){ + + public Collection getTagKeySet() { + if (tags == null) { return Collections.emptyList(); } return tags.keySet(); } - + public abstract void initializeLinks(Map 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 getModifiableTags() { - if(tags == null){ + if (tags == null) { return Collections.emptyMap(); } return tags; diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index 376ae1aa6e..1ae2a1d07f 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -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; }