Created
May 10, 2018 17:53
-
-
Save drewbrokke/cc135642e0a5a0b20a984479275b3f1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright (c) 2000-present Liferay, Inc. All rights reserved. | |
* | |
* This library is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU Lesser General Public License as published by the Free | |
* Software Foundation; either version 2.1 of the License, or (at your option) | |
* any later version. | |
* | |
* This library is distributed in the hope that it will be useful, but WITHOUT | |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
* details. | |
*/ | |
package com.liferay.user.associated.data.util; | |
import com.liferay.portal.kernel.model.BaseModel; | |
import com.liferay.portal.kernel.util.StringUtil; | |
import java.lang.reflect.Method; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* @author Drew Brokke | |
*/ | |
public class UserIdFieldNameUtil { | |
public static <T extends BaseModel> String[] getUserIdFieldNames( | |
Class<T> clazz) { | |
List<String> userIdFieldNames = new ArrayList<>(); | |
Method[] methods = clazz.getMethods(); | |
for (Method method : methods) { | |
String methodName = method.getName(); | |
if (methodName.startsWith("get") && methodName.endsWith("UserId")) { | |
String formattedName = StringUtil.replaceFirst( | |
methodName, "get", ""); | |
userIdFieldNames.add( | |
StringUtil.lowerCaseFirstLetter(formattedName)); | |
} | |
} | |
return userIdFieldNames.toArray(new String[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment