List of usage examples for org.apache.commons.lang ArrayUtils clone
public static boolean[] clone(boolean[] array)
Clones an array returning a typecast result and handling null
.
From source file:org.talend.mdm.webapp.browserecords.server.bizhelpers.DataModelHelper.java
private static String[] getBusinessConceptKeys(String model, String concept) { String[] keys = null;// ww w . j av a 2 s .c o m try { WSConceptKey key = CommonUtil.getPort() .getBusinessConceptKey(new WSGetBusinessConceptKey(new WSDataModelPK(model), concept)); WSConceptKey copyKey = new WSConceptKey(); copyKey.setFields((String[]) ArrayUtils.clone(key.getFields())); copyKey.setSelector(new String(key.getSelector())); keys = copyKey.getFields(); for (int i = 0; i < keys.length; i++) { if (".".equals(key.getSelector())) { //$NON-NLS-1$ keys[i] = concept + "/" + keys[i]; //$NON-NLS-1$ } else { keys[i] = key.getSelector() + keys[i]; } } } catch (Exception e) { logger.error(e.getMessage(), e); } return keys; }
From source file:org.talend.metadata.managment.ui.wizard.context.ContextAdaptConectionSelectPage.java
/** * ldong Comment method "createColumnsAndCellEditors". *///from w w w . ja v a 2 s.c o m private void createColumnsAndCellEditors(final Table table) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(ContextConstant.VARIABLE_COLUMN_NAME); column.setWidth(200); column = new TableColumn(table, SWT.NONE); column.setText(ContextConstant.CONNECTION_FIELD_NAME); column.setWidth(200); List<String> connnectionFields = new ArrayList<String>(); for (String cp : connectionVaribles) { connnectionFields.add(cp); } String[] values = (String[]) ArrayUtils.clone(connectionVaribles.toArray(new String[0])); CellEditor[] cellEditor = new CellEditor[3]; cellEditor[0] = new TextCellEditor(table, SWT.READ_ONLY); cellEditor[1] = new ComboBoxCellEditor(table, values, SWT.NONE); cellEditor[2] = new TextCellEditor(table, SWT.NONE); ((CCombo) cellEditor[1].getControl()).setEditable(false); // set column properties viewer.setColumnProperties( new String[] { ContextConstant.VARIABLE_COLUMN_NAME, ContextConstant.CONNECTION_FIELD_NAME }); // Set cell editors viewer.setCellEditors(cellEditor); // set the Cell Modifier viewer.setCellModifier(new ContextVariableSelectCellModifier(viewer, values)); }
From source file:org.wso2.carbon.identity.oauth2.token.AccessTokenIssuerTest.java
/** * Exception thrown when issuing access token by the Grant Handler * * @throws Exception/* ww w. j av a 2 s .c o m*/ */ @Test(dataProvider = "scopeDataProvider") public void testIssueWithScopes(String[] scopes, String expectedScopeString) throws Exception { when(OAuth2Util.buildScopeString(Matchers.<String[]>anyObject())).thenCallRealMethod(); AuthorizationGrantHandler dummyGrantHandler = getMockGrantHandlerForSuccess(false); OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO(); reqDTO.setGrantType(DUMMY_GRANT_TYPE); OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext(); oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID); reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext); reqDTO.setScope((String[]) ArrayUtils.clone(scopes)); final ResponseHeader responseHeader = new ResponseHeader(); responseHeader.setKey("Header"); responseHeader.setValue("HeaderValue"); final ResponseHeader[] responseHeaders = new ResponseHeader[] { responseHeader }; // Mock Issue when(dummyGrantHandler.issue(any(OAuthTokenReqMessageContext.class))).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { OAuthTokenReqMessageContext context = invocationOnMock.getArgumentAt(0, OAuthTokenReqMessageContext.class); // set some response headers context.addProperty(OAuthConstants.RESPONSE_HEADERS_PROPERTY, responseHeaders); String[] scopeArray = context.getOauth2AccessTokenReqDTO().getScope(); context.setScope(scopeArray); return new OAuth2AccessTokenRespDTO(); } }); HashMap<String, AuthorizationGrantHandler> authorizationGrantHandlers = new HashMap<>(); authorizationGrantHandlers.put(DUMMY_GRANT_TYPE, dummyGrantHandler); mockOAuth2ServerConfiguration(authorizationGrantHandlers); OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO); assertNotNull(tokenRespDTO); assertFalse(tokenRespDTO.isError()); assertEquals(tokenRespDTO.getAuthorizedScopes(), expectedScopeString); // Assert response headers set by the grant handler assertNotNull(tokenRespDTO.getResponseHeaders()); assertTrue(Arrays.deepEquals(tokenRespDTO.getResponseHeaders(), responseHeaders)); }
From source file:org.wso2.carbon.identity.oauth2.token.AccessTokenIssuerTest.java
@Test(dataProvider = "grantTypeDataProvider") public void testIssueWithOpenIdScope(String grantType) throws Exception { OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO(); reqDTO.setGrantType(grantType);//from w ww . ja va 2s .c o m reqDTO.setScope((String[]) ArrayUtils.clone(SCOPES_WITH_OPENID)); OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext(); oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID); reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext); setupOIDCScopeTest(grantType, true); OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO); assertNotNull(tokenRespDTO); assertFalse(tokenRespDTO.isError()); assertTrue(Arrays.deepEquals(tokenRespDTO.getAuthorizedScopes().split(" "), SCOPES_WITH_OPENID)); assertNotNull(tokenRespDTO.getIDToken()); assertEquals(tokenRespDTO.getIDToken(), ID_TOKEN); }
From source file:strat.mining.stratum.proxy.worker.GetworkJobTemplate.java
/** * Build the getwork data based on the given littleEndianMerkleRootHash. * // www.jav a 2s .c o m * @param littleEndianMerkleRootHash * @return */ private byte[] buildData(byte[] littleEndianMerkleRootHash) { // Clone the templateData byte[] data = ArrayUtils.clone(templateData); // Then copy the merkleRoot into the data. strat.mining.stratum.proxy.utils.ArrayUtils.copyInto(littleEndianMerkleRootHash, data, MERKLE_ROOT_BLOCK_HEADER_POSITION); return data; }
From source file:tor.TorCircuit.java
public void rendezvousSetup(byte[] cookie) throws IOException { rendezvousCookie = ArrayUtils.clone(cookie); send(rendezvousCookie, RELAY_COMMAND_ESTABLISH_RENDEZVOUS, false, (short) 0); setState(STATES.RENDEZVOUS_WAIT);/*from w w w.j a va 2s . c om*/ if (blocking) waitForState(STATES.RENDEZVOUS_ESTABLISHED, false); }
From source file:ubic.gemma.visualization.ExperimentalDesignVisualizationServiceImpl.java
@Override public Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> sortVectorDataByDesign( Collection<DoubleVectorValueObject> dedvs) { // cachedThawedBioAssayDimensions.clear(); // TEMPORARY FOR DEBUGGING. // cachedLayouts.clear(); // TEMPORARY FOR DEBUGGING. if (dedvs == null) return new HashMap<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>>( 0);//w w w. jav a 2 s . c om Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> returnedLayouts = new HashMap<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>>( dedvs.size()); StopWatch timer = new StopWatch(); timer.start(); /* * This is shared across experiments that might show up in the dedvs; this should be okay...saves computation. * This is the only slow part. */ prepare(dedvs); if (timer.getTime() > 1000) { log.info("Prepare for sorting with thaws: " + timer.getTime() + "ms"); // this is almos tall the time } /* * This loop is not a performance issue. */ for (DoubleVectorValueObject vec : dedvs) { LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = cachedLayouts .get(vec.getExpressionExperiment().getId()); returnedLayouts.put(vec.getExpressionExperiment().getId(), layout); BioAssayDimensionValueObject bad = vec.getBioAssayDimension(); /* * FIXME this might be a 'gapped' dimension that has a null id. */ if (bad == null || vec.isReorganized()) { /* * We've already done this vector, probably - from the cache. If the experimental design changed in the * meantime ... bad */ continue; } Map<BioAssayValueObject, Integer> ordering = getOrdering(layout); /* * Might be a faster way. */ double[] data = vec.getData(); double[] dol = ArrayUtils.clone(data); if (bad.getId() != null && !cachedThawedBioAssayDimensions.containsKey(bad.getId())) { // log.warn( "Missing bioassaydimension: " + bad.getId() ); // WHY? continue; } if (bad.getId() == null) { // / if the bad was replaced with a pseudo one. // log.warn( "bioassaydimension has no id" ); continue; } Collection<BioAssayValueObject> oldOrdering = cachedThawedBioAssayDimensions.get(bad.getId()) .getBioAssays(); assert oldOrdering instanceof List<?>; int j = 0; for (BioAssayValueObject ba : oldOrdering) { if (!ordering.containsKey(ba)) { log.warn("Order for vector didn't contain " + ba); continue; } int targetIndex = ordering.get(ba); data[targetIndex] = dol[j++]; } /* * Invalidate the bioassaydimension, it's in the wrong order compared to the bioasays. */ vec.setReorganized(true); } if (timer.getTime() > 1500) { log.info("Sort vectors by design: " + timer.getTime() + "ms"); } return returnedLayouts; }
From source file:v7cr.v7db.BSONBackedObject.java
/** * returns the field value, which can be any type of object. Use this only, * if you do not know the type in advance, otherwise the typed methods (such * as getStringField) are preferred./*from w w w. jav a2 s.c o m*/ * * <p> * If the field has multiple values, an array is returned. * * <p> * Always returns immutable objects or copies of the original data, so any * changes made to it later do not affect this object. * */ public Object getField(String field) { Object o = drillDown(field); if (o == null) return null; if (o instanceof String || o instanceof Boolean || o instanceof Long || o instanceof ObjectId || o instanceof Integer) return o; // Date is mutable... if (o instanceof Date) return ((Date) o).clone(); if (o instanceof BasicBSONObject) { return new BSONBackedObject((BasicBSONObject) o, null); } if (o instanceof List<?>) { o = ((List<?>) o).toArray(); } if (o instanceof Object[]) { Object[] a = (Object[]) o; int i = 0; for (Object m : a) { if (m instanceof Date) { a[i] = ((Date) m).clone(); } else if (m instanceof BasicBSONObject) { a[i] = new BSONBackedObject((BasicBSONObject) m, null); } else if (m instanceof String || m instanceof Boolean || m instanceof Long || m instanceof ObjectId || m instanceof Integer) { // immutable, no need to do anything } else throw new RuntimeException( "unsupported field type " + o.getClass().getName() + " for '" + field + "' : " + o); i++; } return a; } if (o instanceof byte[]) { byte[] b = (byte[]) o; return ArrayUtils.clone(b); } throw new RuntimeException( "unsupported field type " + o.getClass().getName() + " for '" + field + "' : " + o); }
From source file:wzw.lang.ArraySupport.java
public static Object[] clone(Object[] array) { return ArrayUtils.clone(array); }