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

com.reprezen.genflow.rapidml.csharp.helpers.NameHelper Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version
package com.reprezen.genflow.rapidml.csharp.helpers;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import com.reprezen.rapidml.Enumeration;
import com.reprezen.rapidml.ResourceDefinition;
import com.reprezen.rapidml.Structure;
import com.reprezen.rapidml.ZenModel;
import java.util.Map;

@SuppressWarnings("all")
public class NameHelper {
  private final static Map helpers = Maps.newHashMap();
  
  public static NameHelper forModel(final ZenModel model) {
    NameHelper _xblockexpression = null;
    {
      String _namespace = model.getNamespace();
      String _plus = (_namespace + ".");
      String _name = model.getName();
      final String qname = (_plus + _name);
      NameHelper _elvis = null;
      NameHelper _get = NameHelper.helpers.get(qname);
      if (_get != null) {
        _elvis = _get;
      } else {
        NameHelper _xblockexpression_1 = null;
        {
          final NameHelper helper = new NameHelper();
          NameHelper.helpers.put(qname, helper);
          _xblockexpression_1 = helper;
        }
        _elvis = _xblockexpression_1;
      }
      _xblockexpression = _elvis;
    }
    return _xblockexpression;
  }
  
  private final BiMap namespaceNames = HashBiMap.create();
  
  public String getNamespaceName(final String... components) {
    String _xblockexpression = null;
    {
      String orig = components[0];
      String _get = components[0];
      String _initialUpper = this.initialUpper(_get);
      String namespace = this.resolve(_initialUpper, orig, this.namespaceNames);
      for (int i = 1; (i < components.length); i++) {
        {
          String _orig = orig;
          String _get_1 = components[i];
          String _plus = ("." + _get_1);
          orig = (_orig + _plus);
          String _get_2 = components[i];
          String _initialUpper_1 = this.initialUpper(_get_2);
          String _plus_1 = ((namespace + ".") + _initialUpper_1);
          String _resolve = this.resolve(_plus_1, orig, this.namespaceNames);
          namespace = _resolve;
        }
      }
      _xblockexpression = namespace;
    }
    return _xblockexpression;
  }
  
  private final BiMap typeInterfaceNames = HashBiMap.create();
  
  public String getTypeInterfaceName(final Structure type) {
    String _xblockexpression = null;
    {
      final String name = type.getName();
      String _initialUpper = this.initialUpper(name);
      final String suggested = ("I" + _initialUpper);
      _xblockexpression = this.resolve(suggested, name, this.typeInterfaceNames);
    }
    return _xblockexpression;
  }
  
  private final BiMap typePocoNames = HashBiMap.create();
  
  public String getTypePocoName(final Structure type) {
    String _xblockexpression = null;
    {
      final String name = type.getName();
      final String suggested = this.initialUpper(name);
      _xblockexpression = this.resolve(suggested, name, this.typePocoNames);
    }
    return _xblockexpression;
  }
  
  private final BiMap enumerationNames = HashBiMap.create();
  
  public String getEnumerationName(final Enumeration enumeration) {
    String _xblockexpression = null;
    {
      final String name = enumeration.getName();
      final String suggested = this.initialUpper(name);
      _xblockexpression = this.resolve(suggested, name, this.enumerationNames);
    }
    return _xblockexpression;
  }
  
  private final BiMap resourceNames = HashBiMap.create();
  
  public String getResourceName(final ResourceDefinition resource) {
    String _xblockexpression = null;
    {
      final String name = resource.getName();
      final String suggested = this.initialUpper(name);
      _xblockexpression = this.resolve(suggested, name, this.resourceNames);
    }
    return _xblockexpression;
  }
  
  public String initialUpper(final String s) {
    String _substring = s.substring(0, 1);
    String _upperCase = _substring.toUpperCase();
    String _substring_1 = s.substring(1);
    return (_upperCase + _substring_1);
  }
  
  private String resolve(final String suggestedName, final String originalName, final BiMap nameMap) {
    String _xblockexpression = null;
    {
      boolean _containsKey = nameMap.containsKey(originalName);
      if (_containsKey) {
        return nameMap.get(originalName);
      }
      final String name = this.disambiguate(suggestedName, nameMap);
      nameMap.put(originalName, name);
      _xblockexpression = name;
    }
    return _xblockexpression;
  }
  
  private String disambiguate(final String name, final BiMap nameMap) {
    String _xblockexpression = null;
    {
      String result = name;
      int i = 1;
      while (nameMap.containsValue(result)) {
        int _plusPlus = i++;
        String _plus = ((name + "_") + Integer.valueOf(_plusPlus));
        result = _plus;
      }
      _xblockexpression = result;
    }
    return _xblockexpression;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy