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.isis.core.metamodel.specloader.validator;
020
021import java.util.Collections;
022import java.util.Iterator;
023import java.util.Set;
024
025import com.google.common.collect.Sets;
026
027public final class ValidationFailures implements Iterable<String> {
028
029    private final Set<String> messages = Sets.newLinkedHashSet();
030    
031    public void add(String pattern, Object... arguments) {
032        final String message = String.format(pattern, arguments);
033        messages.add(message);
034    }
035
036    public void assertNone() {
037        if (!occurred()) {
038            return;
039        }
040        throw new MetaModelInvalidException(messages);
041    }
042
043    public boolean occurred() {
044        return !messages.isEmpty();
045    }
046
047    public Set<String> getMessages() {
048        return Collections.unmodifiableSet(messages);
049    }
050
051    public int getNumberOfMessages() {
052        return messages.size();
053    }
054
055    @Override
056    public Iterator<String> iterator() {
057        return getMessages().iterator();
058    }
059
060
061}