Package org.freezedry.persistence.tree

Examples of org.freezedry.persistence.tree.InfoNode


          LOGGER.error( message.toString() );
          throw new IllegalStateException( message.toString() );
        }
       
        // find the info node that holds the key, and the info node that holds the value
        InfoNode keyNode;
        InfoNode valueNode;
        final String name1 = entryNodes.get( 0 ).getPersistName();
        final String name2 = entryNodes.get( 1 ).getPersistName();
        if( name1.equals( mapKeyName ) && name2.equals( mapValueName ) )
        {
          keyNode = entryNodes.get( 0 );
View Full Code Here


   
    // grab the group name for the map, and create the compound node
    // that holds the map entries of the map as child nodes, and add it
    // to the parent node
    final String group = getGroupName( keyValues.get( 0 ).getFirst() );
    final InfoNode mapNode = InfoNode.createCompoundNode( null, group, null );
    parentNode.addChild( mapNode );
   
    // construct the patterns to determine if the node should be a compound node,
    // in which case we recurse back to the builder, or a leaf node, in which case
    // we simply create it here and add it to the collection node
    final String compoundRegex = "^" + group + decorationRegex;
    final Pattern compoundPattern = Pattern.compile( compoundRegex );

    final String leafRegex = compoundRegex + "$";
    final Pattern leafPattern = Pattern.compile( leafRegex );
   
    // we want to have groups by the map key. the map key is the map key in the key-value pair that.
    // for example, in friends{"Polly"}, the map key is "Polly" (including the quotes). then we
    // can parse each group into its proper node.
    final Map< String, List< Pair< String, String > > > mapKeyGroups = getMapKeyGroups( keyValues );
    for( Map.Entry< String, List< Pair< String, String > > > entry : mapKeyGroups.entrySet() )
    {
      // for each group, i.e. each key, we need a map entry node attached to the map node.
      final InfoNode mapEntryNode = InfoNode.createCompoundNode( null, mapEntryName, null );
      mapNode.addChild( mapEntryNode );

      // grab the map key and the list of key-values associated with that map key
      final String mapKey = entry.getKey();
     
      // run through the list of key-values creating the child nodes for the map-entry node
      final List< Pair< String, String > > keyValueGroup = entry.getValue();
      final List< Pair< String, String > > copiedKeyValues = new ArrayList<>( keyValueGroup );
      for( Pair< String, String > keyValue : keyValueGroup )
      {
        // check to see if any items have been removed from the list. this could happen
        // when there is a compound node that we have combined, and removed all the entries
        // from this list
        if( !copiedKeyValues.contains( keyValue ) )
        {
          continue;
        }

        // grab the key
        final String key = keyValue.getFirst();
       
        // we must figure out whether this is a compound node or a leaf node
        final Matcher compoundMatcher = compoundPattern.matcher( key );
        final Matcher leafMatcher = leafPattern.matcher( key );
        final String trimmedKey = key.replaceAll( " ", "" );
        if( leafMatcher.find() && !trimmedKey.contains( "\"}{\"" ) )
        {
          // its a leaf, create the key node
          final String rawMapKey = getDecorator( mapKey ).undecorate( mapKey );
          final InfoNode keyNode = InfoNode.createLeafNode( null, rawMapKey, mapKeyName, null );
          mapEntryNode.addChild( keyNode );
         
          // so now we need to figure out what the value is. we know that
          // it must be a number (integer, double) or a string.
          final String value = keyValue.getSecond();
          final String rawValue = getDecorator( value ).undecorate( value );
         
          // create the leaf info node and add it to the collection node
          final InfoNode valueNode = InfoNode.createLeafNode( null, rawValue, mapValueName, null );
          mapEntryNode.addChild( valueNode );
        }
        else if( compoundMatcher.find() )
        {
          // its a compound node, create the key node
          final String rawMapKey = getDecorator( mapKey ).undecorate( mapKey );
          final InfoNode keyNode = InfoNode.createLeafNode( null, rawMapKey, mapKeyName, null );
          mapEntryNode.addChild( keyNode );
         
          // in this case, we'll have several entries that have the same index, so
          // we'll need to pull those out and put them into a new key-value list
          final String separator = getPersistenceBuilder().getSeparator();
View Full Code Here

   
    // grab the group name for the collection, and create the compound node
    // that holds the elements of the collection as child nodes, and add it
    // to the parent node
    final String group = getGroupName( keyValues.get( 0 ).getFirst() );
    final InfoNode collectionNode = InfoNode.createCompoundNode( null, group, null );
    parentNode.addChild( collectionNode );
   
    // construct the patterns to determine if the node should be a compound node,
    // in which case we recurse back to the builder, or a leaf node, in which case
    // we simply create it here and add it to the collection node
    final String compoundRegex = "^" + group + decorationRegex;
    final Pattern compoundPattern = Pattern.compile( compoundRegex );
   
    final String leafRegex = compoundRegex + "$";
    final Pattern leafPattern = Pattern.compile( leafRegex );
   
    // run through the list of key-values creating the child nodes for the collection node
    final List< Pair< String, String > > copiedKeyValues = new ArrayList<>( keyValues );
    for( Pair< String, String > keyValue : keyValues )
    {
      // check to see if any items have been removed from the list. this could happen
      // when there is a compound node that we have combined, and removed all the entries
      // from this list
      if( !copiedKeyValues.contains( keyValue ) )
      {
        continue;
      }

      // grab the key
      final String key = keyValue.getFirst();
     
      // then we must figure out whether this is a compound node or a leaf node
      final Matcher compoundMatcher = compoundPattern.matcher( key );
      final Matcher leafMatcher = leafPattern.matcher( key );
      if( leafMatcher.find() )
      {
        // its a leaf, so now we need to figure out what the value is. we know that
        // it must be a number (integer, double) or a string.
        final String value = keyValue.getSecond();
        final Decorator decorator = getDecorator( value );
        final String rawValue = decorator.undecorate( value );
        final String persistName = decorator.representedClass().getSimpleName();
       
        // create the leaf info node and add it to the collection node
        final InfoNode elementNode = InfoNode.createLeafNode( null, rawValue, persistName, null );
        collectionNode.addChild( elementNode );
      }
      else if( compoundMatcher.find() )
      {
        // in this case, we'll have several entries that have the same index, so
View Full Code Here

    {
      // grab the group name for the collection, and create the compound node
      // that holds the elements of the collection as child nodes, and add it
      // to the parent node
      final String group = getGroupName( keyValues.get( 0 ).getFirst() );
      final InfoNode collectionNode = InfoNode.createCompoundNode( null, group, null );
      parentNode.addChild( collectionNode );
     
      // run through the list of key-values creating the child nodes for the collection node
      for( Pair< String, String > keyValue : keyValues )
      {
        // grab the key
        final String key = keyValue.getFirst();
       
        // this must match the validation pattern, i.e. that it is a simple collection. if
        // it doesn't match the simple collection pattern, the forward it to the compound
        // collection renderer (CollectionRenderer, this class' parent class)
        final Matcher leafMatcher = validationPattern.matcher( key );
        if( leafMatcher.find() )
        {
          // we should have list represented by "[ element1, element2, ..., elementN ]". We need to
          // pull apart the elements.
          final String valueList = keyValue.getSecond();
          final Matcher listMatcher = listPattern.matcher( valueList );
          if( listMatcher.find() )
          {
            // create the list of values
            final List< String > values = parseValueList( valueList );
           
            for( String value : values )
            {
              // its a leaf, so now we need to figure out what the value is. we know that
              // it must be a number (integer, double) or a string.
              final Decorator decorator = getDecorator( value);
              final String rawValue = decorator.undecorate( value );
              final String persistName = decorator.representedClass().getSimpleName();
             
              // create the leaf info node and add it to the collection node
              final InfoNode elementNode = InfoNode.createLeafNode( null, rawValue, persistName, null );
              collectionNode.addChild( elementNode );
            }
          }
        }
      }
View Full Code Here

TOP

Related Classes of org.freezedry.persistence.tree.InfoNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.