| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 import java.util.List; | 38 import java.util.List; |
| 39 import java.util.Map; | 39 import java.util.Map; |
| 40 import java.util.Map.Entry; | 40 import java.util.Map.Entry; |
| 41 | 41 |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Data structure which is populated with the locations of each field value pars
ed from the text. | 44 * Data structure which is populated with the locations of each field value pars
ed from the text. |
| 45 * | 45 * |
| 46 * <p>The locations of primary fields values are retrieved by {@code getLocation
} or | 46 * <p>The locations of primary fields values are retrieved by {@code getLocation
} or |
| 47 * {@code getLocations}. The locations of sub message values are within nested | 47 * {@code getLocations}. The locations of sub message values are within nested |
| 48 * {@code TextFormatParseInfoTree}s and are retrieve by {@code getNestedTree} or | 48 * {@code TextFormatParseInfoTree}s and are retrieve by {@getNestedTree} or {cod
e @getNestedTrees}. |
| 49 * {@code getNestedTrees}. | |
| 50 * | 49 * |
| 51 * <p>The {@code TextFormatParseInfoTree} is created by a Builder. | 50 * <p>The {@code TextFormatParseInfoTree} is created by a Builder. |
| 52 */ | 51 */ |
| 53 public class TextFormatParseInfoTree { | 52 public class TextFormatParseInfoTree { |
| 54 | 53 |
| 55 // Defines a mapping between each field's descriptor to the list of locations
where | 54 // Defines a mapping between each field's descriptor to the list of locations
where |
| 56 // its value(s) were was encountered. | 55 // its value(s) were was encountered. |
| 57 private Map<FieldDescriptor, List<TextFormatParseLocation>> locationsFromField
; | 56 private Map<FieldDescriptor, List<TextFormatParseLocation>> locationsFromField
; |
| 58 | 57 |
| 59 // Defines a mapping between a field's descriptor to a list of TextFormatParse
InfoTrees for | 58 // Defines a mapping between a field's descriptor to a list of TextFormatParse
InfoTrees for |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 locationsFromField.put(fieldDescriptor, fieldLocations); | 190 locationsFromField.put(fieldDescriptor, fieldLocations); |
| 192 } | 191 } |
| 193 fieldLocations.add(location); | 192 fieldLocations.add(location); |
| 194 return this; | 193 return this; |
| 195 } | 194 } |
| 196 | 195 |
| 197 /** | 196 /** |
| 198 * Set for a sub message. | 197 * Set for a sub message. |
| 199 * | 198 * |
| 200 * <p>A new builder is created for a sub message. The builder that is return
ed is a new builder. | 199 * <p>A new builder is created for a sub message. The builder that is return
ed is a new builder. |
| 201 * The return is <em>not</em> the invoked {@code builder.getBuilderForSubMes
sageField}. | 200 * The return is <emph>not</emph> the invoked {@code builder.getBuilderForSu
bMessageField}. |
| 202 * | 201 * |
| 203 * @param fieldDescriptor the field whose value is the submessage | 202 * @param fieldDescriptor the field whose value is the submessage |
| 204 * @return a new Builder for the sub message | 203 * @return a new Builder for the sub message |
| 205 */ | 204 */ |
| 206 public Builder getBuilderForSubMessageField(final FieldDescriptor fieldDescr
iptor) { | 205 public Builder getBuilderForSubMessageField(final FieldDescriptor fieldDescr
iptor) { |
| 207 List<Builder> submessageBuilders = subtreeBuildersFromField.get(fieldDescr
iptor); | 206 List<Builder> submessageBuilders = subtreeBuildersFromField.get(fieldDescr
iptor); |
| 208 if (submessageBuilders == null) { | 207 if (submessageBuilders == null) { |
| 209 submessageBuilders = new ArrayList<Builder>(); | 208 submessageBuilders = new ArrayList<Builder>(); |
| 210 subtreeBuildersFromField.put(fieldDescriptor, submessageBuilders); | 209 subtreeBuildersFromField.put(fieldDescriptor, submessageBuilders); |
| 211 } | 210 } |
| 212 Builder subtreeBuilder = new Builder(); | 211 Builder subtreeBuilder = new Builder(); |
| 213 submessageBuilders.add(subtreeBuilder); | 212 submessageBuilders.add(subtreeBuilder); |
| 214 return subtreeBuilder; | 213 return subtreeBuilder; |
| 215 } | 214 } |
| 216 | 215 |
| 217 /** | 216 /** |
| 218 * Build the {@code TextFormatParseInfoTree}. | 217 * Build the {@code TextFormatParseInfoTree}. |
| 219 * | 218 * |
| 220 * @return the {@code TextFormatParseInfoTree} | 219 * @return the {@code TextFormatParseInfoTree} |
| 221 */ | 220 */ |
| 222 public TextFormatParseInfoTree build() { | 221 public TextFormatParseInfoTree build() { |
| 223 return new TextFormatParseInfoTree(locationsFromField, subtreeBuildersFrom
Field); | 222 return new TextFormatParseInfoTree(locationsFromField, subtreeBuildersFrom
Field); |
| 224 } | 223 } |
| 225 } | 224 } |
| 226 } | 225 } |
| OLD | NEW |