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

xapi.gwt.model.ModelGwt Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.gwt.model;

import static xapi.util.impl.PairBuilder.entryOf;

import java.util.Iterator;
import java.util.Map.Entry;

import xapi.model.impl.AbstractModel;

public class ModelGwt extends AbstractModel{

  private final class Itr implements Iterable> {

    private final String[] keys;

    private Itr(final String[] keys) {
      this.keys = keys;
    }

    @Override
    public Iterator> iterator() {
      return new Iterator>() {

        int pos = 0;
        @Override
        public boolean hasNext() {
          return pos < keys.length;
        }

        @Override
        public Entry next() {
          final String key = keys[pos];
          Object value = getProperty(key);
          if (value == null) {
            final Class type = getPropertyType(key);
            if (type.isPrimitive()) {
              value = AbstractModel.getPrimitiveValue(type);
            }
          }
          return entryOf(key, value);
        }
      };
    }
  }

  @Override
  public Iterable> getProperties() {
    // Because we know all generated Gwt modules MUST implement property names,
    // We can safely enforce serialization ordering using .getPropertyNames()
    final String[] names = getPropertyNames();
    return new Itr(names);
  }

  @Override
  public Class getPropertyType(final String key) {
    throw new UnsupportedOperationException("Type "+getClass()+" does not handle property type "+key);
  }

  @Override
  public String[] getPropertyNames() {
    return new String[0];
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy