List of usage examples for org.apache.commons.lang ArrayUtils add
public static short[] add(short[] array, short element)
Copies the given array and adds the given element at the end of the new array.
From source file:org.projectforge.user.PFUserDO.java
@Override public ModificationStatus copyValuesFrom(final BaseDO<? extends Serializable> src, String... ignoreFields) { ignoreFields = (String[]) ArrayUtils.add(ignoreFields, "password"); // NPE save considering ignoreFields final PFUserDO user = (PFUserDO) src; ModificationStatus modificationStatus = AbstractBaseDO.copyValues(user, this, ignoreFields); if (user.getPassword() != null) { setPassword(user.getPassword()); checkAndFixPassword();//from w w w . j a v a 2 s . c o m if (getPassword() != null) { modificationStatus = ModificationStatus.MAJOR; } } return modificationStatus; }
From source file:org.quackbot.hooks.core.CoreQuackbotHookTest.java
@DataProvider(name = "onCommandLongTests") public Object[][] getOnCommandLongTests() { Object[][] test = { { "?Message4-Array23 " + args4, new OnCommandLong("Message4-Array23", 5, 0) { public String onCommand(CommandEvent event, String hello0, String hello1, String[] hello23, String hello4) throws Exception { args = (String[][]) ArrayUtils.add(args, makeArray(hello0)); args = (String[][]) ArrayUtils.add(args, makeArray(hello1)); args = (String[][]) ArrayUtils.add(args, hello23); args = (String[][]) ArrayUtils.add(args, makeArray(hello4)); return "Success"; }/*from www. j av a2 s . co m*/ }, new String[][] { { "hello0" }, { "hello1" }, { "hello2", "hello3" }, { "hello4" } } }, { "?Message4-Array34 " + args4, new OnCommandLong("Message4-Array34", 5, 0) { public String onCommand(CommandEvent event, String hello0, String hello1, String hello2, String[] hello34) throws Exception { args = (String[][]) ArrayUtils.add(args, makeArray(hello0)); args = (String[][]) ArrayUtils.add(args, makeArray(hello1)); args = (String[][]) ArrayUtils.add(args, makeArray(hello2)); args = (String[][]) ArrayUtils.add(args, hello34); return "Success"; } }, new String[][] { { "hello0" }, { "hello1" }, { "hello2" }, { "hello3", "hello4" } } }, { "?Message4-Array01 " + args4, new OnCommandLong("Message4-Array01", 5, 0) { public String onCommand(CommandEvent event, String[] hello01, String hello2, String hello3, String hello4) throws Exception { args = (String[][]) ArrayUtils.add(args, hello01); args = (String[][]) ArrayUtils.add(args, makeArray(hello2)); args = (String[][]) ArrayUtils.add(args, makeArray(hello3)); args = (String[][]) ArrayUtils.add(args, makeArray(hello4)); return "Success"; } }, new String[][] { { "hello0", "hello1" }, { "hello2" }, { "hello3" }, { "hello4" } } }, { "?Message3-Array23 " + args3, new OnCommandLong("Message3-Array23", 4, 0) { public String onCommand(CommandEvent event, String hello0, String hello1, String[] hello23, String hello4) throws Exception { args = (String[][]) ArrayUtils.add(args, makeArray(hello0)); args = (String[][]) ArrayUtils.add(args, makeArray(hello1)); args = (String[][]) ArrayUtils.add(args, hello23); args = (String[][]) ArrayUtils.add(args, makeArray(hello4)); return "Success"; } }, new String[][] { { "hello0" }, { "hello1" }, { "hello2", "hello3" }, { null } } }, { "?Message3-Array34 " + args3, new OnCommandLong("Message3-Array34", 4, 0) { public String onCommand(CommandEvent event, String hello0, String hello1, String hello2, String[] hello34) throws Exception { args = (String[][]) ArrayUtils.add(args, makeArray(hello0)); args = (String[][]) ArrayUtils.add(args, makeArray(hello1)); args = (String[][]) ArrayUtils.add(args, makeArray(hello2)); args = (String[][]) ArrayUtils.add(args, hello34); return "Success"; } }, new String[][] { { "hello0" }, { "hello1" }, { "hello2" }, { "hello3" } //Do not expect null as the last element as its an optional parameter } }, { "?Message3-Array01 " + args3, new OnCommandLong("Message3-Array01", 4, 0) { public String onCommand(CommandEvent event, String[] hello01, String hello2, String hello3, String hello4) throws Exception { args = (String[][]) ArrayUtils.add(args, hello01); args = (String[][]) ArrayUtils.add(args, makeArray(hello2)); args = (String[][]) ArrayUtils.add(args, makeArray(hello3)); args = (String[][]) ArrayUtils.add(args, makeArray(hello4)); return "Success"; } }, new String[][] { { "hello0", "hello1" }, { "hello2" }, { "hello3" }, { null } } } }; return test; }
From source file:org.quackbot.hooks.core.CoreQuackbotListener.java
protected String executeOnCommandLong(CommandEvent commandEvent) throws Exception { try {//from w w w .j av a 2s . c o m Command command = commandEvent.getCommandClass(); Class clazz = command.getClass(); for (Method curMethod : clazz.getMethods()) if (curMethod.getName().equalsIgnoreCase("onCommand") && curMethod.getParameterTypes().length != 1) { //Get parameters leaving off the first one Class[] parameters = (Class[]) ArrayUtils.remove(curMethod.getParameterTypes(), 0); Object[] args = new Object[0]; String[] userArgs = commandEvent.getArgs(); log.debug("UserArgs: " + StringUtils.join(userArgs, ", ")); //Try and fill argument list, handling arrays for (int i = 0; i < userArgs.length; i++) { log.trace("Current parameter: " + i); if (i < parameters.length && parameters[i].isArray()) { log.trace("Parameter " + i + " is an array"); //Look ahead to see how big of an array we need int arrayLength = parameters.length - (i - 1); for (int s = i; s < parameters.length; s++) if (!parameters[s].isArray()) arrayLength--; //Add our array of specified length log.trace("Parameter " + i + " is an array. Assigning it the next " + arrayLength + " args"); Object[] curArray = ArrayUtils.subarray(userArgs, i, i + arrayLength); args = ArrayUtils.add(args, curArray); log.trace("Parameter " + i + " set to " + StringUtils.join(curArray, ", ")); //Move the index forward to account for the args folded into the array i += arrayLength - 1; } else { log.trace("User arg " + i + " isn't an array, assigning " + userArgs[i]); args = ArrayUtils.add(args, userArgs[i]); } } //Pad the args with null values args = Arrays.copyOf(args, parameters.length); //Prefix with command event args = ArrayUtils.addAll(new Object[] { commandEvent }, args); log.trace("Args minus CommandEvent: " + StringUtils.join(ArrayUtils.remove(args, 0), ", ")); //Execute method return (String) curMethod.invoke(command, args); } } catch (InvocationTargetException e) { //Unrwap if nessesary Throwable cause = e.getCause(); if (cause != null && cause instanceof Exception) throw (Exception) e.getCause(); throw e; } return null; }
From source file:org.seedstack.ldap.internal.DefaultLdapService.java
@Override public LdapUserContext findUser(String identityAttributeValue) throws LdapException { try {/* w w w . j ava2s . c om*/ Filter userClassFilter; if (userObjectClass != null && !userObjectClass.isEmpty()) { userClassFilter = Filter.createEqualityFilter("objectClass", userObjectClass); } else { userClassFilter = Filter.createPresenceFilter("objectClass"); } Filter filter = Filter.createANDFilter(userClassFilter, Filter.createEqualityFilter(userIdentityAttribute, identityAttributeValue)); LOGGER.debug(filter.toString()); String[] attributesToRetrieve; if (userAdditionalAttributes != null) { attributesToRetrieve = userAdditionalAttributes; if (!ArrayUtils.contains(attributesToRetrieve, "cn") || !ArrayUtils.contains(attributesToRetrieve, "CN")) { ArrayUtils.add(attributesToRetrieve, "cn"); } } else { attributesToRetrieve = new String[] { "cn" }; } SearchResult searchResult = ldapConnectionPool.search(StringUtils.join(userBase, ','), SearchScope.SUB, filter, attributesToRetrieve); if (searchResult.getEntryCount() != 1) { throw new UnknownAccountException(); } SearchResultEntry searchResultEntry = searchResult.getSearchEntries().get(0); String dn = searchResultEntry.getDN(); DefaultLdapUserContext ldapUserContext = internalCreateUser(dn); ldapUserContext.getKnownAttributes().put("cn", searchResultEntry.getAttributeValue("cn")); return ldapUserContext; } catch (com.unboundid.ldap.sdk.LDAPException e) { throw new LdapException(e); } }
From source file:org.seedstack.seed.security.ldap.internal.DefaultLDAPSupport.java
@Override public LDAPUserContext findUser(String identityAttributeValue) throws LDAPException { try {//from w w w . j a v a 2 s. c o m Filter userClassFilter; if (userObjectClass != null && !userObjectClass.isEmpty()) { userClassFilter = Filter.createEqualityFilter("objectClass", userObjectClass); } else { userClassFilter = Filter.createPresenceFilter("objectClass"); } Filter filter = Filter.createANDFilter(userClassFilter, Filter.createEqualityFilter(userIdentityAttribute, identityAttributeValue)); LOGGER.debug(filter.toString()); String[] attributesToRetrieve; if (userAdditionalAttributes != null) { attributesToRetrieve = userAdditionalAttributes; if (!ArrayUtils.contains(attributesToRetrieve, "cn") || !ArrayUtils.contains(attributesToRetrieve, "CN")) ArrayUtils.add(attributesToRetrieve, "cn"); } else attributesToRetrieve = new String[] { "cn" }; SearchResult searchResult = ldapConnectionPool.search(StringUtils.join(userBase, ','), SearchScope.SUB, filter, attributesToRetrieve); if (searchResult.getEntryCount() != 1) { throw new UnknownAccountException(); } SearchResultEntry searchResultEntry = searchResult.getSearchEntries().get(0); String dn = searchResultEntry.getDN(); DefaultLDAPUserContext ldapUserContext = internalCreateUser(dn); ldapUserContext.getKnownAttributes().put("cn", searchResultEntry.getAttributeValue("cn")); return ldapUserContext; } catch (com.unboundid.ldap.sdk.LDAPException e) { throw new LDAPException(e); } }
From source file:org.sinekartads.applet.AppletResponseDTO.java
public void addFieldError(String field, String error) { FieldErrorDTO fieldError = null;//from w w w .j av a2 s. c om for (FieldErrorDTO fe : fieldErrors) { if (StringUtils.equals(fe.field, field)) { fieldError = fe; } } if (fieldError == null) { fieldError = new FieldErrorDTO(); fieldError.setField(field); fieldErrors = (FieldErrorDTO[]) ArrayUtils.add(fieldErrors, fieldError); } fieldError.errors = (String[]) ArrayUtils.add(fieldError.errors, error); tracer.info(String.format("added fieldError: %s - %s", field, error)); tracer.info(JSONUtils.serializeJSON(fieldErrors, true)); }
From source file:org.sinekartads.applet.AppletResponseDTO.java
public void addActionError(String errorMessage, Throwable errorCause) { ActionErrorDTO actionError = new ActionErrorDTO(); actionError.errorMessage = errorMessage; // TODO serialize the errorCause to JSON and add it to the actionError actionErrors = (ActionErrorDTO[]) ArrayUtils.add(actionErrors, actionError); tracer.info(String.format("added actionError: %s - %s", errorMessage, errorCause)); tracer.info(JSONUtils.serializeJSON(actionErrors, true)); }
From source file:org.sipfoundry.sipxconfig.conference.FreeswitchApiMarshaller.java
public Object[] parameters(String name, Object... args) { // for now: CamelCase to lowercase Object[] operation = new Object[] { name.toLowerCase() }; if (args.length == 0) { return ArrayUtils.add(operation, ""); }/* w w w . j a v a2s .c o m*/ return ArrayUtils.addAll(operation, args); }
From source file:org.sipfoundry.sipxconfig.dialplan.AttendantRule.java
@Override public void appendToGenerationRules(List<DialingRule> rules) { if (!isEnabled() || !m_featureManager.isFeatureEnabled(FreeswitchFeature.FEATURE)) { return;/*from ww w. ja va2s . c om*/ } String[] aliases = AttendantRule.getAttendantAliasesAsArray(m_attendantAliases); if (!StringUtils.isEmpty(m_did)) { aliases = (String[]) ArrayUtils.add(aliases, m_did); } m_mediaServer.setLocation(getLocation()); DialingRule attendantRule = new MappingRule.Operator(getName(), getDescription(), getSystemName(), m_extension, aliases, m_mediaServer); rules.add(attendantRule); }
From source file:org.sipfoundry.sipxconfig.phone.counterpath.CounterpathPhone.java
@Override public Profile[] getProfileTypes() { Profile[] profileTypes = new Profile[] { new PhoneProfile(getPhoneFilename()) }; if (getPhonebookManager().getPhonebookManagementEnabled()) { profileTypes = (Profile[]) ArrayUtils.add(profileTypes, new DirectoryProfile(getDirectoryFilename())); }//w w w . j ava2 s . com return profileTypes; }