Skip to content

Commit

Permalink
重复代码重构
Browse files Browse the repository at this point in the history
  • Loading branch information
codingmiao committed Feb 27, 2023
1 parent 5b8fc3c commit c8ab176
Showing 1 changed file with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,19 @@ public static byte[] feature2Proto(Feature feature) {
return featureCollection2Proto(fc);
}

private static ProtoFeature.Map.Builder putPropertiesToCell(Map<String, Object> properties,ToProtoKeyValueCell keyValueCell) {
ProtoFeature.Map.Builder propertiesBuilder = ProtoFeature.Map.newBuilder();
properties.forEach((k, v) -> {
if (null == v) {
return;
}
PropertiesSetter setter = getPropertiesSetter(v);
setter.setKey(propertiesBuilder, keyValueCell, k);
setter.setValue(propertiesBuilder, keyValueCell, v);
});
return propertiesBuilder;
}

/**
* FeatureCollection 转 ProtoFeature bytes
*
Expand All @@ -563,15 +576,7 @@ public static byte[] featureCollection2Proto(FeatureCollection featureCollection
//properties转换
Map<String, Object> properties = feature.getProperties();
if (null != properties) {
ProtoFeature.Map.Builder propertiesBuilder = ProtoFeature.Map.newBuilder();
properties.forEach((k, v) -> {
if (null == v) {
return;
}
PropertiesSetter setter = getPropertiesSetter(v);
setter.setKey(propertiesBuilder, keyValueCell, k);
setter.setValue(propertiesBuilder, keyValueCell, v);
});
ProtoFeature.Map.Builder propertiesBuilder = putPropertiesToCell(properties, keyValueCell);
builder.addPropertiess(propertiesBuilder);
} else {
builder.addPropertiess(nullMap);
Expand Down Expand Up @@ -885,15 +890,7 @@ public void setValue(ProtoFeature.List.Builder propertiesBuilder, ToProtoKeyValu

private ProtoFeature.Map.Builder createMapBuilder(ToProtoKeyValueCell keyValueCell, Object value) {
Map<String, Object> subProperties = (Map<String, Object>) value;
ProtoFeature.Map.Builder subBuilder = ProtoFeature.Map.newBuilder();
subProperties.forEach((k, v) -> {
if (null == v) {
return;
}
PropertiesSetter setter = getPropertiesSetter(v);
setter.setKey(subBuilder, keyValueCell, k);
setter.setValue(subBuilder, keyValueCell, v);
});
ProtoFeature.Map.Builder subBuilder = putPropertiesToCell(subProperties, keyValueCell);
return subBuilder;
}
};
Expand Down

0 comments on commit c8ab176

Please sign in to comment.