Here you can find the source of merge(J just, Collection
Parameter | Description |
---|---|
just | a parameter |
justs | a parameter |
public static <J extends Set<?>> boolean merge(J just, Collection<J> justs)
//package com.java2s; /*-/*from w w w . ja v a 2s . c o m*/ * #%L * Proof Utility Library * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2014 - 2017 Live Ontologies Project * %% * 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. * #L% */ import java.util.Collection; import java.util.Iterator; import java.util.Set; public class Main { /** * Merges a given justification into a given collection of justifications. * The justification is added to the collection unless its subset is already * contained in the collection. Furthermore, all proper supersets of the * justification are removed from the collection. * * @param just * @param justs * @return {@code true} if the collection is modified as a result of this * operation and {@code false} otherwise */ public static <J extends Set<?>> boolean merge(J just, Collection<J> justs) { int justSize = just.size(); final Iterator<J> oldJustIter = justs.iterator(); boolean isASubsetOfOld = false; while (oldJustIter.hasNext()) { final J oldJust = oldJustIter.next(); if (justSize < oldJust.size()) { if (oldJust.containsAll(just)) { // new justification is smaller oldJustIter.remove(); isASubsetOfOld = true; } } else if (!isASubsetOfOld & just.containsAll(oldJust)) { // is a superset of some old justification return false; } } // justification survived all tests, it is minimal justs.add(just); return true; } }