package com.hea3ven.tools.mappings.parser.srg;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.io.*;

import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;

import com.hea3ven.tools.mappings.*;
import com.hea3ven.tools.mappings.parser.IMappingsParser;

public class SrgMappingsParser implements IMappingsParser {
	private Mapping mapping = new Mapping();

	private Splitter splitter = Splitter.on(CharMatcher.WHITESPACE);

	public SrgMappingsParser() {
		this(new Mapping());
	}

	public SrgMappingsParser(Mapping mapping) {
		this.mapping = mapping;
	}

	@Override
	public Mapping getMapping() {
		return mapping;
	}

	@Override
	public void setMapping(Mapping mapping) {
		this.mapping = mapping;
	}

	@Override
	public void parse(InputStream stream) throws IOException {
		parse(new InputStreamReader(stream));
	}

	@Override
	public void parse(Reader reader) throws IOException {
		BufferedReader br = new BufferedReader(reader);
		for (String line = br.readLine(); line != null; line = br.readLine()) {
			parseLine(line);
		}
	}

	private void parseLine(String line) {
		String type = line.substring(0, line.indexOf(':'));
		String value = line.substring(line.indexOf(':') + 1).trim();
		if (type.equals("CL")) {
			String[] parts = Iterables.toArray(splitter.split(value), String.class);
//			ClsMapping cls = mapping.getCls("asd");
//			cls.setDst((!parts[1].contains("$")) ? parts[1] : parts[1].split("\\$")[1]);
			mapping.addCls(parts[0], parts[1]);
		} else if (type.equals("FD")) {
			String[] parts = Iterables.toArray(splitter.split(value), String.class);
			mapping.addFld(parts[0], parts[1]);
		} else if (type.equals("MD")) {
			String[] parts = Iterables.toArray(splitter.split(value), String.class);
			mapping.addMthd(parts[0], parts[2], parts[1]);
		}
	}

	@Override
	public void write(OutputStream stream) throws IOException {
		write(new OutputStreamWriter(stream));
	}

	@Override
	public void write(Writer writer) throws IOException {
		throw new NotImplementedException();
	}

	/**
	 * @deprecated Use {@link #parse(InputStream)}.
	 */
	@Deprecated
	public Mapping add(InputStream stream) throws IOException {
		parse(stream);
		return getMapping();
	}

	/**
	 * @deprecated Use {@link #parse(Reader)}.
	 */
	@Deprecated
	public Mapping add(Reader reader) throws IOException {
		parse(reader);
		return getMapping();
	}
}

package com.hea3ven.tools.mappings.parser.srg;

import java.io.*;

import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;

import com.hea3ven.tools.mappings.Mapping;
import com.hea3ven.tools.mappings.parser.IMappingsParser;

public class SrgMappingsParser implements IMappingsParser {
	private Mapping mapping = new Mapping();

	private Splitter splitter = Splitter.on(CharMatcher.WHITESPACE);

	public SrgMappingsParser() {
		this(new Mapping());
	}

	public SrgMappingsParser(Mapping mapping) {
		this.mapping = mapping;
	}

	@Override
	public Mapping getMapping() {
		return mapping;
	}

	@Override
	public void setMapping(Mapping mapping) {
		this.mapping = mapping;
	}

	@Override
	public void parse(InputStream stream) throws IOException {
		parse(new InputStreamReader(stream));
	}

	@Override
	public void parse(Reader reader) throws IOException {
		BufferedReader br = new BufferedReader(reader);
		for (String line = br.readLine(); line != null; line = br.readLine()) {
			parseLine(line);
		}
	}

	private void parseLine(String line) {
		String type = line.substring(0, line.indexOf(':'));
		String value = line.substring(line.indexOf(':') + 1).trim();
		if (type.equals("CL")) {
			String[] parts = Iterables.toArray(splitter.split(value), String.class);
//			ClsMapping cls = mapping.getCls("asd");
//			cls.setDst((!parts[1].contains("$")) ? parts[1] : parts[1].split("\\$")[1]);
			mapping.addCls(parts[0], parts[1]);
		} else if (type.equals("FD")) {
			String[] parts = Iterables.toArray(splitter.split(value), String.class);
			mapping.addFld(parts[0], parts[1]);
		} else if (type.equals("MD")) {
			String[] parts = Iterables.toArray(splitter.split(value), String.class);
			mapping.addMthd(parts[0], parts[2], parts[1]);
		}
	}

	@Override
	public void write(OutputStream stream) throws IOException {
		write(new OutputStreamWriter(stream));
	}

	@Override
	public void write(Writer writer) throws IOException {
		throw new RuntimeException("Not implemented");
	}

	/**
	 * @deprecated Use {@link #parse(InputStream)}.
	 */
	@Deprecated
	public Mapping add(InputStream stream) throws IOException {
		parse(stream);
		return getMapping();
	}

	/**
	 * @deprecated Use {@link #parse(Reader)}.
	 */
	@Deprecated
	public Mapping add(Reader reader) throws IOException {
		parse(reader);
		return getMapping();
	}
}

Change import