001/****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one   *
003 * or more contributor license agreements.  See the NOTICE file *
004 * distributed with this work for additional information        *
005 * regarding copyright ownership.  The ASF licenses this file   *
006 * to you under the Apache License, Version 2.0 (the            *
007 * "License"); you may not use this file except in compliance   *
008 * with the License.  You may obtain a copy of the License at   *
009 *                                                              *
010 *   http://www.apache.org/licenses/LICENSE-2.0                 *
011 *                                                              *
012 * Unless required by applicable law or agreed to in writing,   *
013 * software distributed under the License is distributed on an  *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015 * KIND, either express or implied.  See the License for the    *
016 * specific language governing permissions and limitations      *
017 * under the License.                                           *
018 ****************************************************************/
019package org.apache.james.mpt.api;
020
021import java.util.Set;
022
023import com.google.common.base.Preconditions;
024import com.google.common.base.Predicates;
025import com.google.common.collect.FluentIterable;
026import com.google.common.collect.ImmutableSet;
027
028public class ImapFeatures {
029    
030    public enum Feature {
031        NAMESPACE_SUPPORT,
032        MOVE_SUPPORT,
033        USER_FLAGS_SUPPORT,
034        QUOTA_SUPPORT,
035        ANNOTATION_SUPPORT
036    }
037
038    public static ImapFeatures of(Feature... features) {
039        return new ImapFeatures(ImmutableSet.copyOf(features));
040    }
041
042    private final ImmutableSet<Feature> supportedFeatures;
043    
044    private ImapFeatures(ImmutableSet<Feature> supportedFeatures) {
045        this.supportedFeatures = supportedFeatures;
046    }
047    
048    public Set<Feature> supportedFeatures() {
049        return supportedFeatures;
050    }
051    
052    public boolean supports(Feature... features) {
053        Preconditions.checkNotNull(features);
054        ImmutableSet<Feature> requestedFeatures = ImmutableSet.copyOf(features);
055        return FluentIterable.from(requestedFeatures).allMatch(Predicates.in(supportedFeatures));
056    }
057    
058}