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

com.google.web.bindery.requestfactory.shared.impl.TypeLibrary Maven / Gradle / Ivy

There is a newer version: 2.10.0
Show newest version
/*
 * Copyright 2010 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.web.bindery.requestfactory.shared.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Utility methods for querying, encoding, and decoding typed
 * payload data.
 */
public class TypeLibrary {

  public static final Collection> VALUE_TYPES;

  static {
    HashSet> valueTypes = new HashSet>();
    valueTypes.add(BigDecimal.class);
    valueTypes.add(BigInteger.class);
    valueTypes.add(Boolean.class);
    valueTypes.add(Byte.class);
    valueTypes.add(Character.class);
    valueTypes.add(Date.class);
    valueTypes.add(Double.class);
    valueTypes.add(Enum.class);
    valueTypes.add(Float.class);
    valueTypes.add(Integer.class);
    valueTypes.add(Long.class);
    valueTypes.add(Short.class);
    valueTypes.add(String.class);
    VALUE_TYPES = Collections.unmodifiableSet(valueTypes);
  }

  public static boolean isCollectionType(Class type) {
    return type == List.class || type == Set.class;
  }

  public static boolean isProxyType(Class type) {
    return !isValueType(type) && !isCollectionType(type);
  }

  public static boolean isValueType(Class type) {
    return VALUE_TYPES.contains(type);
  }  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy