org.apache.commons.collections.list.UnmodifiableList Java Examples

The following examples show how to use org.apache.commons.collections.list.UnmodifiableList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();
	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.subscribe(new TopicPartition(topic, partition));

		while (true) {
			Map<String, ConsumerRecords<K, V>> topics = consumer.poll(timeout);
			if (topics == null || !topics.containsKey(topic)) {
				break;
			}
			List<ConsumerRecord<K, V>> records = topics.get(topic).records(partition);
			result.addAll(records);
			if (records.size() == 0) {
				break;
			}
		}
		consumer.commit(true);
	}

	return UnmodifiableList.decorate(result);
}
 
Example #2
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();
	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #3
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();
	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #4
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();
	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.subscribe(new TopicPartition(topic, partition));

		while (true) {
			Map<String, ConsumerRecords<K, V>> topics = consumer.poll(timeout);
			if (topics == null || !topics.containsKey(topic)) {
				break;
			}
			List<ConsumerRecord<K, V>> records = topics.get(topic).records(partition);
			result.addAll(records);
			if (records.size() == 0) {
				break;
			}
		}
		consumer.commit(true);
	}

	return UnmodifiableList.decorate(result);
}
 
Example #5
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #6
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #7
Source File: KafkaTestEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #8
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #9
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #10
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #11
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #12
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #13
Source File: KafkaTestEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Collection<ConsumerRecord<K, V>> getAllRecordsFromTopic(Properties properties, String topic, int partition, long timeout) {
	List<ConsumerRecord<K, V>> result = new ArrayList<>();

	try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(properties)) {
		consumer.assign(Arrays.asList(new TopicPartition(topic, partition)));

		while (true) {
			boolean processedAtLeastOneRecord = false;

			// wait for new records with timeout and break the loop if we didn't get any
			Iterator<ConsumerRecord<K, V>> iterator = consumer.poll(timeout).iterator();
			while (iterator.hasNext()) {
				ConsumerRecord<K, V> record = iterator.next();
				result.add(record);
				processedAtLeastOneRecord = true;
			}

			if (!processedAtLeastOneRecord) {
				break;
			}
		}
		consumer.commitSync();
	}

	return UnmodifiableList.decorate(result);
}
 
Example #14
Source File: BeanMap.java    From Penetration_Testing_POC with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the values for the BeanMap.
 * 
 * @return values for the BeanMap.  The returned collection is not
 *        modifiable.
 */
public Collection values() {
    ArrayList answer = new ArrayList( readMethods.size() );
    for ( Iterator iter = valueIterator(); iter.hasNext(); ) {
        answer.add( iter.next() );
    }
    return UnmodifiableList.decorate(answer);
}
 
Example #15
Source File: UserRights.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public List<UserRight> getOrderedRights()
{
  return UnmodifiableList.decorate(orderedRights);
}
 
Example #16
Source File: LinkedMap.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
public List subList(int fromIndexInclusive, int toIndexExclusive) {
    return UnmodifiableList.decorate(super.subList(fromIndexInclusive, toIndexExclusive));
}
 
Example #17
Source File: CollectionsTest.java    From code with Apache License 2.0 4 votes vote down vote up
@Test
public void unmodifiable(){
    List<Integer> list =  new ArrayList<>();
    List unmodifiableList = UnmodifiableList.decorate(list);

}
 
Example #18
Source File: SequencedHashMap.java    From Penetration_Testing_POC with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a List view of the keys rather than a set view.  The returned
 * list is unmodifiable.  This is required because changes to the values of
 * the list (using {@link java.util.ListIterator#set(Object)}) will
 * effectively remove the value from the list and reinsert that value at
 * the end of the list, which is an unexpected side effect of changing the
 * value of a list.  This occurs because changing the key, changes when the
 * mapping is added to the map and thus where it appears in the list.
 *
 * <p>An alternative to this method is to use {@link #keySet()}
 *
 * @see #keySet()
 * @return The ordered list of keys.  
 */
public List sequence() {
    List l = new ArrayList(size());
    Iterator iter = keySet().iterator();
    while (iter.hasNext()) {
        l.add(iter.next());
    }

    return UnmodifiableList.decorate(l);
}
 
Example #19
Source File: ListOrderedSet.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an unmodifiable view of the order of the Set.
 * 
 * @return an unmodifiable list view
 */
public List asList() {
    return UnmodifiableList.decorate(setOrder);
}
 
Example #20
Source File: ListUtils.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an unmodifiable list backed by the given list.
 * <p>
 * This method uses the implementation in the decorators subpackage.
 *
 * @param list  the list to make unmodifiable, must not be null
 * @return an unmodifiable list backed by the given list
 * @throws IllegalArgumentException  if the list is null
 */
public static List unmodifiableList(List list) {
    return UnmodifiableList.decorate(list);
}
 
Example #21
Source File: CompositeCollection.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the collections being decorated.
 *
 * @return Unmodifiable collection of all collections in this composite.
 */
public Collection getCollections() {
    return UnmodifiableList.decorate(Arrays.asList(this.all));
}
 
Example #22
Source File: IteratorChain.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Get the list of Iterators (unmodifiable)
 * 
 * @return the unmodifiable list of iterators added
 */
public List getIterators() {
    return UnmodifiableList.decorate(iteratorChain);
}
 
Example #23
Source File: CollatingIterator.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the list of Iterators (unmodifiable).
 * 
 * @return the unmodifiable list of iterators added
 */
public List getIterators() {
    return UnmodifiableList.decorate(iterators);
}
 
Example #24
Source File: ListOrderedMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an unmodifiable List view of the keys which changes as the map changes.
 * <p>
 * The returned list is unmodifiable because changes to the values of
 * the list (using {@link java.util.ListIterator#set(Object)}) will
 * effectively remove the value from the list and reinsert that value at
 * the end of the list, which is an unexpected side effect of changing the
 * value of a list.  This occurs because changing the key, changes when the
 * mapping is added to the map and thus where it appears in the list.
 * <p>
 * An alternative to this method is to use {@link #keySet()}.
 *
 * @see #keySet()
 * @return The ordered list of keys.  
 */
public List asList() {
    return UnmodifiableList.decorate(insertOrder);
}