<commit_before>/*
 *  Copyright WebGate Consulting AG, 2013
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at:
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing 
 * permissions and limitations under the License.
 */
package org.openntf.xpt.core.dss.binding.util;

import java.util.HashMap;

import lotus.domino.Item;
import lotus.domino.Name;
import lotus.domino.Session;

public class NamesProcessor {

	private static NamesProcessor instance = null;

	private NamesProcessor() {
	}

	public static NamesProcessor getInstance() {
		if (instance == null) {
			instance = new NamesProcessor();
		}
		return instance;
	}

	public String getPerson(HashMap<String, Object> addValues, String strValue, Session sesCurrent) {
		String rcValue = strValue;
		try {
			Name nonCurrent = sesCurrent.createName(strValue);
			if (addValues != null && addValues.size() > 0) {
				if ((addValues.containsKey("isReader") || addValues.containsKey("isAuthor") || addValues.containsKey("isNames"))
						&& addValues.containsKey("showNameAs")) {
					if ("ABBREVIATE".equalsIgnoreCase(addValues.get("showNameAs").toString())) {
						rcValue = nonCurrent.getAbbreviated();
					} else if ("CN".equals(addValues.get("showNameAs"))) {
						rcValue = nonCurrent.getCommon();
					}
				}
				nonCurrent.recycle();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rcValue;
	}

	public String setPerson(String strValue, boolean isNamesValue, Session sesCurrent) {
		String rcValue = strValue;
		Name person = null;
		try {
			person = sesCurrent.createName(strValue);
			if (person != null && isNamesValue)
				rcValue = person.getCanonical();
			person.recycle();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rcValue;
	}

	public boolean setNamesField(HashMap<String, Object> addValues, Item iNotesField) {
		boolean isNamesValue = false;
		try {
			if (addValues != null && addValues.size() > 0) {
				if (iNotesField != null) {
					if (addValues.containsKey("isReader")) {
						isNamesValue = true;
						iNotesField.setReaders(true);
					} else if (addValues.containsKey("isAuthor")) {
						isNamesValue = true;
						iNotesField.setAuthors(true);
					} else if (addValues.containsKey("isNames")) {
						isNamesValue = true;
						iNotesField.setNames(true);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return isNamesValue;
	}
}
<commit_msg>Remove possible null pointer exception<commit_after>/*
 *  Copyright WebGate Consulting AG, 2013
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at:
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing 
 * permissions and limitations under the License.
 */
package org.openntf.xpt.core.dss.binding.util;

import java.util.HashMap;

import lotus.domino.Item;
import lotus.domino.Name;
import lotus.domino.Session;

public class NamesProcessor {

	private static NamesProcessor instance = null;

	private NamesProcessor() {
	}

	public static NamesProcessor getInstance() {
		if (instance == null) {
			instance = new NamesProcessor();
		}
		return instance;
	}

	public String getPerson(HashMap<String, Object> addValues, String strValue, Session sesCurrent) {
		String rcValue = strValue;
		try {
			Name nonCurrent = sesCurrent.createName(strValue);
			if (addValues != null && addValues.size() > 0) {
				if ((addValues.containsKey("isReader") || addValues.containsKey("isAuthor") || addValues.containsKey("isNames"))
						&& addValues.containsKey("showNameAs")) {
					if ("ABBREVIATE".equalsIgnoreCase(addValues.get("showNameAs").toString())) {
						rcValue = nonCurrent.getAbbreviated();
					} else if ("CN".equals(addValues.get("showNameAs"))) {
						rcValue = nonCurrent.getCommon();
					}
				}
				nonCurrent.recycle();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rcValue;
	}

	public String setPerson(String strValue, boolean isNamesValue, Session sesCurrent) {
		String rcValue = strValue;
		Name person = null;
		try {
			person = sesCurrent.createName(strValue);
			if (person != null && isNamesValue){
				rcValue = person.getCanonical();
				person.recycle();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rcValue;
	}

	public boolean setNamesField(HashMap<String, Object> addValues, Item iNotesField) {
		boolean isNamesValue = false;
		try {
			if (addValues != null && addValues.size() > 0) {
				if (iNotesField != null) {
					if (addValues.containsKey("isReader")) {
						isNamesValue = true;
						iNotesField.setReaders(true);
					} else if (addValues.containsKey("isAuthor")) {
						isNamesValue = true;
						iNotesField.setAuthors(true);
					} else if (addValues.containsKey("isNames")) {
						isNamesValue = true;
						iNotesField.setNames(true);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return isNamesValue;
	}
}

{'fraction_non_alphanumeric': 0.1130717834504026, 'fraction_numerical': 0.0034264176803152305, 'mean_word_length': 3.1610833927298647, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5531240', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1700, 'n_words': 464}