Merge pull request #4176 from tschaub/remove-isdefandnotnull

Remove use of goog.isDefAndNotNull().
This commit is contained in:
Tim Schaub
2015-10-01 00:05:57 -06:00
45 changed files with 116 additions and 135 deletions
+15 -18
View File
@@ -60,15 +60,15 @@ ol.format.EsriJSON.readGeometry_ = function(object, opt_options) {
var type;
if (goog.isNumber(object.x) && goog.isNumber(object.y)) {
type = ol.geom.GeometryType.POINT;
} else if (goog.isDefAndNotNull(object.points)) {
} else if (object.points) {
type = ol.geom.GeometryType.MULTI_POINT;
} else if (goog.isDefAndNotNull(object.paths)) {
} else if (object.paths) {
if (object.paths.length === 1) {
type = ol.geom.GeometryType.LINE_STRING;
} else {
type = ol.geom.GeometryType.MULTI_LINE_STRING;
}
} else if (goog.isDefAndNotNull(object.rings)) {
} else if (object.rings) {
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
var rings = ol.format.EsriJSON.convertRings_(object.rings, layout);
object = /** @type {EsriJSONGeometry} */(goog.object.clone(object));
@@ -149,13 +149,13 @@ ol.format.EsriJSON.readPointGeometry_ = function(object) {
goog.asserts.assert(goog.isNumber(object.x), 'object.x should be number');
goog.asserts.assert(goog.isNumber(object.y), 'object.y should be number');
var point;
if (goog.isDefAndNotNull(object.m) && goog.isDefAndNotNull(object.z)) {
if (object.m !== undefined && object.z !== undefined) {
point = new ol.geom.Point([object.x, object.y, object.z, object.m],
ol.geom.GeometryLayout.XYZM);
} else if (goog.isDefAndNotNull(object.z)) {
} else if (object.z !== undefined) {
point = new ol.geom.Point([object.x, object.y, object.z],
ol.geom.GeometryLayout.XYZ);
} else if (goog.isDefAndNotNull(object.m)) {
} else if (object.m !== undefined) {
point = new ol.geom.Point([object.x, object.y, object.m],
ol.geom.GeometryLayout.XYM);
} else {
@@ -219,8 +219,7 @@ ol.format.EsriJSON.getGeometryLayout_ = function(object) {
* @return {ol.geom.Geometry} MultiPoint.
*/
ol.format.EsriJSON.readMultiPointGeometry_ = function(object) {
goog.asserts.assert(goog.isDefAndNotNull(object.points),
'object.points should be defined');
goog.asserts.assert(object.points, 'object.points should be defined');
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
return new ol.geom.MultiPoint(object.points, layout);
};
@@ -232,7 +231,7 @@ ol.format.EsriJSON.readMultiPointGeometry_ = function(object) {
* @return {ol.geom.Geometry} MultiPolygon.
*/
ol.format.EsriJSON.readMultiPolygonGeometry_ = function(object) {
goog.asserts.assert(goog.isDefAndNotNull(object.rings));
goog.asserts.assert(object.rings);
goog.asserts.assert(object.rings.length > 1,
'object.rings should have length larger than 1');
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
@@ -248,7 +247,7 @@ ol.format.EsriJSON.readMultiPolygonGeometry_ = function(object) {
* @return {ol.geom.Geometry} Polygon.
*/
ol.format.EsriJSON.readPolygonGeometry_ = function(object) {
goog.asserts.assert(goog.isDefAndNotNull(object.rings));
goog.asserts.assert(object.rings);
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
return new ol.geom.Polygon(object.rings, layout);
};
@@ -483,10 +482,9 @@ ol.format.EsriJSON.prototype.readFeatures;
ol.format.EsriJSON.prototype.readFeatureFromObject = function(
object, opt_options) {
var esriJSONFeature = /** @type {EsriJSONFeature} */ (object);
goog.asserts.assert(goog.isDefAndNotNull(esriJSONFeature.geometry) ||
goog.isDefAndNotNull(esriJSONFeature.compressedGeometry) ||
goog.isDefAndNotNull(esriJSONFeature.attributes),
'geometry, compressedGeometry or attributes should be defined');
goog.asserts.assert(esriJSONFeature.geometry ||
esriJSONFeature.attributes,
'geometry or attributes should be defined');
var geometry = ol.format.EsriJSON.readGeometry_(esriJSONFeature.geometry,
opt_options);
var feature = new ol.Feature();
@@ -516,7 +514,7 @@ ol.format.EsriJSON.prototype.readFeaturesFromObject = function(
object, opt_options) {
var esriJSONObject = /** @type {EsriJSONObject} */ (object);
var options = opt_options ? opt_options : {};
if (goog.isDefAndNotNull(esriJSONObject.features)) {
if (esriJSONObject.features) {
var esriJSONFeatureCollection = /** @type {EsriJSONFeatureCollection} */
(object);
/** @type {Array.<ol.Feature>} */
@@ -573,8 +571,7 @@ ol.format.EsriJSON.prototype.readProjection;
*/
ol.format.EsriJSON.prototype.readProjectionFromObject = function(object) {
var esriJSONObject = /** @type {EsriJSONObject} */ (object);
if (goog.isDefAndNotNull(esriJSONObject.spatialReference) &&
goog.isDefAndNotNull(esriJSONObject.spatialReference.wkid)) {
if (esriJSONObject.spatialReference && esriJSONObject.spatialReference.wkid) {
var crs = esriJSONObject.spatialReference.wkid;
return ol.proj.get('EPSG:' + crs);
} else {
@@ -650,7 +647,7 @@ ol.format.EsriJSON.prototype.writeFeatureObject = function(
opt_options = this.adaptOptions(opt_options);
var object = {};
var geometry = feature.getGeometry();
if (goog.isDefAndNotNull(geometry)) {
if (geometry) {
object['geometry'] =
ol.format.EsriJSON.writeGeometry_(geometry, opt_options);
}
+1 -1
View File
@@ -67,7 +67,7 @@ ol.format.Feature.prototype.adaptOptions = function(options) {
if (options) {
updatedOptions = {
featureProjection: options.featureProjection,
dataProjection: goog.isDefAndNotNull(options.dataProjection) ?
dataProjection: options.dataProjection ?
options.dataProjection : this.defaultDataProjection,
rightHanded: options.rightHanded
};
+4 -4
View File
@@ -38,7 +38,7 @@ ol.format.GeoJSON = function(opt_options) {
* @inheritDoc
*/
this.defaultDataProjection = ol.proj.get(
goog.isDefAndNotNull(options.defaultDataProjection) ?
options.defaultDataProjection ?
options.defaultDataProjection : 'EPSG:4326');
@@ -484,7 +484,7 @@ ol.format.GeoJSON.prototype.readProjection;
ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) {
var geoJSONObject = /** @type {GeoJSONObject} */ (object);
var crs = geoJSONObject.crs;
if (goog.isDefAndNotNull(crs)) {
if (crs) {
if (crs.type == 'name') {
return ol.proj.get(crs.properties.name);
} else if (crs.type == 'EPSG') {
@@ -530,11 +530,11 @@ ol.format.GeoJSON.prototype.writeFeatureObject = function(
'type': 'Feature'
};
var id = feature.getId();
if (goog.isDefAndNotNull(id)) {
if (id) {
object['id'] = id;
}
var geometry = feature.getGeometry();
if (goog.isDefAndNotNull(geometry)) {
if (geometry) {
object['geometry'] =
ol.format.GeoJSON.writeGeometry_(geometry, opt_options);
} else {
+9 -10
View File
@@ -643,7 +643,7 @@ ol.format.GML3.prototype.writePos_ = function(node, value, objectStack) {
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
var axisOrientation = 'enu';
if (goog.isDefAndNotNull(srsName)) {
if (srsName) {
axisOrientation = ol.proj.get(srsName).getAxisOrientation();
}
var point = value.getCoordinates();
@@ -666,7 +666,7 @@ ol.format.GML3.prototype.writePos_ = function(node, value, objectStack) {
*/
ol.format.GML3.prototype.getCoords_ = function(point, opt_srsName) {
var axisOrientation = 'enu';
if (goog.isDefAndNotNull(opt_srsName)) {
if (opt_srsName) {
axisOrientation = ol.proj.get(opt_srsName).getAxisOrientation();
}
return ((axisOrientation.substr(0, 2) === 'en') ?
@@ -708,7 +708,7 @@ ol.format.GML3.prototype.writePoint_ = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (goog.isDefAndNotNull(srsName)) {
if (srsName) {
node.setAttribute('srsName', srsName);
}
var pos = ol.xml.createElementNS(node.namespaceURI, 'pos');
@@ -763,7 +763,7 @@ ol.format.GML3.prototype.writeLinearRing_ =
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (goog.isDefAndNotNull(srsName)) {
if (srsName) {
node.setAttribute('srsName', srsName);
}
var posList = ol.xml.createElementNS(node.namespaceURI, 'posList');
@@ -804,7 +804,7 @@ ol.format.GML3.prototype.writeSurfaceOrPolygon_ =
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (node.nodeName !== 'PolygonPatch' && goog.isDefAndNotNull(srsName)) {
if (node.nodeName !== 'PolygonPatch' && srsName) {
node.setAttribute('srsName', srsName);
}
if (node.nodeName === 'Polygon' || node.nodeName === 'PolygonPatch') {
@@ -834,8 +834,7 @@ ol.format.GML3.prototype.writeCurveOrLineString_ =
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (node.nodeName !== 'LineStringSegment' &&
goog.isDefAndNotNull(srsName)) {
if (node.nodeName !== 'LineStringSegment' && srsName) {
node.setAttribute('srsName', srsName);
}
if (node.nodeName === 'LineString' ||
@@ -864,7 +863,7 @@ ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_ =
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
var surface = context['surface'];
if (goog.isDefAndNotNull(srsName)) {
if (srsName) {
node.setAttribute('srsName', srsName);
}
var polygons = geometry.getPolygons();
@@ -886,7 +885,7 @@ ol.format.GML3.prototype.writeMultiPoint_ = function(node, geometry,
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (goog.isDefAndNotNull(srsName)) {
if (srsName) {
node.setAttribute('srsName', srsName);
}
var points = geometry.getPoints();
@@ -909,7 +908,7 @@ ol.format.GML3.prototype.writeMultiCurveOrLineString_ =
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
var curve = context['curve'];
if (goog.isDefAndNotNull(srsName)) {
if (srsName) {
node.setAttribute('srsName', srsName);
}
var lines = geometry.getLineStrings();
+5 -5
View File
@@ -116,7 +116,7 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
var featureType = context['featureType'];
var featureNS = context['featureNS'];
var i, ii, prefix = 'p', defaultPrefix = 'p0';
if (!featureType && goog.isDefAndNotNull(node.childNodes)) {
if (!featureType && node.childNodes) {
featureType = [], featureNS = {};
for (i = 0, ii = node.childNodes.length; i < ii; ++i) {
var child = node.childNodes[i];
@@ -180,7 +180,7 @@ ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) {
context['srsName'] = node.firstElementChild.getAttribute('srsName');
var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null),
this.GEOMETRY_PARSERS_, node, objectStack, this);
if (goog.isDefAndNotNull(geometry)) {
if (geometry) {
return /** @type {ol.geom.Geometry} */ (
ol.format.Feature.transformWithOptions(geometry, false, context));
} else {
@@ -243,7 +243,7 @@ ol.format.GMLBase.prototype.readPoint = function(node, objectStack) {
goog.asserts.assert(node.localName == 'Point', 'localName should be Point');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (goog.isDefAndNotNull(flatCoordinates)) {
if (flatCoordinates) {
var point = new ol.geom.Point(null);
goog.asserts.assert(flatCoordinates.length == 3,
'flatCoordinates should have a length of 3');
@@ -382,7 +382,7 @@ ol.format.GMLBase.prototype.readLineString = function(node, objectStack) {
'localName should be LineString');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (goog.isDefAndNotNull(flatCoordinates)) {
if (flatCoordinates) {
var lineString = new ol.geom.LineString(null);
lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
return lineString;
@@ -406,7 +406,7 @@ ol.format.GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
var ring = ol.xml.pushParseAndPop(/** @type {Array.<number>} */(null),
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
objectStack, this);
if (goog.isDefAndNotNull(ring)) {
if (ring) {
return ring;
} else {
return undefined;
+10 -11
View File
@@ -393,7 +393,7 @@ ol.format.KML.readFlatCoordinates_ = function(node) {
*/
ol.format.KML.readStyleUrl_ = function(node) {
var s = goog.string.trim(ol.xml.getAllTextContent(node, false));
if (goog.isDefAndNotNull(node.baseURI)) {
if (node.baseURI) {
return goog.Uri.resolve(node.baseURI, s).toString();
} else {
return s;
@@ -409,7 +409,7 @@ ol.format.KML.readStyleUrl_ = function(node) {
*/
ol.format.KML.readURI_ = function(node) {
var s = ol.xml.getAllTextContent(node, false);
if (goog.isDefAndNotNull(node.baseURI)) {
if (node.baseURI) {
return goog.Uri.resolve(node.baseURI, goog.string.trim(s)).toString();
} else {
return goog.string.trim(s);
@@ -949,7 +949,7 @@ ol.format.KML.readPoint_ = function(node, objectStack) {
objectStack);
var flatCoordinates =
ol.format.KML.readFlatCoordinatesFromNode_(node, objectStack);
if (goog.isDefAndNotNull(flatCoordinates)) {
if (flatCoordinates) {
var point = new ol.geom.Point(null);
goog.asserts.assert(flatCoordinates.length == 3,
'flatCoordinates should have a length of 3');
@@ -979,8 +979,7 @@ ol.format.KML.readPolygon_ = function(node, objectStack) {
var flatLinearRings = ol.xml.pushParseAndPop(
/** @type {Array.<Array.<number>>} */ ([null]),
ol.format.KML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack);
if (goog.isDefAndNotNull(flatLinearRings) &&
!goog.isNull(flatLinearRings[0])) {
if (flatLinearRings && !goog.isNull(flatLinearRings[0])) {
var polygon = new ol.geom.Polygon(null);
var flatCoordinates = flatLinearRings[0];
var ends = [flatCoordinates.length];
@@ -1686,7 +1685,7 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) {
var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
var geometry = object['geometry'];
if (goog.isDefAndNotNull(geometry)) {
if (geometry) {
ol.format.Feature.transformWithOptions(geometry, false, options);
}
feature.setGeometry(geometry);
@@ -1723,7 +1722,7 @@ ol.format.KML.prototype.readSharedStyle_ = function(node, objectStack) {
var style = ol.format.KML.readStyle_(node, objectStack);
if (style) {
var styleUri;
if (goog.isDefAndNotNull(node.baseURI)) {
if (node.baseURI) {
styleUri = goog.Uri.resolve(node.baseURI, '#' + id).toString();
} else {
styleUri = '#' + id;
@@ -1753,7 +1752,7 @@ ol.format.KML.prototype.readSharedStyleMap_ = function(node, objectStack) {
return;
}
var styleUri;
if (goog.isDefAndNotNull(node.baseURI)) {
if (node.baseURI) {
styleUri = goog.Uri.resolve(node.baseURI, '#' + id).toString();
} else {
styleUri = '#' + id;
@@ -2269,7 +2268,7 @@ ol.format.KML.writePlacemark_ = function(node, feature, objectStack) {
var /** @type {ol.xml.NodeStackItem} */ context = {node: node};
// set id
if (goog.isDefAndNotNull(feature.getId())) {
if (feature.getId()) {
node.setAttribute('id', feature.getId());
}
@@ -2297,7 +2296,7 @@ ol.format.KML.writePlacemark_ = function(node, feature, objectStack) {
// serialize geometry
var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
var geometry = feature.getGeometry();
if (goog.isDefAndNotNull(geometry)) {
if (geometry) {
geometry =
ol.format.Feature.transformWithOptions(geometry, true, options);
}
@@ -2753,7 +2752,7 @@ ol.format.KML.DOCUMENT_NODE_FACTORY_ = function(value, objectStack,
*/
ol.format.KML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
opt_nodeName) {
if (goog.isDefAndNotNull(value)) {
if (value) {
goog.asserts.assertInstanceof(value, ol.geom.Geometry,
'value should be an ol.geom.Geometry');
var parentNode = objectStack[objectStack.length - 1].node;
+1 -1
View File
@@ -356,7 +356,7 @@ ol.format.Polyline.prototype.readProjection;
*/
ol.format.Polyline.prototype.writeFeatureText = function(feature, opt_options) {
var geometry = feature.getGeometry();
if (goog.isDefAndNotNull(geometry)) {
if (geometry) {
return this.writeGeometryText(geometry, opt_options);
} else {
goog.asserts.fail('geometry needs to be defined');
+1 -1
View File
@@ -34,7 +34,7 @@ ol.format.TopoJSON = function(opt_options) {
* @inheritDoc
*/
this.defaultDataProjection = ol.proj.get(
goog.isDefAndNotNull(options.defaultDataProjection) ?
options.defaultDataProjection ?
options.defaultDataProjection : 'EPSG:4326');
};
+6 -6
View File
@@ -475,7 +475,7 @@ ol.format.WFS.writeProperty_ = function(node, pair, objectStack) {
var name = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Name');
node.appendChild(name);
ol.format.XSD.writeStringTextNode(name, pair.name);
if (goog.isDefAndNotNull(pair.value)) {
if (pair.value !== undefined && pair.value !== null) {
var value = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Value');
node.appendChild(value);
if (pair.value instanceof ol.geom.Geometry) {
@@ -697,7 +697,7 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
}
ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation', this.schemaLocation_);
if (goog.isDefAndNotNull(inserts)) {
if (inserts) {
obj = {node: node, featureNS: options.featureNS,
featureType: options.featureType, featurePrefix: options.featurePrefix};
goog.object.extend(obj, baseObj);
@@ -706,7 +706,7 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
ol.xml.makeSimpleNodeFactory('Insert'), inserts,
objectStack);
}
if (goog.isDefAndNotNull(updates)) {
if (updates) {
obj = {node: node, featureNS: options.featureNS,
featureType: options.featureType, featurePrefix: options.featurePrefix};
goog.object.extend(obj, baseObj);
@@ -715,7 +715,7 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
ol.xml.makeSimpleNodeFactory('Update'), updates,
objectStack);
}
if (goog.isDefAndNotNull(deletes)) {
if (deletes) {
ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS,
featureType: options.featureType, featurePrefix: options.featurePrefix},
ol.format.WFS.TRANSACTION_SERIALIZERS_,
@@ -768,8 +768,8 @@ ol.format.WFS.prototype.readProjectionFromNode = function(node) {
goog.asserts.assert(node.localName == 'FeatureCollection',
'localName should be FeatureCollection');
if (goog.isDefAndNotNull(node.firstElementChild) &&
goog.isDefAndNotNull(node.firstElementChild.firstElementChild)) {
if (node.firstElementChild &&
node.firstElementChild.firstElementChild) {
node = node.firstElementChild.firstElementChild;
for (var n = node.firstElementChild; !goog.isNull(n);
n = n.nextElementSibling) {