001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  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.apache.wicket.core.util.resource.locator;
018
019import java.util.Iterator;
020
021/**
022 * Iterate over all possible combinations of style and variation
023 *
024 * @author Juergen Donnerstag
025 */
026public class StyleAndVariationResourceNameIterator implements Iterator<String>
027{
028        /** The style (see Session) */
029        private final String style;
030
031        /** The variation (see Component) */
032        private final String variation;
033
034        /** Internal state */
035        private int state = 0;
036
037        /**
038         * Construct.
039         *
040         * @param style
041         * @param variation
042         */
043        public StyleAndVariationResourceNameIterator(final String style, final String variation)
044        {
045                this.style = style;
046                this.variation = variation;
047        }
048
049        /**
050         *
051         * @see java.util.Iterator#hasNext()
052         */
053        @Override
054        public boolean hasNext()
055        {
056                return (state < 4);
057        }
058
059        /**
060         * The return value will always be null. Use getStyle() and getVariation() instead.
061         *
062         * @see java.util.Iterator#next()
063         */
064        @Override
065        public String next()
066        {
067                if (state == 0)
068                {
069                        state++;
070                        if ((style != null) && (variation != null))
071                        {
072                                return null;
073                        }
074                }
075
076                if (state == 1)
077                {
078                        state++;
079                        if (style != null)
080                        {
081                                return null;
082                        }
083                }
084
085                if (state == 2)
086                {
087                        state++;
088                        if (variation != null)
089                        {
090                                return null;
091                        }
092                }
093
094                state = 4;
095                return null;
096        }
097
098        /**
099         * @return Gets the style related to the iterator state
100         */
101        public final String getStyle()
102        {
103                return ((state == 1) || (state == 2)) ? style : null;
104        }
105
106        /**
107         * @return Gets the variation related to the iterator state
108         */
109        public final String getVariation()
110        {
111                return ((state == 1) || (state == 3)) ? variation : null;
112        }
113
114        /**
115         *
116         * @see java.util.Iterator#remove()
117         */
118        @Override
119        public void remove()
120        {
121        }
122}