List of usage examples for org.apache.commons.lang ArrayUtils removeElement
public static short[] removeElement(short[] array, short element)
Removes the first occurrence of the specified element from the specified array.
From source file:com.example.java.collections.ArrayExample.java
public static void main(String[] args) { /* ########################################################### */ // Initializing an Array String[] creatures = { "goldfish", "oscar", "guppy", "minnow" }; int[] numbers = new int[10]; int counter = 0; while (counter < numbers.length) { numbers[counter] = counter;//from w w w . jav a 2s. c o m System.out.println("number[" + counter + "]: " + counter); counter++; } for (int theInt : numbers) { System.out.println(theInt); } //System.out.println(numbers[numbers.length]); /* ########################################################### */ /* ########################################################### */ // Using Charecter Array String name = "Michael"; // Charecter Array char[] charName = name.toCharArray(); System.out.println(charName); // Array Fuctions char[] html = new char[] { 'M', 'i', 'c', 'h', 'a', 'e', 'l' }; char[] lastFour = new char[4]; System.arraycopy(html, 3, lastFour, 0, lastFour.length); System.out.println(lastFour); /* ########################################################### */ /* ########################################################### */ // Using Arrays of Other Types Object[] person = new Object[] { "Michael", new Integer(94), new Integer(1), new Date() }; String fname = (String) person[0]; //ok Integer age = (Integer) person[1]; //ok Date start = (Date) person[2]; //oops! /* ########################################################### */ /* ########################################################### */ // Muti Dimestional Array String[][] bits = { { "Michael", "Ernest", "MFE" }, { "Ernest", "Friedman-Hill", "EFH" }, { "Kathi", "Duggan", "KD" }, { "Jeff", "Kellum", "JK" } }; bits[0] = new String[] { "Rudy", "Polanski", "RP" }; bits[1] = new String[] { "Rudy", "Washington", "RW" }; bits[2] = new String[] { "Rudy", "O'Reilly", "RO" }; /* ########################################################### */ /* ########################################################### */ //Create ArrayList from array String[] stringArray = { "a", "b", "c", "d", "e" }; ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(stringArray)); System.out.println(arrayList); // [a, b, c, d, e] /* ########################################################### */ /* ########################################################### */ //Check if an array contains a certain value String[] stringArray1 = { "a", "b", "c", "d", "e" }; boolean b = Arrays.asList(stringArray).contains("a"); System.out.println(b); // true /* ########################################################### */ /* ########################################################### */ //Concatenate two arrays int[] intArray = { 1, 2, 3, 4, 5 }; int[] intArray2 = { 6, 7, 8, 9, 10 }; // Apache Commons Lang library int[] combinedIntArray = ArrayUtils.addAll(intArray, intArray2); /* ########################################################### */ /* ########################################################### */ //Joins the elements of the provided array into a single String // Apache common lang String j = StringUtils.join(new String[] { "a", "b", "c" }, ", "); System.out.println(j); // a, b, c /* ########################################################### */ /* ########################################################### */ //Covnert ArrayList to Array String[] stringArray3 = { "a", "b", "c", "d", "e" }; ArrayList<String> arrayList1 = new ArrayList<String>(Arrays.asList(stringArray)); String[] stringArr = new String[arrayList.size()]; arrayList.toArray(stringArr); for (String s : stringArr) { System.out.println(s); } /* ########################################################### */ /* ########################################################### */ //Convert Array to Set Set<String> set = new HashSet<String>(Arrays.asList(stringArray)); System.out.println(set); //[d, e, b, c, a] /* ########################################################### */ /* ########################################################### */ //Reverse an array int[] intArray1 = { 1, 2, 3, 4, 5 }; ArrayUtils.reverse(intArray1); System.out.println(Arrays.toString(intArray1)); //[5, 4, 3, 2, 1] /* ########################################################### */ /* ########################################################### */ // Remove element of an array int[] intArray3 = { 1, 2, 3, 4, 5 }; int[] removed = ArrayUtils.removeElement(intArray3, 3);//create a new array System.out.println(Arrays.toString(removed)); /* ########################################################### */ /* ########################################################### */ byte[] bytes = ByteBuffer.allocate(4).putInt(8).array(); for (byte t : bytes) { System.out.format("0x%x ", t); } /* ########################################################### */ }
From source file:de.maklerpoint.office.Tags.Tags.java
/** * Entfernt den Tag und ldt die Liste neu * @param tagName /* w w w .ja v a 2s. c o m*/ */ public static void removeTag(String tagName) { Preferences prefs = Preferences.userRoot().node(Tags.class.getName()); String taglist = prefs.get("tagListe", "Standard,ffentlich,Wichtig,Dienstlich,Persnlich"); String[] result = taglist.split(","); if (result == null) { return; } String[] clean = (String[]) ArrayUtils.removeElement(result, tagName); prefs.put("tagListe", ArrayStringTools.arrayToString(clean, ",")); InitializeTags.loadTags(); }
From source file:com.tera.common.vcontext.model.elements.AbstractContext.java
/** * @param name/*from w ww. j a va 2 s . c om*/ * @return */ private String[] extractNames(String name) { String[] nodes = name.split("/"); nodes = (String[]) ArrayUtils.removeElement(nodes, StringUtils.EMPTY); return nodes; }
From source file:net.navasoft.madcoin.backend.services.WorkRequestQueryFilter.java
/** * Choose filter.//from w w w . j a v a 2s . c o m * * @param entryVO * the entry vo * @return the generic filter * @since 27/07/2014, 06:48:16 PM */ @Override public GenericFilter<WorkRequestQueryVO> chooseFilter(WorkRequestQueryVO entryVO) { GenericFilter<WorkRequestQueryVO> selector = null; Method[] accessors = WorkRequestQueryVO.class.getMethods(); try { accessors = (Method[]) ArrayUtils.removeElement(accessors, WorkRequestQueryVO.class.getMethod("getClass", ArrayUtils.EMPTY_CLASS_ARRAY)); } catch (NoSuchMethodException e1) { e1.printStackTrace(); } catch (SecurityException e1) { e1.printStackTrace(); } try { if (entryVO != null) { for (Method beanGetters : accessors) { if (beanGetters.getName().startsWith("get")) { Object fieldValue; fieldValue = beanGetters.invoke(entryVO, ArrayUtils.EMPTY_OBJECT_ARRAY); if (fieldValue != null) { String fieldToFilter = beanGetters.getName().replace("get", ""); EFilters guessedFilters = null; if (ArrayUtils.contains(mandatory, fieldToFilter)) { guessedFilters = EFilters.valueOf(fieldToFilter.toUpperCase() + "_FILTER"); } else { if (guessedFilters == null) { guessedFilters = optionalCorrelation.get(fieldToFilter); } } selector = (GenericFilter<WorkRequestQueryVO>) Class .forName(guessedFilters.getImplementingClass()).getConstructor(EFilters.class) .newInstance(guessedFilters); } } } if (selector == null) { selector = WorkRequestNoFilter.class.newInstance(); } else { selector.setScope(entryVO); } return selector; } else { selector = WorkRequestNoFilter.class.newInstance(); } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return selector; }
From source file:fr.exanpe.t5.lib.internal.contextpagereset.ContextPageResetFilter.java
public void handlePageRender(PageRenderRequestParameters parameters, ComponentRequestHandler handler) throws IOException { PageRenderRequestParameters p = parameters; if (parameters.getActivationContext() != null && parameters.getActivationContext().toStrings() != null && parameters.getActivationContext().toStrings().length > 0 && ArrayUtils.contains(parameters.getActivationContext().toStrings(), contextMarker)) { if (logger.isDebugEnabled()) { logger.debug(/*from w w w. ja v a2 s . co m*/ "Context page reset marker {} has been found for page activation {} and will be removed.", contextMarker, parameters.getActivationContext()); } URLEventContext old = (URLEventContext) parameters.getActivationContext(); p = new PageRenderRequestParameters(parameters.getLogicalPageName(), new URLEventContext(contextValueEncoder, (String[]) ArrayUtils.removeElement(old.toStrings(), contextMarker)), false); } handler.handlePageRender(p); }
From source file:com.avatarproject.core.command.APTabCompleter.java
@Override public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) { List<String> complete = new ArrayList<String>(); if (cmd.getName().equalsIgnoreCase("avatar")) { if (args.length == 1) { List<String> possible = new ArrayList<String>(); for (APCommand command : APCommand.instances.values()) { if (hasPermission(sender, command.getName())) { possible.add(command.getAliases()[0]); }/* ww w. ja v a 2 s .c o m*/ } return getPossibleCompletionsForGivenArgs(args, possible); } if (args.length > 1) { for (APCommand command : APCommand.instances.values()) { if (ArrayUtils.contains(command.getAliases(), args[0].toLowerCase())) { if (command.getCompleters() != null) { if (command.getCompleters().length >= (args.length - 1)) { String[] completers = command.getCompleters()[(args.length - 2)]; if (Arrays.asList(completers).contains("%custom")) { completers = (String[]) ArrayUtils.removeElement(completers, "%custom"); completers = (String[]) ArrayUtils.addAll(completers, command.tabComplete(sender, args)); } if (Arrays.asList(completers).contains("%player")) { completers = (String[]) ArrayUtils.removeElement(completers, "%player"); List<String> array = new ArrayList<String>(); for (Player p : Bukkit.getOnlinePlayers()) { array.add(p.getName()); } completers = (String[]) ArrayUtils.addAll(completers, array.toArray(new String[array.size()])); } return getPossibleCompletionsForGivenArgs(args, completers); } } } } } } return complete; }
From source file:io.druid.segment.data.CompressionStrategy.java
public static CompressionStrategy[] noNoneValues() { return (CompressionStrategy[]) ArrayUtils.removeElement(CompressionStrategy.values(), NONE); }
From source file:adalid.core.AbstractPersistentEnumerationEntity.java
/** * @return the search instance array/*from www . j av a2 s. c o m*/ */ public Instance[] getSearchInstanceArray() { if (_searchInstanceArray == null && _removeInstanceArray != null && _removeInstanceArray.length > 0) { _searchInstanceArray = getInsertableRowsList().toArray(new Instance[0]); for (Instance instance : _removeInstanceArray) { _searchInstanceArray = (Instance[]) ArrayUtils.removeElement(_searchInstanceArray, instance); } } return _searchInstanceArray; }
From source file:com.aionemu.gameserver.controllers.ObserveController.java
/** * //from w ww . j a va2s . co m * @param observer */ public void removeObserver(ActionObserver observer) { synchronized (observers) { observers = (ActionObserver[]) ArrayUtils.removeElement(observers, observer); } }
From source file:com.aionemu.gameserver.controllers.ObserveController.java
/** * //from w w w . j a v a 2s . c om * @param observer */ public void removeEquipObserver(ActionObserver observer) { synchronized (equipObservers) { equipObservers = (ActionObserver[]) ArrayUtils.removeElement(equipObservers, observer); } }