All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.i18n.server.StringMapMessageTranslation Maven / Gradle / Ivy

There is a newer version: 2.10.0
Show newest version
/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.i18n.server;

import com.google.gwt.i18n.server.Message.AlternateFormMapping;
import com.google.gwt.i18n.shared.AlternateMessageSelector.AlternateForm;
import com.google.gwt.i18n.shared.GwtLocale;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * A {@link MessageTranslation} that is backed by a map, along with an ordered
 * list of keys.
 */
class StringMapMessageTranslation
    implements MessageTranslation {

  private final String defaultMessage;
  private final List forms;
  private final Map map;
  private final GwtLocale locale;

  public StringMapMessageTranslation(String defaultMessage,
      List forms, Map map, GwtLocale locale) {
    this.defaultMessage = defaultMessage;
    this.forms = forms;
    this.map = map;
    this.locale = locale;
  }

  public Iterable getAllMessageForms() {
    return new Iterable() {
      protected final Iterator iter = forms.iterator();

      public Iterator iterator() {
        return new Iterator() {
          public boolean hasNext() {
            return iter.hasNext();
          }

          public AlternateFormMapping next() {
            String form = iter.next();
            return new AlternateFormMapping(Arrays.asList(new AlternateForm(
                form, form)), map.get(form));
          }

          public void remove() {
            throw new UnsupportedOperationException();
          }
        };
      }
    };
  }

  public String getDefaultMessage() {
    return defaultMessage;
  }

  public GwtLocale getMatchedLocale() {
    return locale;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy