List of usage examples for org.apache.commons.lang ArrayUtils subarray
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
From source file:com.intel.daal.spark.rdd.DistributedNumericTable.java
/** * Transforms a well-formed JavaDoubleRDD into a DistributedNumericTable that is backed * by HomogenNumericTables, with specified number of columns. * @param rdd - The source JavaDoubleRDD. * @param ncols - Number of columns in the result DistributedNumericTable. * @return A DistributedNumericTable./*from w w w .j a v a2 s . c o m*/ * @throws IllegalArgumentException. */ public static DistributedNumericTable fromJavaDoubleRDD(final JavaDoubleRDD rdd, final int ncols) throws IllegalArgumentException { long count = rdd.count(); if (count / ncols * ncols != count) { throw new IllegalArgumentException("Invalid NumericTable dimensions"); } JavaRDD<List<Double>> arrays = rdd.glom(); JavaRDD<Vector> vecrdd = arrays.flatMap(new FlatMapFunction<List<Double>, Vector>() { public List<Vector> call(List<Double> dlist) { int blocksize = dlist.size(); Double[] array = dlist.toArray(new Double[blocksize]); final double[] unboxed = ArrayUtils.toPrimitive(array); ArrayList<Vector> veclist = new ArrayList<Vector>(); long begin = 0; long end = ncols; while (begin < unboxed.length) { double[] row = ArrayUtils.subarray(unboxed, (int) begin, (int) end); DenseVector dv = new DenseVector(row); veclist.add(dv); begin = end; end += ncols; } return veclist; } }); return fromJavaVectorRDD(vecrdd, 0); }
From source file:com.mnxfst.testing.plan.ctx.TSPlanExecutionContext.java
/** * Extracts the {@link Method method representations} for the given path of getter methods * @param varType//from w w w. j a v a 2 s.c o m * @param getterMethodNames * @param result * @throws TSVariableEvaluationFailedException */ protected void extractGetterMethods(Class<?> varType, String[] getterMethodNames, List<Method> result) throws TSVariableEvaluationFailedException { if (varType != null && getterMethodNames != null && getterMethodNames.length > 0) { String nextGetter = getterMethodNames[0]; try { Method getterMethod = varType.getMethod(nextGetter, null); result.add(getterMethod); extractGetterMethods(getterMethod.getReturnType(), (String[]) ArrayUtils.subarray(getterMethodNames, 1, getterMethodNames.length), result); } catch (NoSuchMethodException e) { throw new TSVariableEvaluationFailedException( "No such getter '" + nextGetter + "' for class " + varType.getName()); } } }
From source file:gda.device.detector.countertimer.TfgScaler.java
private ScalerFrame[] reduceFrames(ScalerFrame[] frames) { int firstChannel = 0; if (firstDataChannel != null) { firstChannel = firstDataChannel; }//from ww w .ja v a2 s.c o m ScalerFrame[] reducedFrames = new ScalerFrame[frames.length]; for (int i = 0; i < frames.length; i++) { reducedFrames[i] = new ScalerFrame(); reducedFrames[i].time = frames[i].time; if (numChannelsToRead == null) { reducedFrames[i].data = ArrayUtils.subarray(frames[i].data, firstChannel, frames[i].data.length); } else { reducedFrames[i].data = ArrayUtils.subarray(frames[i].data, firstChannel, firstChannel + numChannelsToRead); } } return reducedFrames; }
From source file:gda.device.detector.countertimer.TfgScaler.java
private ScalerFrame[] convertToFrames(double[][] output) { ScalerFrame[] frames = new ScalerFrame[output.length]; for (int i = 0; i < output.length; i++) { frames[i] = new ScalerFrame(); if (isTFGv2) { // TFG2 always returns first channel as #clock counts (TFG has a 100MHz clock cycle) frames[i].time = output[i][0] / 100000000; } else {// www . j av a 2 s .co m if (frameSets == null || frameSets.size() == 0) { frames[i].time = collectionTime; } else { frames[i].time = frameSets.get(i).requestedLiveTime / 1000.0; } } if (isTFGv2) { frames[i].data = ArrayUtils.subarray(output[i], 1, output[i].length); } else { frames[i].data = output[i]; } } return frames; }
From source file:edu.utdallas.bigsecret.crypter.CrypterMode1.java
/** * {@inheritDoc}/* w w w . j a v a2 s. com*/ */ public long unwrapTimestamp(byte[] row, byte[] family, byte[] qualifier, long ts, byte[] value) throws Exception { if (qualifier == null || qualifier.length == 0) throw new Exception("Qualifier data null or no data"); int qualifierIndexSize = getIndexQualifierDataSize(); byte[] completeData = m_keyCipher.decrypt(qualifier, qualifierIndexSize); int rowSize = Bytes.toInt(completeData, 0, 4); int famSize = Bytes.toInt(completeData, 4, 4); int quaSize = Bytes.toInt(completeData, 8, 4); return Bytes.toLong(ArrayUtils.subarray(completeData, 12 + rowSize + famSize + quaSize, 12 + rowSize + famSize + quaSize + 8)); }
From source file:com.haulmont.cuba.gui.ComponentsHelper.java
/** * Searches for an action by name./*from w ww . ja v a2s . co m*/ * @param actionName action name, can be a path to an action contained in some {@link Component.ActionsHolder} * @param frame current frame * @return action instance or null if there is no action with the specified name * @throws IllegalStateException if the component denoted by the path doesn't exist or is not an ActionsHolder */ @Nullable public static Action findAction(String actionName, Frame frame) { String[] elements = ValuePathHelper.parse(actionName); if (elements.length > 1) { String id = elements[elements.length - 1]; String[] subPath = (String[]) ArrayUtils.subarray(elements, 0, elements.length - 1); Component component = frame.getComponent(ValuePathHelper.format(subPath)); if (component != null) { if (component instanceof Component.ActionsHolder) { return ((Component.ActionsHolder) component).getAction(id); } else { throw new IllegalArgumentException( String.format("Component '%s' can't contain actions", Arrays.toString(subPath))); } } else { throw new IllegalArgumentException( String.format("Can't find component '%s'", Arrays.toString(subPath))); } } else if (elements.length == 1) { String id = elements[0]; return frame.getAction(id); } else { throw new IllegalArgumentException("Invalid action name: " + actionName); } }
From source file:hudson.util.spring.BeanBuilder.java
/** * This method is called when a bean definition node is called * * @param name The name of the bean to define * @param args The arguments to the bean. The first argument is the class name, the last argument is sometimes a closure. All * the arguments in between are constructor arguments * @return The bean configuration instance *///from w w w . j a va2 s . co m private BeanConfiguration invokeBeanDefiningMethod(String name, Object[] args) { BeanConfiguration old = currentBeanConfig; try { if (args[0] instanceof Class) { Class beanClass = args[0] instanceof Class ? (Class) args[0] : args[0].getClass(); if (args.length >= 1) { if (args[args.length - 1] instanceof Closure) { if (args.length - 1 != 1) { Object[] constructorArgs = ArrayUtils.subarray(args, 1, args.length - 1); filterGStringReferences(constructorArgs); if (name.equals(ANONYMOUS_BEAN)) currentBeanConfig = springConfig.createSingletonBean(beanClass, Arrays.asList(constructorArgs)); else currentBeanConfig = springConfig.addSingletonBean(name, beanClass, Arrays.asList(constructorArgs)); } else { if (name.equals(ANONYMOUS_BEAN)) currentBeanConfig = springConfig.createSingletonBean(beanClass); else currentBeanConfig = springConfig.addSingletonBean(name, beanClass); } } else { Object[] constructorArgs = ArrayUtils.subarray(args, 1, args.length); filterGStringReferences(constructorArgs); if (name.equals(ANONYMOUS_BEAN)) currentBeanConfig = springConfig.createSingletonBean(beanClass, Arrays.asList(constructorArgs)); else currentBeanConfig = springConfig.addSingletonBean(name, beanClass, Arrays.asList(constructorArgs)); } } } else if (args[0] instanceof RuntimeBeanReference) { currentBeanConfig = springConfig.addSingletonBean(name); currentBeanConfig.setFactoryBean(((RuntimeBeanReference) args[0]).getBeanName()); } else if (args[0] instanceof Map) { currentBeanConfig = springConfig.addSingletonBean(name); Map.Entry factoryBeanEntry = (Map.Entry) ((Map) args[0]).entrySet().iterator().next(); currentBeanConfig.setFactoryBean(factoryBeanEntry.getKey().toString()); currentBeanConfig.setFactoryMethod(factoryBeanEntry.getValue().toString()); } else if (args[0] instanceof Closure) { currentBeanConfig = springConfig.addAbstractBean(name); } else { Object[] constructorArgs; if (args[args.length - 1] instanceof Closure) { constructorArgs = ArrayUtils.subarray(args, 0, args.length - 1); } else { constructorArgs = ArrayUtils.subarray(args, 0, args.length); } filterGStringReferences(constructorArgs); currentBeanConfig = new DefaultBeanConfiguration(name, null, Arrays.asList(constructorArgs)); springConfig.addBeanConfiguration(name, currentBeanConfig); } if (args[args.length - 1] instanceof Closure) { Closure callable = (Closure) args[args.length - 1]; callable.setDelegate(this); callable.setResolveStrategy(Closure.DELEGATE_FIRST); callable.call(new Object[] { currentBeanConfig }); } return currentBeanConfig; } finally { currentBeanConfig = old; } }
From source file:com.ec.android.module.bluetooth40.base.BaseBluetoothControlWithProtocolActivity.java
/** * ?/*from w w w . ja v a 2 s.c o m*/ * TODO ? * * @param data */ private void onReceiveData(byte[] data) { if (data.length < 7) { //?7header?? return; } // byte magic = data[0]; if (magic != Packet.MAGIC_BYTE) { //? return; } // byte dataMuti = data[1]; byte errFlag = (byte) (dataMuti & 0x08); // int payloadLength = data[2]; if (payloadLength < 0) { payloadLength = 256 + payloadLength; } //// byte sequenceIdHigh8 = data[3]; byte sequenceIdLow8 = data[4]; // int sequenceIdHigh8Int = sequenceIdHigh8; int sequenceIdLow8Int = sequenceIdLow8; // if (sequenceIdHigh8 < 0) { sequenceIdHigh8Int = (256 + sequenceIdHigh8); } if (sequenceIdLow8 < 0) { sequenceIdLow8Int = (256 + sequenceIdLow8); } // // short sequenceIdTemp = 0; //sequenceIdpacket short sequenceId = (short) ((sequenceIdHigh8Int << 8) + sequenceIdLow8Int); // if (errFlag == 0x08) { //??1 mProtocolDataUtils.putErrFlag(sequenceId, true); return; } else { //???0 mProtocolDataUtils.putErrFlag(sequenceId, false); } // byte ackFlag = (byte) (dataMuti & 0x04); if (ackFlag == 0x04) { //??1 //packet? } else { //??? //?? // byte beginFlag = (byte) (dataMuti & 0x02); byte endFlag = (byte) (dataMuti & 0x01); //?packet // int myCrc = magic ^ data[1] ^ payloadLength ^ sequenceId; int crcHigh = data[5]; int crcLow = data[6]; if (crcHigh < 0) { crcHigh = 256 + crcHigh; } if (crcLow < 0) { crcLow = 256 + crcLow; } // int crcTemp = 0x00; // int crc = (crcHigh << 8) + crcLow; if (crc != myCrc) { //? mProtocolDataUtils.removeGetDataMap(sequenceId); return; } //? byte[] bodyBytes = ArrayUtils.subarray(data, 7, data.length); // if (beginFlag == 0x02) { //??1?packet //packet??sequenceId?????? mProtocolDataUtils.removeGetDataMap(sequenceId); mProtocolDataUtils.plusGetDataMap(sequenceId, ArrayUtils.toObject(bodyBytes)); } else { //??0??packet //???sequenceId??? ArrayList<Byte[]> getDataMapList = mProtocolDataUtils.getGetDataMap(sequenceId); if (getDataMapList == null || getDataMapList.isEmpty()) { return; } else { //?? mProtocolDataUtils.plusGetDataMap(sequenceId, ArrayUtils.toObject(bodyBytes)); } } // if (endFlag == 0x01) { //??1??packet //?? ArrayList<Byte[]> getDataMapList = mProtocolDataUtils.getGetDataMap(sequenceId); if (getDataMapList != null) { Byte[] myAllBytes = null; for (Byte[] bytes : getDataMapList) { myAllBytes = (Byte[]) ArrayUtils.addAll(myAllBytes, bytes); } //? mProtocolDataUtils.removeGetDataMap(sequenceId); // onActionDataAvailable(myAllBytes); } } } // }
From source file:de.codesourcery.jasm16.parser.InstructionNodeTest.java
public void testParseNestedImmediateExpression() throws Exception { final String source = "SET I, 4+5*3"; final ICompilationUnit unit = CompilationUnit.createInstance("string input", source); final IParseContext context = createParseContext(source); final ASTNode result = new InstructionNode().parse(context); assertFalse(getErrors(source, result), result.hasErrors()); assertEquals(InstructionNode.class, result.getClass()); final InstructionNode instruction = (InstructionNode) result; final AtomicReference<byte[]> objcode = new AtomicReference<byte[]>(); final IObjectCodeWriter writer = new IObjectCodeWriter() { @Override/*from w w w . j a v a 2 s. com*/ public void close() throws IOException { } @Override public void writeObjectCode(byte[] data, int offset, int length) throws IOException { objcode.set(ArrayUtils.subarray(data, offset, offset + length)); } @Override public void writeObjectCode(byte[] data) throws IOException { writeObjectCode(data, 0, data.length); } @Override public void deleteOutput() throws IOException { // TODO Auto-generated method stub } @Override public Address getCurrentWriteOffset() { return Address.ZERO; } @Override public Address getFirstWriteOffset() { return Address.ZERO; } @Override public void advanceToWriteOffset(Address offset) throws IOException { throw new UnsupportedOperationException("Not implemented"); } }; final ICompilationContext compContext = createCompilationContext(unit); final OperandNode operand = instruction.getOperand(1); final TermNode oldExpression = (TermNode) operand.child(0); final TermNode newExpression = oldExpression.reduce(compContext); if (newExpression != oldExpression) { operand.setChild(0, newExpression); } instruction.symbolsResolved(compContext); instruction.writeObjectCode(writer, compContext); assertNotNull(objcode.get()); assertEquals(source, toSourceCode(result, source)); }
From source file:gda.device.scannable.ScannableMotionBase.java
/** * WARNING: This method will not work with units. * <p>/*from w w w . j a v a2s . c om*/ * * @param tolerance * @throws DeviceException */ @Override public void setTolerances(Double[] tolerance) throws DeviceException { // bug in Castor: seem to get tolerance arrays which are too long! int inputNamesLength = getInputNames().length; if (tolerance.length > inputNamesLength) { this.tolerance = (Double[]) ArrayUtils.subarray(tolerance, tolerance.length - inputNamesLength, tolerance.length); } else if (tolerance.length < inputNamesLength) { throw new DeviceException("Length of input (" + tolerance.length + ") does not match number of inputFields (" + inputNamesLength + ")."); } else { this.tolerance = tolerance; } }