Example usage for org.apache.commons.lang ArrayUtils remove

List of usage examples for org.apache.commons.lang ArrayUtils remove

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils remove.

Prototype

private static Object remove(Object array, int index) 

Source Link

Document

Removes the element at the specified position from the specified array.

Usage

From source file:edu.mayo.cts2.framework.core.json.JsonConverter.java

/**
 * Builds the gson.//from  w  ww.  j a  v  a 2s .c o m
 *
 * @return the gson
 */
protected Gson buildGson() {
    GsonBuilder gson = new GsonBuilder();

    gson.setDateFormat(ISO_DATE_FORMAT);

    gson.setExclusionStrategies(new ExclusionStrategy() {

        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getName().equals(CHOICE_VALUE);
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }

    });

    gson.registerTypeAdapter(List.class, new EmptyCollectionSerializer());
    gson.registerTypeAdapter(TsAnyType.class, new TsAnyTypeSerializer());
    gson.registerTypeAdapter(Date.class, new DateTypeAdapter());
    gson.registerTypeAdapterFactory(new ChangeableTypeAdapterFactory());
    gson.registerTypeAdapterFactory(new ChangeableResourceTypeAdapterFactory());

    gson.setFieldNamingStrategy(new FieldNamingStrategy() {

        @Override
        public String translateName(Field field) {
            String fieldName = field.getName();

            char[] array = fieldName.toCharArray();

            if (array[0] == '_') {
                array = ArrayUtils.remove(array, 0);
            }

            String name = new String(array);
            if (name.endsWith(LIST_SUFFIX)) {
                name = StringUtils.removeEnd(name, LIST_SUFFIX);
            }

            return name;
        }

    });

    return gson.create();
}

From source file:gda.device.detector.countertimer.TFGTriggeredScaler.java

public void setReturnCountRates(Boolean returnCountRates) {

    if (!timeChannelRequired && returnCountRates) {
        timeChannelRequired = true;/*  w  ww .  j  a va 2 s  .c om*/
        this.extraNames = (String[]) ArrayUtils.addAll(new String[] { "time" }, this.extraNames);
        this.outputFormat = (String[]) ArrayUtils.addAll(new String[] { this.outputFormat[0] },
                this.outputFormat);
    } else if (timeChannelRequired && this.returnCountRates && !returnCountRates) {
        timeChannelRequired = false;
        this.extraNames = (String[]) ArrayUtils.remove(this.extraNames, 0);
        this.outputFormat = (String[]) ArrayUtils.remove(this.outputFormat, 0);
    }

    this.returnCountRates = returnCountRates;
}

From source file:gda.device.detector.countertimer.BufferedScaler.java

public void setReturnCountRates(Boolean returnCountRates) {
    if (!timeChannelRequired && returnCountRates) {
        timeChannelRequired = true;/*  w  w w .  ja v a2  s .c o  m*/
        extraNames = (String[]) ArrayUtils.addAll(new String[] { "time" }, this.extraNames);
        outputFormat = (String[]) ArrayUtils.addAll(new String[] { this.outputFormat[0] }, this.outputFormat);
    } else if (timeChannelRequired && this.returnCountRates && !returnCountRates) {
        timeChannelRequired = false;
        extraNames = (String[]) ArrayUtils.remove(this.extraNames, 0);
        outputFormat = (String[]) ArrayUtils.remove(this.outputFormat, 0);
    }
    this.returnCountRates = returnCountRates;
}

From source file:com.blockwithme.hacktors.Chunk.java

/** Removes an item, using local coordinates. */
public void removeItemLocal(final int x, final int y, final Item item) {
    if (item == null) {
        throw new IllegalArgumentException("item is null");
    }//from  w  ww  .ja v  a  2 s.  co  m
    final int index = index(x, y);
    final int where = ArrayUtils.indexOf(items[index], item);
    if (where < 0) {
        throw new IllegalArgumentException("item not found");
    }
    items[index] = (Item[]) ArrayUtils.remove(items[index], where);
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceEStoreImpl.java

protected Object remove(PersistentEObject object, EAttribute eAttribute, int index) {
    Object[] array = (Object[]) getFromMap(object, eAttribute);
    Object oldValue = array[index];
    array = ArrayUtils.remove(array, index);
    map.put(Fun.t2(object.id(), eAttribute.getName()), array);
    return parseMapValue(eAttribute, oldValue);
}

From source file:edu.isi.wings.portal.classes.Config.java

private void initializeUserConfig(HttpServletRequest request) {
    // Set userid, domainid, viewerId
    this.userId = request.getParameter("userid");
    this.domainId = request.getParameter("domainid");
    this.viewerId = request.getRemoteUser();

    // Set default script values
    this.scriptPath = this.contextRootPath + request.getServletPath();
    this.scriptArguments = new String[] {};

    String path = request.getPathInfo();
    if (path == null)
        path = "/";
    this.scriptArguments = path.split("/");
    if (this.scriptArguments.length > 0)
        this.scriptArguments = (String[]) ArrayUtils.remove(this.scriptArguments, 0);

    if (this.domainId != null) {
        this.userDomainUrl = this.contextRootPath + "/" + this.getUsersRelativeDir() + "/" + this.getUserId()
                + "/" + this.getDomainId();
        this.scriptPath = this.userDomainUrl + request.getServletPath();
    } else if (this.userId != null) {
        this.scriptPath = this.contextRootPath + "/" + this.getUsersRelativeDir() + "/" + this.getUserId()
                + request.getServletPath();
    }/*ww w.  j  a  v a2  s  . c  o  m*/

    this.sessionId = request.getSession().getId();

    if (this.viewerId == null)
        return;

    // If no userId specified, then set the viewer as the user
    if (this.userId == null)
        this.userId = this.viewerId;

    if (!this.checkUser(null))
        return;

    this.exportUserUrl = serverUrl + contextRootPath + exportServletPath + "/" + usersRelativeDir + "/"
            + userId;
    this.userPath = contextRootPath + "/" + usersRelativeDir + "/" + userId;
    this.userDir = storageDirectory + File.separator + usersRelativeDir + File.separator + userId;

    // Create userDir (if it doesn't exist)
    File uf = new File(this.userDir);
    if (!uf.exists() && !uf.mkdirs())
        System.err.println("Cannot create user directory : " + uf.getAbsolutePath());

    // Get domain and user list
    DomainController dc = new DomainController(1, this);
    this.domainsList = dc.getReadableDomainsList();
    this.usersList = this.userapi.getUsersList();

    // Get user's selected domain
    this.domain = dc.getUserDomain();

    // If the domain isn't a part of the readable domain list, 
    // then choose the first one
    if (this.domain == null || !domainsList.contains(this.domain.getDomainName())) {
        if (domainsList.size() > 0)
            this.domain = dc.getDomain(domainsList.get(0));
        else
            this.domain = null;
    }

    if (this.domain != null) {
        this.userDomainUrl = this.contextRootPath + "/" + this.getUsersRelativeDir() + "/" + this.getUserId()
                + "/" + this.domain.getDomainName();
        this.domainId = this.domain.getDomainName();
    }
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceEStoreImpl.java

protected Object remove(PersistentEObject object, EReference eReference, int index) {
    Object[] array = (Object[]) getFromMap(object, eReference);
    Object oldId = array[index];/*  w w  w. j av  a2s . c o m*/
    array = ArrayUtils.remove(array, index);
    map.put(Fun.t2(object.id(), eReference.getName()), array);
    return eObject((Id) oldId);

}

From source file:com.blockwithme.hacktors.Mobile.java

/** Picks up stuff on the floor, until all is picked up, or the inventory is full. */
public boolean pickup() {
    final World world = position.getWorld();
    if (world == null) {
        // Detached
        return false;
    }//  ww w  . j ava2 s  .c  o m
    final Chunk chunk = world.getOrCreateChunk(position);
    if (chunk == null) {
        // At worlds edge
        return false;
    }
    final int x = position.getX();
    final int y = position.getY();
    Item[] items = chunk.getItems(x, y);
    boolean result = false;
    for (int i = 0; i < items.length; i++) {
        final Item item = items[i];
        if (addItem(item)) {
            items = (Item[]) ArrayUtils.remove(items, i--);
            chunk.removeItem(x, y, item);
            result = true;
        }
    }
    final Block block = chunk.getBlock(x, y);
    final BlockType blockType = block.getType();
    if (blockType == BlockType.OpenChest) {
        items = block.getContent();
        for (int i = 0; i < items.length; i++) {
            final Item item = items[i];
            if (addItem(item)) {
                items = (Item[]) ArrayUtils.remove(items, i--);
                result = true;
            }
        }
        block.setContent(items);
    }
    return result;
}

From source file:eu.scidipes.toolkits.palibrary.impl.UploadRepInfoLabel.java

private void removeRepInfoHelper(final RepresentationInformation riToRemove, final CoreRIType type) {

    for (final RepresentationInformation repInfo : repInfoChildren) {

        if (type.getType().isAssignableFrom(repInfo.getClass())
                && repInfo.getRepresentationInformation() != null) {

            final RepInfoGroup repInfoGroup = (RepInfoGroup) repInfo.getRepresentationInformation();
            final RepresentationInformation[] currentGrandChildren = repInfoGroup
                    .getRepresentationInformationChildren();

            final int idx = ArrayUtils.indexOf(currentGrandChildren, riToRemove);

            LOG.debug("Index of riToRemove in currentGrandChildren is: " + idx);

            if (idx > -1) {
                repInfoGroup.setRepresentationInformationChildren(
                        (RepresentationInformation[]) ArrayUtils.remove(currentGrandChildren, idx));
                LOG.debug(format("riToRemove [%s] at index [%d] was removed from %s core RI", riToRemove,
                        Integer.valueOf(idx), type.toString()));
            } else {
                LOG.debug(format("riToRemove [%s] was not found in %s core RI", riToRemove, type.toString()));
            }/*from w  w  w. j a v  a  2  s  .  co  m*/
        }

    }

}

From source file:com.google.gdt.eclipse.designer.gxt.model.widgets.ComponentTest.java

/**
 * Some users try to use old version of GXT, but our descriptions are for GXT 2.0.1 (we are not
 * subscribers, so don't have access to higher versions). We should check version and fail with
 * good message./*ww  w.ja  va 2 s  .  com*/
 * <p>
 * http://fogbugz.instantiations.com/fogbugz/default.php?43669
 */
@DisposeProjectAfter
public void test_oldVersion() throws Exception {
    dontUseSharedGWTState();
    // replace GXT jar, use old version
    {
        IClasspathEntry[] entries = m_javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            String path = entry.getPath().toString();
            if (path.contains("gxt") && path.endsWith(".jar")) {
                entries = (IClasspathEntry[]) ArrayUtils.remove(entries, i);
                break;
            }
        }
        m_javaProject.setRawClasspath(entries, null);
        waitForAutoBuild();
        // add gxt.jar for version 1.2.4
        m_testProject.addExternalJar(ExtGwtTests.GXT_LOCATION_OLD + "/gxt.jar");
    }
    // try to parse, failure expected
    try {
        parseJavaInfo("public class Test implements EntryPoint {", "  public void onModuleLoad() {",
                "    RootPanel rootPanel = RootPanel.get();", "    {", "      Button button = new Button();",
                "      rootPanel.add(button);", "    }", "  }", "}");
        fail();
    } catch (Throwable e) {
        DesignerException de = DesignerExceptionUtils.getDesignerException(e);
        assertEquals(de.getCode(), IExceptionConstants.INCORRECT_VERSION);
        assertTrue(DesignerExceptionUtils.isWarning(e));
    }
}