集册 Java实例教程 从提供的集合复制条目,直到到达屏障项。

从提供的集合复制条目,直到到达屏障项。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

522
从提供的集合复制条目,直到到达屏障项。

/*

 * Copyright Terracotta, Inc.

 *

 * 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 com.nowjava;/** 来自 时 代 J a v a - nowjava.com**/


import java.util.LinkedHashSet;


import java.util.Set;


public class Main {

    /**

     * Copies entries from the {@code Set} provided until reaching a barrier item.

     * The items are copied in iterator order and the result does not include the barrier.

     *

     * @param source the {@code Set} from which the items are copied

     * @param barrier the barrier indicating the end of the copy

     *

     * @return a new, entry-ordered {@code Set} containing the subset of {@code source}

     */

    static Set<String> copyUntil(final Set<String> source,

            final String barrier) {

        final Set<String> subset = new LinkedHashSet<String>();

        for (
展开阅读全文