| 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 {@getNestedTree} or {cod
e @getNestedTrees}. | 48 * {@code TextFormatParseInfoTree}s and are retrieve by {@code getNestedTree} or |
| 49 * {@code getNestedTrees}. |
| 49 * | 50 * |
| 50 * <p>The {@code TextFormatParseInfoTree} is created by a Builder. | 51 * <p>The {@code TextFormatParseInfoTree} is created by a Builder. |
| 51 */ | 52 */ |
| 52 public class TextFormatParseInfoTree { | 53 public class TextFormatParseInfoTree { |
| 53 | 54 |
| 54 // Defines a mapping between each field's descriptor to the list of locations
where | 55 // Defines a mapping between each field's descriptor to the list of locations
where |
| 55 // its value(s) were was encountered. | 56 // its value(s) were was encountered. |
| 56 private Map<FieldDescriptor, List<TextFormatParseLocation>> locationsFromField
; | 57 private Map<FieldDescriptor, List<TextFormatParseLocation>> locationsFromField
; |
| 57 | 58 |
| 58 // Defines a mapping between a field's descriptor to a list of TextFormatParse
InfoTrees for | 59 // 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... |
| 190 locationsFromField.put(fieldDescriptor, fieldLocations); | 191 locationsFromField.put(fieldDescriptor, fieldLocations); |
| 191 } | 192 } |
| 192 fieldLocations.add(location); | 193 fieldLocations.add(location); |
| 193 return this; | 194 return this; |
| 194 } | 195 } |
| 195 | 196 |
| 196 /** | 197 /** |
| 197 * Set for a sub message. | 198 * Set for a sub message. |
| 198 * | 199 * |
| 199 * <p>A new builder is created for a sub message. The builder that is return
ed is a new builder. | 200 * <p>A new builder is created for a sub message. The builder that is return
ed is a new builder. |
| 200 * The return is <emph>not</emph> the invoked {@code builder.getBuilderForSu
bMessageField}. | 201 * The return is <em>not</em> the invoked {@code builder.getBuilderForSubMes
sageField}. |
| 201 * | 202 * |
| 202 * @param fieldDescriptor the field whose value is the submessage | 203 * @param fieldDescriptor the field whose value is the submessage |
| 203 * @return a new Builder for the sub message | 204 * @return a new Builder for the sub message |
| 204 */ | 205 */ |
| 205 public Builder getBuilderForSubMessageField(final FieldDescriptor fieldDescr
iptor) { | 206 public Builder getBuilderForSubMessageField(final FieldDescriptor fieldDescr
iptor) { |
| 206 List<Builder> submessageBuilders = subtreeBuildersFromField.get(fieldDescr
iptor); | 207 List<Builder> submessageBuilders = subtreeBuildersFromField.get(fieldDescr
iptor); |
| 207 if (submessageBuilders == null) { | 208 if (submessageBuilders == null) { |
| 208 submessageBuilders = new ArrayList<Builder>(); | 209 submessageBuilders = new ArrayList<Builder>(); |
| 209 subtreeBuildersFromField.put(fieldDescriptor, submessageBuilders); | 210 subtreeBuildersFromField.put(fieldDescriptor, submessageBuilders); |
| 210 } | 211 } |
| 211 Builder subtreeBuilder = new Builder(); | 212 Builder subtreeBuilder = new Builder(); |
| 212 submessageBuilders.add(subtreeBuilder); | 213 submessageBuilders.add(subtreeBuilder); |
| 213 return subtreeBuilder; | 214 return subtreeBuilder; |
| 214 } | 215 } |
| 215 | 216 |
| 216 /** | 217 /** |
| 217 * Build the {@code TextFormatParseInfoTree}. | 218 * Build the {@code TextFormatParseInfoTree}. |
| 218 * | 219 * |
| 219 * @return the {@code TextFormatParseInfoTree} | 220 * @return the {@code TextFormatParseInfoTree} |
| 220 */ | 221 */ |
| 221 public TextFormatParseInfoTree build() { | 222 public TextFormatParseInfoTree build() { |
| 222 return new TextFormatParseInfoTree(locationsFromField, subtreeBuildersFrom
Field); | 223 return new TextFormatParseInfoTree(locationsFromField, subtreeBuildersFrom
Field); |
| 223 } | 224 } |
| 224 } | 225 } |
| 225 } | 226 } |
| OLD | NEW |