Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013-2015 Amazon Technologies, Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at:
   *
   *    http://aws.amazon.com/apache2.0
   *
  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  * OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.amazonaws.services.dynamodbv2.datamodeling;
 
 import java.util.List;
 import java.util.Map;
 
A virtual AttributeTransformer that transforms and untransforms attributes by running them through a cascading series of child AttributeTransformer instances.
 
 public class AttributeTransformerChain implements AttributeTransformer {
 
     private final List<AttributeTransformertransformers;

    
Creates a new transformer chain from the given array of transformers. When transforming attributes, these transformers are invoked from first to last; when untransforming they are invoked in the opposite order.

Parameters:
transformers the chain of transformers.
 
     public AttributeTransformerChain(
             final AttributeTransformer... transformers) {
 
         this(Arrays.asList(transformers));
     }

    
Creates a new transformer chain from the given list of transformers. When transforming attributes, these transformers are invoked from first to last; when untransforming they are invoked in the opposite order.

Parameters:
transformers the chain of transformers.
 
     public AttributeTransformerChain(
             final List<AttributeTransformertransformers) {
 
         this. = Collections.unmodifiableList(
             new ArrayList<AttributeTransformer>(transformers));
     }

    

Returns:
the transformers in this chain
 
         return ;
     }
 
     @Override
     public Map<StringAttributeValuetransform(
             final Parameters<?> parameters) {
 
         ProxyParameters<?> proxy = new ProxyParameters(parameters);
 
         for (int i = 0; i < .size(); ++i) {
             proxy.setAttributeValues(.get(i).transform(proxy));
         }
 
         return proxy.getAttributeValues();
     }
 
     @Override
     public Map<StringAttributeValueuntransform(
             final Parameters<?> parameters) {
 
         ProxyParameters<?> proxy = new ProxyParameters(parameters);
 
         for (int i = .size() - 1; i >= 0; --i) {
             proxy.setAttributeValues(.get(i).untransform(proxy));
         }
 
         return proxy.getAttributeValues();
     }
 
     @Override
     public String toString() {
         return .toString();
     }

    
A Parameters proxy that intercepts calls to getAttributeValues and overrides the return value.
    private static class ProxyParameters<T> implements Parameters<T> {
        private final Parameters<T> delegate;
        private Map<StringAttributeValuevalues;

        
Create a new proxy wrapping the given Parameters object.

Parameters:
delegate the parameters object to wrap
        public ProxyParameters(final Parameters<T> delegate) {
            this. = delegate;
            this. = delegate.getAttributeValues();
        }
        @Override
        public Map<StringAttributeValuegetAttributeValues() {
            return ;
        }

        
Changes the attribute values for this instance.

Parameters:
values the new values
        public void setAttributeValues(
                final Map<StringAttributeValuevalues) {
            this. = Collections.unmodifiableMap(values);
        }
        @Override
        public boolean isPartialUpdate() {
            return .isPartialUpdate();
        }
        @Override
        public Class<T> getModelClass() {
            return .getModelClass();
        }
        @Override
        public DynamoDBMapperConfig getMapperConfig() {
            return .getMapperConfig();
        }
        @Override
        public String getTableName() {
            return .getTableName();
        }
        @Override
        public String getHashKeyName() {
            return .getHashKeyName();
        }
        @Override
        public String getRangeKeyName() {
            return .getRangeKeyName();
        }
    }
New to GrepCode? Check out our FAQ X