Java tutorial
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.zxy.commons.lang.utils; import java.lang.reflect.InvocationTargetException; import java.util.Map; import org.apache.commons.beanutils.BeanUtils; /** * Map * * <p> * <a href="MapsUtils.java"><i>View Source</i></a> * </p> * * @author zhaoxunyong@qq.com * @version 1.0 * @since 1.0 */ public final class MapsUtils { private MapsUtils() { } /** * map?null * * @param map map * @return ? */ public static boolean isEmpty(Map<?, ?> map) { return map == null || map.isEmpty(); } /** * map??null * * @param map map * @return ?? */ public static boolean isNotEmpty(Map<?, ?> map) { return !isEmpty(map); } /** * ?map{@link BeanUtils#populate(Object, Map)}? * * @param map map? * @param classes * @return ?? * @throws IllegalAccessException IllegalAccessException * @throws InstantiationException InstantiationException * @throws InvocationTargetException InvocationTargetException * @see BeanUtils#populate(Object, Map) */ public static Object convertObject(Map<String, Object> map, Class<?> classes) throws InstantiationException, IllegalAccessException, InvocationTargetException { Object object = null; object = classes.newInstance(); BeanUtils.populate(object, map); return object; } /** * ?map?{@link BeanUtils#describe(Object)}? * * @param obj * @return map? * @throws IllegalAccessException IllegalAccessException * @throws InvocationTargetException InvocationTargetException * @throws NoSuchMethodException NoSuchMethodException * @see BeanUtils#describe(Object) */ public static Map<?, ?> convertMap(Object obj) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Map<?, ?> map = BeanUtils.describe(obj); // ?key:class, map.remove("class"); return map; } }