Java Code Examples for java.util.EnumSet#retainAll()

The following examples show how to use java.util.EnumSet#retainAll() . These examples are extracted from open source projects. 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 Project: Kettle   File: Vine.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Vine(EnumSet<BlockFace> faces) {
    this((byte) 0);
    faces.retainAll(possibleFaces);

    byte data = 0;

    if (faces.contains(BlockFace.WEST)) {
        data |= VINE_WEST;
    }

    if (faces.contains(BlockFace.NORTH)) {
        data |= VINE_NORTH;
    }

    if (faces.contains(BlockFace.SOUTH)) {
        data |= VINE_SOUTH;
    }

    if (faces.contains(BlockFace.EAST)) {
        data |= VINE_EAST;
    }

    setData(data);
}
 
Example 2
Source Project: netbeans   File: CodeStyle.java    License: Apache License 2.0 5 votes vote down vote up
private boolean check(ElementKind kind, Set<Modifier> modifiers) {
    if (this.kind != kind)
        return false;
    if (modifiers == null || modifiers.isEmpty())
        return mods.isEmpty();
    if (!modifiers.containsAll(this.mods))
        return false;
    EnumSet<Modifier> copy = EnumSet.copyOf(modifiers);
    copy.removeAll(this.mods);
    copy.retainAll(ignoreVisibility? EnumSet.of(Modifier.STATIC)
            : EnumSet.of(Modifier.STATIC, Modifier.PUBLIC, Modifier.PRIVATE, Modifier.PROTECTED)); 
    return copy.isEmpty();
}
 
Example 3
Source Project: gm4java   File: GMOperation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Throws {@link IllegalArgumentException} if more than one option from {@code mutuallyExclusive} annotations
 * exist in the {@code used} set.
 */
private static void throwMutuallyExclusiveException(final Collection<GeometryAnnotation> used,
        final boolean shouldHaveAtLeastOne, final Collection<GeometryAnnotation> mutuallyExclusive) {
    final EnumSet<GeometryAnnotation> matched = EnumSet.copyOf(used);
    matched.retainAll(mutuallyExclusive);
    if (matched.size() > 1) {
        throw new IllegalArgumentException("Geometry annotations " + join(matched, "and")
                + "are mutually exclusive");
    }
    if (shouldHaveAtLeastOne && (matched.size() != 1)) {
        throw new IllegalArgumentException("One of the following geometry annotations must be used: "
                + join(mutuallyExclusive, "or"));
    }
}
 
Example 4
Source Project: java-tool   File: CompositeRSeq.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected EnumSet<C.Feature> initFeatures() {
    EnumSet<C.Feature> features = left.features();
    features.retainAll(right.features());
    features.add(READONLY);
    features.add(LAZY);
    return features;
}
 
Example 5
Source Project: java-tool   File: CompositeSeq.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected EnumSet<C.Feature> initFeatures() {
    EnumSet<C.Feature> features = left.features();
    features.retainAll(right.features());
    features.add(READONLY);
    features.add(LAZY);
    return features;
}
 
Example 6
@Override
protected void decodePacket(ChannelHandlerContext ctx, int sequenceId, ByteBuf packet, List<Object> out) {
	EnumSet<CapabilityFlags> clientCapabilities = CodecUtils.readIntEnumSet(packet, CapabilityFlags.class);

	if (!clientCapabilities.contains(CapabilityFlags.CLIENT_PROTOCOL_41)) {
		throw new DecoderException("MySQL client protocol 4.1 support required");
	}

	ClientHandshakePacket.Builder response = ClientHandshakePacket.create();
	response.sequenceId(sequenceId);
	response.addCapabilities(clientCapabilities)
			.maxPacketSize((int)packet.readUnsignedIntLE());
	MysqlCharacterSet characterSet = MysqlCharacterSet.findById(packet.readByte());

	response.characterSet(characterSet);
	packet.skipBytes(23);
	if (packet.isReadable()) {
		response.username(CodecUtils.readNullTerminatedString(packet, characterSet.getCharset()));

		EnumSet<CapabilityFlags> serverCapabilities = session.getBackendCapabilities();
		EnumSet<CapabilityFlags> capabilities = EnumSet.copyOf(clientCapabilities);
		capabilities.retainAll(serverCapabilities);

		int authResponseLength;
		if (capabilities.contains(CapabilityFlags.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA)) {
			authResponseLength = (int)CodecUtils.readLengthEncodedInteger(packet);
		} else if (capabilities.contains(CapabilityFlags.CLIENT_SECURE_CONNECTION)) {
			authResponseLength = packet.readUnsignedByte();
		} else {
			authResponseLength = CodecUtils.findNullTermLen(packet);
		}
		response.addAuthData(packet, authResponseLength);

		if (capabilities.contains(CapabilityFlags.CLIENT_CONNECT_WITH_DB)) {
			response.database(CodecUtils.readNullTerminatedString(packet, characterSet.getCharset()));
		}

		if (capabilities.contains(CapabilityFlags.CLIENT_PLUGIN_AUTH)) {
			response.authPluginName(CodecUtils.readNullTerminatedString(packet, StandardCharsets.UTF_8));
		}

		if (capabilities.contains(CapabilityFlags.CLIENT_CONNECT_ATTRS)) {
			long keyValueLen = CodecUtils.readLengthEncodedInteger(packet);
			for (int i = 0; i < keyValueLen; i++) {
				response.addAttribute(
						CodecUtils.readLengthEncodedString(packet, StandardCharsets.UTF_8),
						CodecUtils.readLengthEncodedString(packet, StandardCharsets.UTF_8));
			}
		}
	}
	out.add(response.build());
}
 
Example 7
Source Project: netbeans   File: FileInformation.java    License: Apache License 2.0 4 votes vote down vote up
public boolean containsStatus (Set<Status> includeStatus) {
    EnumSet<Status> intersection = status.clone();
    intersection.retainAll(includeStatus);
    return !intersection.isEmpty();
}
 
Example 8
Source Project: Bytecoder   File: Collectors.java    License: Apache License 2.0 4 votes vote down vote up
private static <T, A1, A2, R1, R2, R>
Collector<T, ?, R> teeing0(Collector<? super T, A1, R1> downstream1,
                           Collector<? super T, A2, R2> downstream2,
                           BiFunction<? super R1, ? super R2, R> merger) {
    Objects.requireNonNull(downstream1, "downstream1");
    Objects.requireNonNull(downstream2, "downstream2");
    Objects.requireNonNull(merger, "merger");

    Supplier<A1> c1Supplier = Objects.requireNonNull(downstream1.supplier(), "downstream1 supplier");
    Supplier<A2> c2Supplier = Objects.requireNonNull(downstream2.supplier(), "downstream2 supplier");
    BiConsumer<A1, ? super T> c1Accumulator =
            Objects.requireNonNull(downstream1.accumulator(), "downstream1 accumulator");
    BiConsumer<A2, ? super T> c2Accumulator =
            Objects.requireNonNull(downstream2.accumulator(), "downstream2 accumulator");
    BinaryOperator<A1> c1Combiner = Objects.requireNonNull(downstream1.combiner(), "downstream1 combiner");
    BinaryOperator<A2> c2Combiner = Objects.requireNonNull(downstream2.combiner(), "downstream2 combiner");
    Function<A1, R1> c1Finisher = Objects.requireNonNull(downstream1.finisher(), "downstream1 finisher");
    Function<A2, R2> c2Finisher = Objects.requireNonNull(downstream2.finisher(), "downstream2 finisher");

    Set<Collector.Characteristics> characteristics;
    Set<Collector.Characteristics> c1Characteristics = downstream1.characteristics();
    Set<Collector.Characteristics> c2Characteristics = downstream2.characteristics();
    if (CH_ID.containsAll(c1Characteristics) || CH_ID.containsAll(c2Characteristics)) {
        characteristics = CH_NOID;
    } else {
        EnumSet<Collector.Characteristics> c = EnumSet.noneOf(Collector.Characteristics.class);
        c.addAll(c1Characteristics);
        c.retainAll(c2Characteristics);
        c.remove(Collector.Characteristics.IDENTITY_FINISH);
        characteristics = Collections.unmodifiableSet(c);
    }

    class PairBox {
        A1 left = c1Supplier.get();
        A2 right = c2Supplier.get();

        void add(T t) {
            c1Accumulator.accept(left, t);
            c2Accumulator.accept(right, t);
        }

        PairBox combine(PairBox other) {
            left = c1Combiner.apply(left, other.left);
            right = c2Combiner.apply(right, other.right);
            return this;
        }

        R get() {
            R1 r1 = c1Finisher.apply(left);
            R2 r2 = c2Finisher.apply(right);
            return merger.apply(r1, r2);
        }
    }

    return new CollectorImpl<>(PairBox::new, PairBox::add, PairBox::combine, PairBox::get, characteristics);
}
 
Example 9
static void createRelation(StringBuilder b, 
            Class<?> first, FusionMode[] firstModes, Class<?> second, FusionMode[] secondModes) {
        EnumSet<FusionMode> ef0 = EnumSet.noneOf(FusionMode.class);
        ef0.addAll(Arrays.asList(firstModes));

        EnumSet<FusionMode> ef = EnumSet.noneOf(FusionMode.class);
        ef.addAll(Arrays.asList(firstModes));
        
        EnumSet<FusionMode> es = EnumSet.noneOf(FusionMode.class);
        es.addAll(Arrays.asList(secondModes));
        
        ef.retainAll(es);
        ef.remove(FusionMode.NONE);
        
        if (ef.isEmpty() || (ef0.contains(FusionMode.BOUNDARY) && es.contains(FusionMode.BOUNDARY))) {
            b.append("'>Unfuseable");
        } else {
//            b.append("' bgcolor='#FFFFC0'>");
            b.append("' bgcolor='#FFCC80'>");
            int i = 0;
            for (FusionMode fm : ef) {
                b.append("        ");
                
                String c = "#000000";
                
//                switch (fm) {
//                case SCALAR:
//                    c = "#CF0000";
//                    break;
//                case SYNC:
//                    c = "#FF00FF";
//                    break;
//                case ASYNC:
//                    c = "#8080FF";
//                    break;
//                case CONDITIONAL:
//                    c = "#00CC00";
//                    break;
//                default:
//                }
                
                b
                .append("<font color='").append(c).append("'>")
                .append(fm.toString().substring(0, 1))
                .append(fm.toString().substring(1).toLowerCase())
                .append("</font>");
                if (i != ef.size() - 1) {
                    b.append("<br/>");
                }
                b.append("\r\n");
            }
        }
    }