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

com.emv.qrcode.decoder.mpm.DecoderMpm Maven / Gradle / Ivy

package com.emv.qrcode.decoder.mpm;

import java.lang.reflect.Constructor;
import java.util.AbstractMap.SimpleEntry;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.function.BiConsumer;

import com.emv.qrcode.core.configuration.DecodersMpmMap;
import com.emv.qrcode.core.exception.MerchantPresentedModeException;

// @formatter:off
public abstract class DecoderMpm {

  protected final Iterator iterator;

  protected DecoderMpm(final String source) {
    this.iterator = new DecodeMpmIterator(source);
  }

  protected abstract T decode() throws MerchantPresentedModeException;

  protected static  Entry, BiConsumer> consumerTagLengthValue(final Class clazz, final BiConsumer consumer) {
    return new SimpleEntry<>(clazz, consumer);
  }

  public static  T decode(final String source, final Class clazz) throws MerchantPresentedModeException {
    try {
      final Class> parserClass = DecodersMpmMap.getDecoder(clazz);
      final Constructor> ctor = parserClass.getConstructor(String.class);
      final DecoderMpm parser = ctor.newInstance(source);
      return clazz.cast(parser.decode());
    } catch (final MerchantPresentedModeException ex) {
      throw ex;
    } catch (final Exception ex) {
      throw new RuntimeException(ex);
    }
  }

}
// @formatter:on




© 2015 - 2025 Weber Informatics LLC | Privacy Policy