Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.java.ao.schema.info;
  
  
  import java.util.Map;
 import java.util.Set;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
 class ImmutableEntityInfo<T extends RawEntity<K>, K> implements EntityInfo<T, K>
 {
 
     private final Class<T> entityType;
     private final String tableName;
     private final FieldInfo<K> primaryKey;
     private final Map<StringFieldInfofieldByName;
     private final Map<MethodFieldInfofieldByMethod;
 
             Class<T> entityType,
             String tableName,
             Set<FieldInfofields)
     {
         this. = checkNotNull(entityType"entityType");
         this. = checkNotNull(tableName"tableName");
 
         ImmutableMap.Builder<StringFieldInfofieldByNameBuilder = ImmutableMap.builder();
         ImmutableMap.Builder<MethodFieldInfofieldByMethodBuilder = ImmutableMap.builder();
         FieldInfo primaryKey = null;
         for (FieldInfo field : fields)
         {
             fieldByNameBuilder.put(field.getName(), field);
             if (field.getPolymorphicName() != null)
             {
                 fieldByNameBuilder.put(field.getPolymorphicName(), field);
             }
             if (field.isPrimary())
             {
                 primaryKey = field;
             }
             if (field.hasAccessor())
             {
                 fieldByMethodBuilder.put(field.getAccessor(), field);
             }
             if (field.hasMutator())
             {
                 fieldByMethodBuilder.put(field.getMutator(), field);
             }
         }
          = fieldByNameBuilder.build();
          = fieldByMethodBuilder.build();
         //noinspection unchecked
         this. = checkNotNull(primaryKey"primaryKey");
     }
 
     @Override
     public Class<T> getEntityType()
     {
         return ;
     }
 
     @Override
     public String getName()
     {
         return ;
     }
 
     @Override
     public FieldInfo<K> getPrimaryKey()
     {
         return ;
     }
 
     @Override
     public Set<FieldInfogetFields()
     {
         return ImmutableSet.copyOf(.values());
     }
 
     @Override
     public Set<StringgetFieldNames()
     {
         return ImmutableSet.copyOf(Collections2.transform(getFields(), .));
     }
 
     @Override
     public FieldInfo getField(Method method)
     {
         return .get(method);
     }
 
     @Override
     public FieldInfo getField(String fieldName)
     {
         return .get(fieldName);
    }
    @Override
    public boolean hasAccessor(Method method)
    {
        FieldInfo field = .get(method);
        return field != null && method.equals(field.getAccessor());
    }
    @Override
    public boolean hasMutator(Method method)
    {
        FieldInfo field = .get(method);
        return field != null && method.equals(field.getMutator());
    }
    @Override
    public boolean hasField(String fieldName)
    {
        return .containsKey(fieldName);
    }
    @Override
    public boolean equals(Object o)
    {
        if (this == oreturn true;
        if (o == null || getClass() != o.getClass()) return false;
        ImmutableEntityInfo that = (ImmutableEntityInfoo;
        return !( != null ? !.equals(that.entityType) : that.entityType != null);
    }
    @Override
    public int hashCode()
    {
        return  != null ? .hashCode() : 0;
    }
New to GrepCode? Check out our FAQ X