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

com.ardikars.jxpacket.common.AbstractPacket Maven / Gradle / Ivy

There is a newer version: 1.2.6.RELEASE
Show newest version
/**
 * Copyright (C) 2017-2018  Ardika Rommy Sanjaya 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package com.ardikars.jxpacket.common;

import com.ardikars.jxpacket.common.util.PacketIterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Abstraction for protocol codec.
 * @author Ardika Rommy Sanjaya
 * @since 1.5.0
 */
public abstract class AbstractPacket implements Packet {

    @Override
    public  boolean contains(Class clazz) {
        return !get(clazz).isEmpty();
    }

    @Override
    public  List get(Class clazz) {
        List packets = new ArrayList<>();
        Iterator iterator = this.iterator();
        while (iterator.hasNext()) {
            Packet packet = iterator.next();
            if (clazz.isInstance(packet)) {
                packets.add(packet);
            }
        }
        return (List) packets;
    }

    @Override
    public Iterator iterator() {
        return new PacketIterator(this);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy