/*
 * Copyright 2013 the original author or authors.
 *
 * 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 net.kuujo.vertigo.util;

import java.util.HashMap;
import java.util.Map;

import net.kuujo.vertigo.feeder.Feeder;
import net.kuujo.vertigo.worker.Worker;

import org.vertx.java.platform.impl.ModuleIdentifier;

/**
 * Component helper methods.
 *
 * @author Jordan Halterman
 */
public final class Component {

  /**
   * Indicates whether the given name is a module name.
   *
   * This validation is performed by using the core Vert.x module name validation
   * contained in the {@link ModuleIdentifier} class.
   *
   * @param moduleName
   *   The name to check.
   * @return
   *   Indicates whether the name is a module name.
   */
  public static boolean isModuleName(String moduleName) {
    try {
      new ModuleIdentifier(moduleName);
    }
    catch (IllegalArgumentException e) {
      return false;
    }
    return true;
  }

  /**
   * Indicates whether the given name is a verticle main.
   *
   * This validation is performed by using the core Vert.x module name validation
   * contained in the {@link ModuleIdentifier} class.
   *
   * @param verticleMain
   *   The name to check.
   * @return
   *   Indicates whether the name is a verticle main.
   */
  public static boolean isVerticleMain(String verticleMain) {
    return !isModuleName(verticleMain);
  }

  @SuppressWarnings("serial")
  private static Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>() {{
    put("feeder", Feeder.class);
    put("worker", Worker.class);
  }};

  @SuppressWarnings("serial")
  private static Map<Class<?>, String> reverseTypeMap = new HashMap<Class<?>, String>() {{
    put(Feeder.class, "feeder");
    put(Worker.class, "worker");
  }};

  /**
   * Serializes a component type to a string.
   *
   * @param type
   *   The component type.
   * @return
   *   A string representation of the component type.
   */
  public static String serializeType(Class<?> type) {
    return reverseTypeMap.get(type);
  }

  /**
   * Deserializes a component type from a string.
   *
   * @param type
   *   The string representation of the component type.
   * @return
   *   The component type.
   */
  public static Class<?> deserializeType(String type) {
    return typeMap.get(type);
  }

}

@@ -641,138 +641,8 @@
 l;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport net.kuujo.vertigo.feeder.Feeder;%0Aimport net.kuujo.vertigo.worker.Worker;%0A%0A
 impo
@@ -1768,928 +1768,6 @@
  %7D%0A%0A
-  @SuppressWarnings(%22serial%22)%0A  private static Map%3CString, Class%3C?%3E%3E typeMap = new HashMap%3CString, Class%3C?%3E%3E() %7B%7B%0A    put(%22feeder%22, Feeder.class);%0A    put(%22worker%22, Worker.class);%0A  %7D%7D;%0A%0A  @SuppressWarnings(%22serial%22)%0A  private static Map%3CClass%3C?%3E, String%3E reverseTypeMap = new HashMap%3CClass%3C?%3E, String%3E() %7B%7B%0A    put(Feeder.class, %22feeder%22);%0A    put(Worker.class, %22worker%22);%0A  %7D%7D;%0A%0A  /**%0A   * Serializes a component type to a string.%0A   *%0A   * @param type%0A   *   The component type.%0A   * @return%0A   *   A string representation of the component type.%0A   */%0A  public static String serializeType(Class%3C?%3E type) %7B%0A    return reverseTypeMap.get(type);%0A  %7D%0A%0A  /**%0A   * Deserializes a component type from a string.%0A   *%0A   * @param type%0A   *   The string representation of the component type.%0A   * @return%0A   *   The component type.%0A   */%0A  public static Class%3C?%3E deserializeType(String type) %7B%0A    return typeMap.get(type);%0A  %7D%0A%0A
 %7D%0A

Clean up dead code in component utility.