Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License 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.facebook.presto.type;
 
 
 import java.util.List;
 
 import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public final class TypeUtils
 {
     private TypeUtils()
     {
     }
 
     public static int hashPosition(Type typeBlock blockint position)
     {
         if (block.isNull(position)) {
             return 0;
         }
         return type.hash(blockposition);
     }
 
     public static boolean positionEqualsPosition(Type typeBlock leftBlockint leftPositionBlock rightBlockint rightPosition)
     {
         boolean leftIsNull = leftBlock.isNull(leftPosition);
         boolean rightIsNull = rightBlock.isNull(rightPosition);
         if (leftIsNull || rightIsNull) {
             return leftIsNull && rightIsNull;
         }
         return type.equalTo(leftBlockleftPositionrightBlockrightPosition);
     }
 
     public static List<TyperesolveTypes(List<TypeSignaturetypeNamesfinal TypeManager typeManager)
     {
         return typeNames.stream()
                 .map((TypeSignature type) -> checkNotNull(typeManager.getType(type), "Type '%s' not found"type))
                 .collect(toImmutableList());
     }
 
     public static TypeSignature parameterizedTypeName(String baseTypeSignature... argumentNames)
     {
         return new TypeSignature(base, ImmutableList.copyOf(argumentNames), ImmutableList.of());
     }
 
     public static int getHashPosition(List<? extends TypehashTypesBlock[] hashBlocksint position)
     {
         int[] hashChannels = new int[hashBlocks.length];
         for (int i = 0; i < hashBlocks.lengthi++) {
             hashChannels[i] = i;
         }
         HashGenerator hashGenerator = new InterpretedHashGenerator(ImmutableList.copyOf(hashTypes), hashChannels);
         Page page = new Page(hashBlocks);
         return hashGenerator.hashPosition(positionpage);
     }
 
     public static Block getHashBlock(List<? extends TypehashTypesBlock... hashBlocks)
     {
         checkArgument(hashTypes.size() == hashBlocks.length);
         int[] hashChannels = new int[hashBlocks.length];
         for (int i = 0; i < hashBlocks.lengthi++) {
             hashChannels[i] = i;
         }
         HashGenerator hashGenerator = new InterpretedHashGenerator(ImmutableList.copyOf(hashTypes), hashChannels);
         int positionCount = hashBlocks[0].getPositionCount();
         BlockBuilder builder = ..createFixedSizeBlockBuilder(positionCount);
         Page page = new Page(hashBlocks);
         for (int i = 0; i < positionCounti++) {
             ..writeLong(builderhashGenerator.hashPosition(ipage));
         }
         return builder.build();
     }
 
     public static Page getHashPage(Page pageList<? extends TypetypesList<IntegerhashChannels)
     {
        Block[] blocks = Arrays.copyOf(page.getBlocks(), page.getChannelCount() + 1);
        ImmutableList.Builder<TypehashTypes = ImmutableList.builder();
        Block[] hashBlocks = new Block[hashChannels.size()];
        int hashBlockIndex = 0;
        for (int channel : hashChannels) {
            hashTypes.add(types.get(channel));
            hashBlocks[hashBlockIndex++] = blocks[channel];
        }
        blocks[page.getChannelCount()] = getHashBlock(hashTypes.build(), hashBlocks);
        return new Page(blocks);
    }
New to GrepCode? Check out our FAQ X