<commit_before>/*
 *   Copyright (c) 2012 <NAME>.  All rights reserved.
 *
 *   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 cloudeventbus.pki;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;

/**
 * @author <NAME> <<EMAIL>>
 */
public class CertificateChain extends AbstractList<Certificate> {

	private final List<Certificate> internalList = new ArrayList<>();

	@Override
	public boolean add(Certificate certificate) {
		if (internalList.size() == 0) {
			return internalList.add(certificate);
		} else {
			final Certificate previousCertificate = getLast();
			previousCertificate.validateSignature(certificate);
			for (Certificate c : internalList) {
				if (c.getSerialNumber() == certificate.getSerialNumber()) {
					throw new DuplicateCertificateException("A certificate with the serial number " + certificate.getSerialNumber() + " already exists in the certificate chain.");
				}
			}
		}
		return internalList.add(certificate);
	}

	@Override
	public Certificate get(int index) {
		return internalList.get(index);
	}

	@Override
	public int size() {
		return internalList.size();
	}

	/**
	 * Returns the first certificate in the chain. This certificate is typically signed by an authority.
	 *
	 * @return the first certificate.
	 */
	public Certificate getFirst() {
		return get(0);
	}

	/**
	 * Returns the last certificate in the chain.
	 * @return the last certificate in the chain.
	 */
	public Certificate getLast() {
		return internalList.get(internalList.size() - 1);
	}
}
<commit_msg>Added a constructor for creating a non-empty chain.<commit_after>/*
 *   Copyright (c) 2012 <NAME>.  All rights reserved.
 *
 *   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 cloudeventbus.pki;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author <NAME> <<EMAIL>>
 */
public class CertificateChain extends AbstractList<Certificate> {

	private final List<Certificate> internalList = new ArrayList<>();

	public CertificateChain() {
	}

	public CertificateChain(Certificate... certificates) {
		internalList.addAll(Arrays.asList(certificates));
	}

	@Override
	public boolean add(Certificate certificate) {
		if (internalList.size() == 0) {
			return internalList.add(certificate);
		} else {
			final Certificate previousCertificate = getLast();
			previousCertificate.validateSignature(certificate);
			for (Certificate c : internalList) {
				if (c.getSerialNumber() == certificate.getSerialNumber()) {
					throw new DuplicateCertificateException("A certificate with the serial number " + certificate.getSerialNumber() + " already exists in the certificate chain.");
				}
			}
		}
		return internalList.add(certificate);
	}

	@Override
	public Certificate get(int index) {
		return internalList.get(index);
	}

	@Override
	public int size() {
		return internalList.size();
	}

	/**
	 * Returns the first certificate in the chain. This certificate is typically signed by an authority.
	 *
	 * @return the first certificate.
	 */
	public Certificate getFirst() {
		return get(0);
	}

	/**
	 * Returns the last certificate in the chain.
	 * @return the last certificate in the chain.
	 */
	public Certificate getLast() {
		return internalList.get(internalList.size() - 1);
	}
}

{'fraction_non_alphanumeric': 0.10050366300366301, 'fraction_numerical': 0.005036630036630037, 'mean_word_length': 3.838316722037652, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2140797', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1169, 'n_words': 425}