All Downloads are FREE. Search and download functionalities are using the official Maven repository.

os.rio-core.0.6.0.source-code.VariableMap Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 Objectos, Fábrica de Software LTDA.
 *
 * 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 br.com.objectos.rio;

import java.util.Map;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.StandardSystemProperty;
import com.google.common.collect.Maps;

/**
 * @author [email protected] (Marcio Endo)
 */
class VariableMap {

  private final Map map = Maps.newHashMap();

  private VariableMap() {
  }

  public static VariableMap newMap() {
    VariableMap map = new VariableMap();

    for (StandardSystemProperty systemProperty : StandardSystemProperty.values()) {
      map.put(systemProperty.key(), systemProperty.value());
    }

    return map;
  }

  public Optional get(String key) {
    String maybe = map.get(key);
    return Optional.fromNullable(maybe);
  }

  public void put(String key, String value) {
    Preconditions.checkNotNull(key);

    if (value != null) {
      map.put(key, value);
    }
  }

  public String expandOrSelf(String variableName) {
    String key = variableName;
    int size = variableName.length();
    if (size > 4) {
      key = variableName.substring(2, size - 2);
    }
    return get(key).or(variableName);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy