LipidMapsParser.java

  1. /*
  2.  * Copyright 2021 Dominik Kopczynski, Nils Hoffmann.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *      http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.lifstools.jgoslin.parser;

  17. import org.lifstools.jgoslin.domain.KnownFunctionalGroups;
  18. import org.lifstools.jgoslin.domain.StringFunctions;
  19. import org.lifstools.jgoslin.domain.LipidAdduct;

  20. /**
  21.  * Parser implementation for the LIPID MAPS lipid shorthand nomenclature.
  22.  *
  23.  * @author Dominik Kopczynski
  24.  * @author Nils Hoffmann
  25.  */
  26. public class LipidMapsParser extends Parser<LipidAdduct> {

  27.     private static final String DEFAULT_GRAMMAR = "LipidMaps.g4";

  28.     private final KnownFunctionalGroups knownFunctionalGroups;
  29.    
  30.     /**
  31.      * Create a new instance of a {@link LipidMapsParser}.
  32.      *
  33.      * @param knownFunctionalGroups the known functional groups
  34.      * @param grammarContent the grammar text content
  35.      * @param quote the quotation character used in the grammar
  36.      */
  37.     public LipidMapsParser(KnownFunctionalGroups knownFunctionalGroups, String grammarContent, char quote) {
  38.         super(grammarContent, quote);
  39.         this.knownFunctionalGroups = knownFunctionalGroups;
  40.     }

  41.     /**
  42.      * Create a new instance of a {@link LipidMapsParser} with default grammar
  43.      * {@link LipidMapsParser#DEFAULT_GRAMMAR} and default quote
  44.      * {@link StringFunctions#DEFAULT_QUOTE}.
  45.      *
  46.      * @param knownFunctionalGroups the known functional groups
  47.      */
  48.     public LipidMapsParser(KnownFunctionalGroups knownFunctionalGroups) {
  49.         this(knownFunctionalGroups, StringFunctions.getResourceAsString(DEFAULT_GRAMMAR), StringFunctions.DEFAULT_QUOTE);
  50.     }

  51.     /**
  52.      * Create a new instance of a {@link LipidMapsParser} with default grammar
  53.      * {@link LipidMapsParser#DEFAULT_GRAMMAR} and default quote
  54.      * {@link StringFunctions#DEFAULT_QUOTE} and default
  55.      * {@link KnownFunctionalGroups}.
  56.      */
  57.     public LipidMapsParser() {
  58.         this(new KnownFunctionalGroups(), StringFunctions.getResourceAsString(DEFAULT_GRAMMAR), StringFunctions.DEFAULT_QUOTE);
  59.     }

  60.     @Override
  61.     public LipidMapsParserEventHandler newEventHandler() {
  62.         return new LipidMapsParserEventHandler(knownFunctionalGroups);
  63.     }

  64. }