com.sun.xml.ws.message.AttachmentSetImpl Maven / Gradle / Ivy
Show all versions of rt Show documentation
/*
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.ws.message;
import com.sun.xml.ws.api.message.AttachmentSet;
import com.sun.xml.ws.api.message.Attachment;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Default dumb {@link AttachmentSet} implementation backed by {@link ArrayList}.
*
*
* The assumption here is that the number of attachments are small enough to
* justify linear search in {@link #get(String)}.
*
* @author Kohsuke Kawaguchi
*/
public final class AttachmentSetImpl implements AttachmentSet {
private final ArrayList attList = new ArrayList<>();
/**
* Creates an empty {@link AttachmentSet}.
*/
public AttachmentSetImpl() {
}
/**
* Creates an {@link AttachmentSet} by copying contents from another.
*/
public AttachmentSetImpl(Iterable base) {
for (Attachment a : base)
add(a);
}
@Override
public Attachment get(String contentId) {
for( int i=attList.size()-1; i>=0; i-- ) {
Attachment a = attList.get(i);
if(a.getContentId().equals(contentId))
return a;
}
return null;
}
@Override
public boolean isEmpty() {
return attList.isEmpty();
}
@Override
public void add(Attachment att) {
attList.add(att);
}
@Override
public Iterator iterator() {
return attList.iterator();
}
}