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

com.regnosys.rosetta.translate.ParserResult Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.regnosys.rosetta.translate;

import com.google.common.base.Objects;
import com.regnosys.rosetta.common.translation.Mapping;
import com.regnosys.rosetta.common.translation.MappingContext;
import com.regnosys.rosetta.common.translation.MappingProcessor;
import com.regnosys.rosetta.common.translation.Path;
import com.rosetta.model.lib.RosettaModelObjectBuilder;
import com.rosetta.model.lib.path.RosettaPath;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.xtend.lib.annotations.Data;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

@Data
@SuppressWarnings("all")
public class ParserResult {
  @Data
  public static class Context {
    private final MappingContext mappingContext;

    private final Map mappingProcessors = CollectionLiterals.newHashMap();

    private final List xmlValidationErrors = CollectionLiterals.newArrayList();

    public Context(final SynonymToEnumMapBuilder synonymToEnumMap) {
      Map, Map>> _map = synonymToEnumMap.getMap();
      MappingContext _mappingContext = new MappingContext(_map);
      this.mappingContext = _mappingContext;
    }

    @Override
    @Pure
    public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((this.mappingContext== null) ? 0 : this.mappingContext.hashCode());
      result = prime * result + ((this.mappingProcessors== null) ? 0 : this.mappingProcessors.hashCode());
      return prime * result + ((this.xmlValidationErrors== null) ? 0 : this.xmlValidationErrors.hashCode());
    }

    @Override
    @Pure
    public boolean equals(final Object obj) {
      if (this == obj)
        return true;
      if (obj == null)
        return false;
      if (getClass() != obj.getClass())
        return false;
      ParserResult.Context other = (ParserResult.Context) obj;
      if (this.mappingContext == null) {
        if (other.mappingContext != null)
          return false;
      } else if (!this.mappingContext.equals(other.mappingContext))
        return false;
      if (this.mappingProcessors == null) {
        if (other.mappingProcessors != null)
          return false;
      } else if (!this.mappingProcessors.equals(other.mappingProcessors))
        return false;
      if (this.xmlValidationErrors == null) {
        if (other.xmlValidationErrors != null)
          return false;
      } else if (!this.xmlValidationErrors.equals(other.xmlValidationErrors))
        return false;
      return true;
    }

    @Override
    @Pure
    public String toString() {
      ToStringBuilder b = new ToStringBuilder(this);
      b.add("mappingContext", this.mappingContext);
      b.add("mappingProcessors", this.mappingProcessors);
      b.add("xmlValidationErrors", this.xmlValidationErrors);
      return b.toString();
    }

    @Pure
    public MappingContext getMappingContext() {
      return this.mappingContext;
    }

    @Pure
    public Map getMappingProcessors() {
      return this.mappingProcessors;
    }

    @Pure
    public List getXmlValidationErrors() {
      return this.xmlValidationErrors;
    }
  }

  private final RosettaModelObjectBuilder rosettaInstance;

  private final ParserResult.Context context;

  public Mapping getMappingForRosetta(final String path) {
    Mapping _xblockexpression = null;
    {
      final Function1 _function = (String s) -> {
        return this.toPathElement(s);
      };
      final List split = IterableExtensions.toList(ListExtensions.map(((List)Conversions.doWrapArray(path.split("\\."))), _function));
      final Function1 _function_1 = (Mapping m) -> {
        Path _rosettaPath = m.getRosettaPath();
        List _elements = null;
        if (_rosettaPath!=null) {
          _elements=_rosettaPath.getElements();
        }
        return Boolean.valueOf(Objects.equal(_elements, split));
      };
      IterableExtensions.findFirst(this.context.mappingContext.getMappings(), _function_1);
      final Function1 _function_2 = (Mapping it) -> {
        Path _rosettaPath = it.getRosettaPath();
        return Boolean.valueOf((_rosettaPath != null));
      };
      final Function1 _function_3 = (Mapping m) -> {
        List _elements = m.getRosettaPath().getElements();
        return Boolean.valueOf(Objects.equal(_elements, split));
      };
      _xblockexpression = IterableExtensions.findFirst(IterableExtensions.filter(this.context.mappingContext.getMappings(), _function_2), _function_3);
    }
    return _xblockexpression;
  }

  private static Pattern elementPattern = Pattern.compile("(\\w*)(?:\\[(\\d*)\\])?");

  public Path.PathElement toPathElement(final String string) {
    Path.PathElement _xblockexpression = null;
    {
      final Matcher matcher = ParserResult.elementPattern.matcher(string);
      matcher.matches();
      String _group = matcher.group(1);
      final Function _function = (String i) -> {
        return Integer.valueOf(i);
      };
      Optional _map = Optional.ofNullable(matcher.group(2)).map(_function);
      Map _emptyMap = Collections.emptyMap();
      _xblockexpression = new Path.PathElement(_group, _map, _emptyMap);
    }
    return _xblockexpression;
  }

  public ParserResult(final RosettaModelObjectBuilder rosettaInstance, final ParserResult.Context context) {
    super();
    this.rosettaInstance = rosettaInstance;
    this.context = context;
  }

  @Override
  @Pure
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((this.rosettaInstance== null) ? 0 : this.rosettaInstance.hashCode());
    return prime * result + ((this.context== null) ? 0 : this.context.hashCode());
  }

  @Override
  @Pure
  public boolean equals(final Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    ParserResult other = (ParserResult) obj;
    if (this.rosettaInstance == null) {
      if (other.rosettaInstance != null)
        return false;
    } else if (!this.rosettaInstance.equals(other.rosettaInstance))
      return false;
    if (this.context == null) {
      if (other.context != null)
        return false;
    } else if (!this.context.equals(other.context))
      return false;
    return true;
  }

  @Override
  @Pure
  public String toString() {
    ToStringBuilder b = new ToStringBuilder(this);
    b.add("rosettaInstance", this.rosettaInstance);
    b.add("context", this.context);
    return b.toString();
  }

  @Pure
  public RosettaModelObjectBuilder getRosettaInstance() {
    return this.rosettaInstance;
  }

  @Pure
  public ParserResult.Context getContext() {
    return this.context;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy