List of usage examples for org.apache.commons.lang ArrayUtils remove
private static Object remove(Object array, int index)
Removes the element at the specified position from the specified array.
From source file:net.stuxcrystal.simpledev.commands.compat.bukkit.BukkitCommandHandler.java
/** * Simple command handler for subcommands. * * @param _sender The sender that sends the command. * @param command The internal command * @param label The alias used to execute this command. * @param arguments The arguments passed to the command. *//*from www . j av a2 s . c o m*/ @Override public boolean onCommand(CommandSender _sender, org.bukkit.command.Command command, String label, String[] arguments) { if (arguments.length == 0) { // Make a command out of it. arguments = new String[] { CommandHandler.FALLBACK_COMMAND_NAME }; } net.stuxcrystal.simpledev.commands.CommandExecutor<?> sender = ((BukkitPluginBackend) this.backend) .wrapSender(_sender); if (!this.execute(sender, arguments[0], (String[]) ArrayUtils.remove(arguments, 0))) sender.sendMessage(T(sender, "cmd.notfound")); return true; }
From source file:net.stuxcrystal.simpledev.commands.compat.canary.CanaryCommandHandler.java
/** * Executes the command as a subcommand. * * @param caller The caller.// w w w . j av a 2 s . com * @param args The given arguments. */ public void executeSubCommand(MessageReceiver caller, String[] args) { CommandExecutor executor = ((CanaryPluginBackend) getServerBackend()).wrapReceiver(caller); args = (String[]) ArrayUtils.remove(args, 0); String name; if (args.length == 0) { name = CommandHandler.FALLBACK_COMMAND_NAME; args = new String[0]; } else { name = args[0]; args = (String[]) ArrayUtils.remove(args, 0); } if (!this.execute(executor, name, args)) executor.sendMessage(T(executor, "cmd.notfound")); }
From source file:net.tooan.ynpay.third.mongodb.mapper.MapperUtil.java
/** * Get the name property of @Entity annotation. * If the name property is not set, then return the class' name, in lower case type. * * @param clazz//from w w w .jav a2s . c o m * @return */ public static String[] getEntityName(Class<?> clazz) { Entity entity = clazz.getAnnotation(Entity.class); String[] name = entity.name().split("\\."); if (name.length == 1) { name = (String[]) ArrayUtils.add(name, clazz.getSimpleName().toLowerCase()); } else { name[1] = StringUtils.join(ArrayUtils.remove(name, 0), "."); } return name; }
From source file:org.apache.carbondata.processing.loading.row.CarbonRowBatch.java
@Override public void remove() { rowBatch = (CarbonRow[]) ArrayUtils.remove(rowBatch, index - 1); --size; --index; }
From source file:org.apache.kylin.cube.model.CubeDesc.java
private void initDerivedMap(TblColRef[] hostCols, DeriveType type, JoinDesc join, TblColRef[] derivedCols, String[] extra) {//from www . j av a 2 s .com if (hostCols.length == 0 || derivedCols.length == 0) throw new IllegalStateException("host/derived columns must not be empty"); // Although FK derives PK automatically, user unaware of this can declare PK as derived dimension explicitly. // In that case, derivedCols[] will contain a FK which is transformed from the PK by initDimensionColRef(). // Must drop FK from derivedCols[] before continue. for (int i = 0; i < derivedCols.length; i++) { if (ArrayUtils.contains(hostCols, derivedCols[i])) { derivedCols = (TblColRef[]) ArrayUtils.remove(derivedCols, i); if (extra != null) extra = (String[]) ArrayUtils.remove(extra, i); i--; } } if (derivedCols.length == 0) return; for (int i = 0; i < derivedCols.length; i++) { TblColRef derivedCol = derivedCols[i]; boolean isOneToOne = type == DeriveType.PK_FK || ArrayUtils.contains(hostCols, derivedCol) || (extra != null && extra[i].contains("1-1")); derivedToHostMap.put(derivedCol, new DeriveInfo(type, join, hostCols, isOneToOne)); } Array<TblColRef> hostColArray = new Array<TblColRef>(hostCols); List<DeriveInfo> infoList = hostToDerivedMap.get(hostColArray); if (infoList == null) { infoList = new ArrayList<DeriveInfo>(); hostToDerivedMap.put(hostColArray, infoList); } // Merged duplicated derived column List<TblColRef> whatsLeft = new ArrayList<>(); for (TblColRef derCol : derivedCols) { boolean merged = false; for (DeriveInfo existing : infoList) { if (existing.type == type && existing.join.getPKSide().equals(join.getPKSide())) { if (ArrayUtils.contains(existing.columns, derCol)) { merged = true; break; } if (type == DeriveType.LOOKUP) { existing.columns = (TblColRef[]) ArrayUtils.add(existing.columns, derCol); merged = true; break; } } } if (!merged) whatsLeft.add(derCol); } if (whatsLeft.size() > 0) { infoList.add(new DeriveInfo(type, join, (TblColRef[]) whatsLeft.toArray(new TblColRef[whatsLeft.size()]), false)); } }
From source file:org.apache.kylin.cube.model.v1_4_0.CubeDesc.java
private void initDerivedMap(TblColRef[] hostCols, DeriveType type, DimensionDesc dimension, TblColRef[] derivedCols, String[] extra) { if (hostCols.length == 0 || derivedCols.length == 0) throw new IllegalStateException("host/derived columns must not be empty"); // Although FK derives PK automatically, user unaware of this can declare PK as derived dimension explicitly. // In that case, derivedCols[] will contain a FK which is transformed from the PK by initDimensionColRef(). // Must drop FK from derivedCols[] before continue. for (int i = 0; i < derivedCols.length; i++) { if (ArrayUtils.contains(hostCols, derivedCols[i])) { derivedCols = (TblColRef[]) ArrayUtils.remove(derivedCols, i); extra = (String[]) ArrayUtils.remove(extra, i); i--;//from w w w . j av a 2s . co m } } Array<TblColRef> hostColArray = new Array<TblColRef>(hostCols); List<DeriveInfo> infoList = hostToDerivedMap.get(hostColArray); if (infoList == null) { hostToDerivedMap.put(hostColArray, infoList = new ArrayList<DeriveInfo>()); } infoList.add(new DeriveInfo(type, dimension, derivedCols, false)); for (int i = 0; i < derivedCols.length; i++) { TblColRef derivedCol = derivedCols[i]; boolean isOneToOne = type == DeriveType.PK_FK || ArrayUtils.contains(hostCols, derivedCol) || (extra != null && extra[i].contains("1-1")); derivedToHostMap.put(derivedCol, new DeriveInfo(type, dimension, hostCols, isOneToOne)); } }
From source file:org.apache.ojb.broker.core.MtoNBroker.java
/** * Stores new values of a M:N association in a indirection table. * * @param cod The {@link org.apache.ojb.broker.metadata.CollectionDescriptor} for the m:n relation * @param realObject The real object/*from w w w . ja va2 s .c om*/ * @param otherObj The referenced object * @param mnKeys The all {@link org.apache.ojb.broker.core.MtoNBroker.Key} matching the real object */ public void storeMtoNImplementor(CollectionDescriptor cod, Object realObject, Object otherObj, Collection mnKeys) { ClassDescriptor cld = pb.getDescriptorRepository().getDescriptorFor(realObject.getClass()); ValueContainer[] pkValues = pb.serviceBrokerHelper().getKeyValues(cld, realObject); String[] pkColumns = cod.getFksToThisClass(); ClassDescriptor otherCld = pb.getDescriptorRepository() .getDescriptorFor(ProxyHelper.getRealClass(otherObj)); ValueContainer[] otherPkValues = pb.serviceBrokerHelper().getKeyValues(otherCld, otherObj); String[] otherPkColumns = cod.getFksToItemClass(); String table = cod.getIndirectionTable(); MtoNBroker.Key key = new MtoNBroker.Key(otherPkValues); if (mnKeys.contains(key)) { return; } /* fix for OJB-76, composite M & N keys that have some fields common find the "shared" indirection table columns, values and remove these from m- or n- side */ for (int i = 0; i < otherPkColumns.length; i++) { int index = ArrayUtils.indexOf(pkColumns, otherPkColumns[i]); if (index != -1) { // shared indirection table column found, remove this column from one side pkColumns = (String[]) ArrayUtils.remove(pkColumns, index); // remove duplicate value too pkValues = (ValueContainer[]) ArrayUtils.remove(pkValues, index); } } String[] cols = mergeColumns(pkColumns, otherPkColumns); String insertStmt = pb.serviceSqlGenerator().getInsertMNStatement(table, pkColumns, otherPkColumns); ValueContainer[] values = mergeContainer(pkValues, otherPkValues); GenericObject gObj = new GenericObject(table, cols, values); if (!tempObjects.contains(gObj)) { pb.serviceJdbcAccess().executeUpdateSQL(insertStmt, cld, pkValues, otherPkValues); tempObjects.add(gObj); } }
From source file:org.apache.pig.piggybank.storage.GAMultiStorage.java
private Text RemoveLastByte(byte[] input) { return new Text(ArrayUtils.remove(input, input.length - 1)); }
From source file:org.apache.sling.resource.collection.impl.ResourceCollectionImpl.java
/** * {@inheritDoc}//from ww w. j av a 2 s . co m */ public boolean remove(Resource res) throws PersistenceException { //remove the resource Resource tobeRemovedRes = findRes(res); if (tobeRemovedRes == null) { return false; } resolver.delete(tobeRemovedRes); //remove from order array ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class); String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[] {}); int index = ArrayUtils.indexOf(order, res.getPath(), 0); order = (String[]) ArrayUtils.remove(order, index); vm.put(ResourceCollectionConstants.REFERENCES_PROP, order); return true; }
From source file:org.apache.sling.resource.collection.impl.ResourceCollectionImpl.java
public void orderBefore(Resource srcResource, Resource destResource) { if (srcResource == null) { throw new IllegalArgumentException("Source Resource can not be null"); }/*w w w . jav a2 s. co m*/ ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class); String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[] {}); String srcPath = srcResource.getPath(); int srcIndex = ArrayUtils.indexOf(order, srcPath); if (srcIndex < 0) { log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource", srcPath, getPath()); return; } if (destResource == null) { //add it to the end. order = (String[]) ArrayUtils.remove(order, srcIndex); order = (String[]) ArrayUtils.add(order, srcPath); } else { String destPath = destResource.getPath(); if (destPath.equals(srcPath)) { String message = MessageFormat.format( "Collection ordering failed, as source {0} and destination {1} can not be same", srcPath, destPath); log.error(message); throw new IllegalArgumentException(message); } int destIndex = ArrayUtils.indexOf(order, destPath); if (destIndex < 0) { log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource", destPath, getPath()); return; } order = (String[]) ArrayUtils.remove(order, srcIndex); if (srcIndex < destIndex) { //recalculate dest index destIndex = ArrayUtils.indexOf(order, destPath); } order = (String[]) ArrayUtils.add(order, destIndex, srcPath); } vm.put(ResourceCollectionConstants.REFERENCES_PROP, order); }