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:mitm.common.security.ca.handlers.comodo.Tier2PartnerDetails.java
/** * Requests a certificate. Returns true if a certificate was successfully requested. */// w w w . ja va2 s . com public boolean retrieveDetails() throws CustomClientCertException { reset(); if (StringUtils.isEmpty(loginName)) { throw new CustomClientCertException("loginName must be specified."); } if (StringUtils.isEmpty(loginPassword)) { throw new CustomClientCertException("loginPassword must be specified."); } PostMethod postMethod = new PostMethod(connectionSettings.getTier2PartnerDetailsURL()); NameValuePair[] data = { new NameValuePair("loginName", loginName), new NameValuePair("loginPassword", loginPassword) }; if (accountID != null) { data = (NameValuePair[]) ArrayUtils.add(data, new NameValuePair("accountID", accountID)); } postMethod.setRequestBody(data); HTTPMethodExecutor executor = new HTTPMethodExecutor(connectionSettings.getTotalTimeout(), connectionSettings.getProxyInjector()); executor.setConnectTimeout(connectionSettings.getConnectTimeout()); executor.setReadTimeout(connectionSettings.getReadTimeout()); try { executor.executeMethod(postMethod, responseHandler); } catch (IOException e) { throw new CustomClientCertException(e); } return !error; }
From source file:gda.jython.batoncontrol.BatonManager.java
@Override public ClientDetails[] getOtherClientInformation(String myJSFIdentifier) { renewLease(myJSFIdentifier);/*from w ww. j a va2 s . c o m*/ ClientDetails[] array = new ClientDetails[0]; // loop through facades and find matching index for (String uniqueID : facadeNames.keySet()) { boolean hasBaton = amIBatonHolder(uniqueID, false); ClientInfo info = getClientInfo(uniqueID); ClientDetails details = new ClientDetails(info, hasBaton); // add other clients whose lease has not run out // (so ignore Object Servers and Clients who have probably died and not de-registered) if (!uniqueID.equals(myJSFIdentifier) && !details.userID.equals("") && leaseHolders.containsKey(idFromIndex(details.index))) { array = (ClientDetails[]) ArrayUtils.add(array, details); } } return array; }
From source file:com.adobe.acs.commons.workflow.bulk.execution.model.Workspace.java
/** Internal logic proxies **/ public void addActivePayload(Payload payload) { if (!ArrayUtils.contains(activePayloads, payload.getDereferencedPath())) { activePayloads = (String[]) ArrayUtils.add(activePayloads, payload.getDereferencedPath()); properties.put(PN_ACTIVE_PAYLOADS, activePayloads); addActivePayloadGroup(payload.getPayloadGroup()); }/*from w ww . ja va 2s . c o m*/ }
From source file:gda.scan.ConcurrentScanChild.java
TreeMap<Integer, Scannable[]> generateDevicesToMoveByLevel(TreeMap<Integer, Scannable[]> scannableLevels, Vector<Detector> detectors) { TreeMap<Integer, Scannable[]> devicesToMoveByLevel = new TreeMap<Integer, Scannable[]>(); devicesToMoveByLevel.putAll(scannableLevels); for (Scannable detector : detectors) { Integer level = detector.getLevel(); if (devicesToMoveByLevel.containsKey(level)) { Scannable[] levelArray = devicesToMoveByLevel.get(level); levelArray = (Scannable[]) ArrayUtils.add(levelArray, detector); devicesToMoveByLevel.put(level, levelArray); } else {/* ww w. ja v a 2 s.co m*/ Scannable[] levelArray = new Scannable[] { detector }; devicesToMoveByLevel.put(level, levelArray); } } return devicesToMoveByLevel; }
From source file:gda.jython.accesscontrol.ProtectedMethodComponent.java
/** * Adds the given method to the list of protected methods. The parameter types are also stored as this object does * not work simply on method names. This is done by using two internal hashmaps linked with a common index number. * /*from www.ja va2 s .co m*/ * @param method */ private void addMethod(Method method) { // find the index number of this method name. If its not there then add the method name to the list if (!protectedMethodNames.contains(method.getName())) { protectedMethodNames.add(method.getName()); } Integer indexNumber = protectedMethodNames.indexOf(method.getName()); // using the index number, add the list of parameters types of this method to the array stored in the hashmap if (!protectedMethodParameters.containsKey(indexNumber)) { Class<?>[][] newEntry = new Class<?>[1][]; newEntry[0] = method.getParameterTypes(); protectedMethodParameters.put(indexNumber, newEntry); } else { Class<?>[][] oldEntry = protectedMethodParameters.get(indexNumber); boolean found = false; for (Class<?>[] parameterTypes : oldEntry) { if (parameterTypesArrayComparison(parameterTypes, method.getParameterTypes())) { found = true; } } if (!found) { oldEntry = (Class<?>[][]) ArrayUtils.add(oldEntry, method.getParameterTypes()); protectedMethodParameters.put(indexNumber, oldEntry); } } }
From source file:com.google.gdt.eclipse.designer.wizards.ui.JUnitWizardPage.java
private IPackageFragmentRoot handleTestSourceFolder(IJavaProject javaProject) throws Exception { String testSourceFolderName = com.google.gdt.eclipse.designer.Activator.getStore() .getString(Constants.P_GWT_TESTS_SOURCE_FOLDER); IFolder testSourceFolder = javaProject.getProject().getFolder(testSourceFolderName); IPackageFragmentRoot testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); // check create if (!testSourceFolder.exists() || testSourceFragmentRoot == null || !testSourceFragmentRoot.exists()) { // create folder if (!testSourceFolder.exists()) { testSourceFolder.create(true, false, null); }//from w w w . j a v a2 s . c o m IClasspathEntry[] classpath = javaProject.getRawClasspath(); // find last source entry int insertIndex = -1; for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { insertIndex = i + 1; } } // insert new source to entries IClasspathEntry testSourceEntry = JavaCore.newSourceEntry(testSourceFolder.getFullPath()); if (insertIndex == -1) { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, testSourceEntry); } else { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, insertIndex, testSourceEntry); } // modify classpath javaProject.setRawClasspath(classpath, javaProject.getOutputLocation(), null); testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); } // setPackageFragmentRoot(testSourceFragmentRoot, true); return testSourceFragmentRoot; }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
/** * base method for all findNearest* /*from w w w .j a v a2s . c o m*/ * * @param point * The point from which we want to find GIS Object * @param pointId * the id of the point that we don't want to be include, it * is used to not include the gisFeature from which we want * to find the nearest * @param distance * distance The radius in meters * @param firstResult * the firstResult index (for pagination), numbered from 1, * if < 1 : it will not be taken into account * @param maxResults * The Maximum number of results to retrieve (for * pagination), if <= 0 : it will not be taken into acount * @param requiredClass * the class of the object to be retireved * @param isMunicipality whether we should filter on city that are flag as 'municipality'. act as a filter, if false it doesn't filters( false doesn't mean that we return non municipality) * @return A List of GisFeatureDistance with the nearest elements or an * emptylist (never return null), ordered by distance.<u>note</u> * the specified gisFeature will not be included into results * @see GisFeatureDistance * @return a list of gisFeature (never return null but an empty list) */ @SuppressWarnings("unchecked") protected List<GisFeatureDistance> getNearestAndDistanceFrom(final Point point, final Long pointId, final double distance, final int firstResult, final int maxResults, final boolean includeDistanceField, final Class<? extends GisFeature> requiredClass, final boolean isMunicipality) { Assert.notNull(point); return (List<GisFeatureDistance>) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { Criteria criteria = session.createCriteria(requiredClass); if (maxResults > 0) { criteria = criteria.setMaxResults(maxResults); } if (firstResult >= 1) { criteria = criteria.setFirstResult(firstResult - 1); } criteria = criteria.add(new DistanceRestriction(point, distance)); List<String> fieldList = IntrospectionHelper.getFieldsAsList(requiredClass); ProjectionList projections = ProjectionBean.fieldList(fieldList, true); if (includeDistanceField) { projections.add(SpatialProjection.distance_sphere(point, GisFeature.LOCATION_COLUMN_NAME) .as("distance")); } criteria.setProjection(projections); if (pointId != 0) { // remove The From Point criteria = criteria.add(Restrictions.not(Restrictions.idEq(pointId))); } if (includeDistanceField) { criteria.addOrder(new ProjectionOrder("distance")); } if (isMunicipality && (requiredClass == City.class || requiredClass == GisFeature.class)) { criteria.add(Restrictions.eq(City.MUNICIPALITY_FIELD_NAME, isMunicipality)); } criteria.setCacheable(true); List<Object[]> queryResults = criteria.list(); String[] aliasList; if (includeDistanceField) { aliasList = (String[]) ArrayUtils.add(IntrospectionHelper.getFieldsAsArray(requiredClass), "distance"); } else { aliasList = IntrospectionHelper.getFieldsAsArray(requiredClass); } int idPropertyIndexInAliasList = 0; for (int i = 0; i < aliasList.length; i++) { if (aliasList[i] == "id") { idPropertyIndexInAliasList = i; break; } } boolean hasZipCodesProperty = ZipCodesAware.class.isAssignableFrom(requiredClass); Map<Long, Set<String>> idToZipCodesMap = null; if (hasZipCodesProperty && queryResults.size() > 0) { List<Long> ids = new ArrayList<Long>(); for (Object[] tuple : queryResults) { ids.add((Long) tuple[idPropertyIndexInAliasList]); } String zipCodeQuery = "SELECT code as code,gisfeature as id FROM " + ZipCode.class.getSimpleName().toLowerCase() + " zip where zip.gisfeature in (:ids)"; Query qry = session.createSQLQuery(zipCodeQuery).addScalar("code", Hibernate.STRING) .addScalar("id", Hibernate.LONG); qry.setCacheable(true); qry.setParameterList("ids", ids); List<Object[]> zipCodes = (List<Object[]>) qry.list(); if (zipCodes.size() > 0) { idToZipCodesMap = new HashMap<Long, Set<String>>(); for (Object[] zipCode : zipCodes) { Long idFromZipcode = (Long) zipCode[1]; Set<String> zipCodesFromMap = idToZipCodesMap.get(idFromZipcode); if (zipCodesFromMap == null) { Set<String> zipCodesToAdd = new HashSet<String>(); idToZipCodesMap.put(idFromZipcode, zipCodesToAdd); zipCodesFromMap = zipCodesToAdd; } zipCodesFromMap.add((String) zipCode[0]); } } } List<GisFeatureDistance> results = ResultTransformerUtil.transformToGisFeatureDistance(aliasList, queryResults, idToZipCodesMap, requiredClass); return results; } }); }
From source file:gda.device.scannable.component.UnitsComponent.java
/** * Should only be called once the hardware units have been set. * * @return Returns the acceptableUnitStrings. *///from w w w. j a va 2 s . co m public String[] getAcceptableUnits() { String[] output = new String[0]; for (Unit<? extends Quantity> unit : this.acceptableUnits) { output = (String[]) ArrayUtils.add(output, unit.toString()); } return output; }
From source file:gda.scan.ScanDataPoint.java
/** * Add a piece of data to this object. Calls to this method must be made in the same order as calls to addDetector * to associate the data with the detector. * <p>// w w w .java2 s . c o m * * @param data */ @Override public void addDetectorData(Object data, String[] format) { if (data != null) { this.detectorData.add(data); if (format == null || format.length == 0) { format = new String[] { "%s" }; } detectorFormats = (String[][]) ArrayUtils.add(detectorFormats, format); } }
From source file:com.bayesforecast.ingdat.vigsteps.vigmake.VigMakeStep.java
public void emitItem(VigMakeStepData data, Item item, boolean emitLastState) { Set<Date> processedDates = data.processedDates.keySet(); Object[] ids = item.getId().toArray(); Object[] attributes = item.getAttributes().toArray(); Object[] itemData = ArrayUtils.addAll(ids, attributes); Set<Entry<Date, State>> set = item.getStates().entrySet(); for (Entry<Date, State> status : set) { if (!status.getValue().isNullState() && !(item.getStates().lastKey().equals(status.getKey()) && !emitLastState)) { Object[] itemStateData = ArrayUtils.addAll(itemData, status.getValue().getStatus().toArray()); Object[] itemStateData2 = ArrayUtils.add(itemStateData, status.getKey()); Date dateEnd = null;//w ww . ja v a 2 s. c o m Object[] statusPrev = new Object[meta.getStatusFields().size()]; Object[] statusNext = new Object[meta.getStatusFields().size()]; if (status.getValue().getPrevious() != null && !status.getValue().getPrevious().isNullState()) { statusPrev = status.getValue().getPrevious().getStatus().toArray(); } if (status.getValue().getNext() != null) { if (!status.getValue().getNext().isNullState()) { statusNext = status.getValue().getNext().getStatus().toArray(); dateEnd = item.getStates().higherKey(status.getKey()); } else { dateEnd = DateUtils.addDays(item.getStates().higherKey(status.getKey()), -1); } } Object[] itemStateData3 = ArrayUtils.add(itemStateData2, dateEnd); Object[] itemStateData4 = ArrayUtils.addAll(itemStateData3, statusPrev); Object[] itemStateData5 = ArrayUtils.addAll(itemStateData4, statusNext); // put the row to the output row stream try { putRow(data.outputRowMeta, itemStateData5); } catch (KettleStepException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }