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

org.afplib.helper.formdef.FormdefImpl Maven / Gradle / Ivy

package org.afplib.helper.formdef;

import java.io.IOException;
import java.util.LinkedList;

import org.afplib.AfpBuilder;
import org.afplib.afplib.AfplibFactory;
import org.afplib.afplib.AfplibPackage;
import org.afplib.afplib.BMM;
import org.afplib.afplib.BRS;
import org.afplib.afplib.EMM;
import org.afplib.afplib.ERS;
import org.afplib.afplib.ResourceObjectType;
import org.afplib.afplib.ResourceObjectTypeObjType;
import org.afplib.base.SF;
import org.afplib.io.AfpOutputStream;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class FormdefImpl implements Formdef {

	private static final Logger log = LoggerFactory.getLogger(Formdef.class);

	private LinkedList maps = new LinkedList();

	private SF[] bdg;
	
	FormdefImpl() {
	}
	
	@Override
	public MediumMap findByName(String mmname) {
		for(MediumMap map : maps) {
			if(mmname.equals(map.getMmname()))
				return map;
		}
		return null;
	}

	@Override
	public MediumMap findFirstByBin(int bin) {
		for(MediumMap map : maps) {
			if(map.getBin() != null && map.getBin().intValue() == bin)
				return map;
		}
		return null;
	}

	@Override
	public MediumMap findFirstByBin(int bin, Plex plex) {
		if(plex == Plex.UNKNOWN) return findFirstByBin(bin);
		for(MediumMap map : maps) {
			if(map.getBin() != null && map.getBin().intValue() == bin) {
				if(map.getPlex() != null && map.getPlex() == plex)
					return map;
			}
		}
		return null;
	}

	@Override
	public MediumMap findFirstByMediaName(String media) {
		for(MediumMap map : maps) {
			if(media.equals(map.getMediaName()))
				return map;
		}
		return null;
	}

	@Override
	public MediumMap findFirstByMediaName(String media, Plex plex) {
		if(plex == Plex.UNKNOWN) return findFirstByMediaName(media);
		for(MediumMap map : maps) {
			if(media.equals(map.getMediaName())) {
				if(map.getPlex() != null && map.getPlex() == plex)
					return map;				
			}
		}
		return null;
	}

	@Override
	public MediumMap findByHash(int hash) {
		LinkedList result = new LinkedList();
		for(MediumMap map : maps) {
			if(hash == map.hashCode())
				result.add(map);
		}
		if(result.size() == 0) return null;
		if(result.size() == 1) return result.getFirst();
		log.error("at least {} and {} share the same hash value - cannot continue.", result.getFirst(), result.get(1));
		System.exit(1);
		return null;
	}

	@Override
	public MediumMap findEqual(MediumMap map) {
		int hash = map.hashCode();
		
		LinkedList result = new LinkedList();
		for(MediumMap m : maps) {
			if(hash == m.hashCode())
				result.add(m);
		}
		if(result.size() == 0) return null;
		
		SF[] sfs1 = map.getSfs();
		
		for(MediumMap m : maps) {
			SF[] sfs2 = m.getSfs();
			if(sfs2.length != sfs1.length) continue;
			boolean equals = true;
			for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy