drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaltekruse <...@git.apache.org>
Subject [GitHub] drill pull request: DRILL-3497: Throw UserException#validationErro...
Date Wed, 02 Sep 2015 21:23:45 GMT
Github user jaltekruse commented on a diff in the pull request:

    https://github.com/apache/drill/pull/98#discussion_r38586355
  
    --- Diff: common/src/main/java/org/apache/drill/common/map/CaseInsensitiveMap.java ---
    @@ -0,0 +1,141 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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 org.apache.drill.common.map;
    +
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Maps;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +
    +/**
    + * A special type of {@link Map} with {@link String}s as keys, and the case of a key
is ignored for operations involving
    + * keys like {@link #put}, {@link #get}, etc. The keys are stored and retrieved in lower
case. Use the static methods to
    + * create instances of this class (e.g. {@link #newConcurrentMap}).
    + *
    + * @param <VALUE> the type of values to be stored in the map
    + */
    +public class CaseInsensitiveMap<VALUE> implements Map<String, VALUE> {
    +
    +  /**
    +   * Returns a new instance of {@link java.util.concurrent.ConcurrentMap} with key case-insensitivity.
See
    +   * {@link java.util.concurrent.ConcurrentMap}.
    +   *
    +   * @param <VALUE> type of values to be stored in the map
    +   * @return key case-insensitive concurrent map
    +   */
    +  public static <VALUE> CaseInsensitiveMap<VALUE> newConcurrentMap() {
    +    return new CaseInsensitiveMap<>(Maps.<String, VALUE>newConcurrentMap());
    +  }
    +
    +  /**
    +   * Returns a new instance of {@link java.util.HashMap} with key case-insensitivity.
See {@link java.util.HashMap}.
    +   *
    +   * @param <VALUE> type of values to be stored in the map
    +   * @return key case-insensitive hash map
    +   */
    +  public static <VALUE> CaseInsensitiveMap<VALUE> newHashMap() {
    +    return new CaseInsensitiveMap<>(Maps.<String, VALUE>newHashMap());
    +  }
    +
    +  /**
    +   * Returns a new instance of {@link ImmutableMap} with key case-insensitivity. This
map is built from the given
    +   * map. See {@link ImmutableMap}.
    +   *
    +   * @param map map to copy from
    +   * @param <VALUE> type of values to be stored in the map
    +   * @return key case-insensitive immutable map
    +   */
    +  public static <VALUE> CaseInsensitiveMap<VALUE> newImmutableMap(final Map<?
extends String, ? extends VALUE> map) {
    +    final ImmutableMap.Builder<String, VALUE> builder = ImmutableMap.builder();
    +    for (final Entry<? extends String, ? extends VALUE> entry : map.entrySet())
{
    +      builder.put(entry.getKey().toLowerCase(), entry.getValue());
    +    }
    +    return new CaseInsensitiveMap<>(builder.build());
    +  }
    +
    +  private final Map<String, VALUE> underlyingMap;
    +
    +  protected CaseInsensitiveMap(final Map<String, VALUE> underlyingMap) {
    +    this.underlyingMap = underlyingMap;
    --- End diff --
    
    Would it be worth enforcing that the map being wrapped is empty? As the newImmuatableMap()
method makes a copy of the map, properly importing the keys, someone may get the wrong impression
that this constructor would remove and re-insert the values currently in the map so that they
will be accessible. Right now it would be possible to wrap a map that has uppercase in the
key names and those members would not be able to be extracted through this interface.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message