001/**
002 *
003 * Copyright 2017 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.hints;
018
019import java.util.Collections;
020import java.util.HashSet;
021import java.util.Set;
022
023import org.jivesoftware.smack.packet.Message;
024
025import org.jivesoftware.smackx.hints.element.MessageProcessingHintType;
026import org.jivesoftware.smackx.hints.element.NoCopyHint;
027import org.jivesoftware.smackx.hints.element.NoPermanentStoreHint;
028import org.jivesoftware.smackx.hints.element.NoStoreHint;
029import org.jivesoftware.smackx.hints.element.StoreHint;
030
031public class MessageProcessingHintsManager {
032
033    public static Set<MessageProcessingHintType> getHintsFrom(Message message) {
034        Set<MessageProcessingHintType> hints = null;
035
036        boolean noCopyHint = NoCopyHint.hasHint(message);
037        if (noCopyHint) {
038            hints = new HashSet<>(MessageProcessingHintType.values().length);
039            hints.add(MessageProcessingHintType.no_copy);
040        }
041
042        boolean noPermanentStoreHint = NoPermanentStoreHint.hasHint(message);
043        if (noPermanentStoreHint) {
044            if (hints == null) {
045                hints = new HashSet<>(MessageProcessingHintType.values().length);
046            }
047            hints.add(MessageProcessingHintType.no_permanent_store);
048        }
049
050        boolean noStoreHint = NoStoreHint.hasHint(message);
051        if (noStoreHint) {
052            if (hints == null) {
053                hints = new HashSet<>(MessageProcessingHintType.values().length);
054            }
055            hints.add(MessageProcessingHintType.no_store);
056        }
057
058        boolean storeHint = StoreHint.hasHint(message);
059        if (storeHint) {
060            if (hints == null) {
061                hints = new HashSet<>(MessageProcessingHintType.values().length);
062            }
063            hints.add(MessageProcessingHintType.store);
064        }
065
066        if (hints == null) {
067            return Collections.emptySet();
068        }
069
070        return hints;
071    }
072}