Java Code Examples for org.apache.commons.lang.ArrayUtils#remove()
The following examples show how to use
org.apache.commons.lang.ArrayUtils#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJobInstance.java From haven-platform with Apache License 2.0 | 6 votes |
/** * Send message into job log which formatted as {@link MessageFormat#format(String, Object...)} * @param message message with * @param args objects, also first find throwable will be extracted and passed into event as {@link JobEvent#getException()} */ @Override public void send(String message, Object ... args) { Throwable throwable = null; if(!ArrayUtils.isEmpty(args)) { //find and extract throwable for(int i = 0; i < args.length; i++) { Object arg = args[i]; if(arg instanceof Throwable) { throwable = (Throwable) arg; args = ArrayUtils.remove(args, i); break; } } if(message != null) { try { message = MessageFormat.format(message, args); } catch (Exception e) { LOG.error("Cannot format message: \"{}\"", message, e); } } } sendEvent(new JobEvent(getInfo(), message, throwable)); }
Example 2
Source File: SearchRequestFactory.java From moneta with Apache License 2.0 | 6 votes |
protected String[] deriveSearchNodes(HttpServletRequest request) { String searchUri; if (request.getContextPath() != null) { searchUri = request.getRequestURI().substring(request.getContextPath().length()); } else { searchUri = request.getRequestURI(); } String[] nodes= StringUtils.split(searchUri, '/'); if (nodes != null && nodes.length > 0 && MonetaEnvironment.getConfiguration().getIgnoredContextPathNodes() != null) { while (ArrayUtils.contains(MonetaEnvironment.getConfiguration().getIgnoredContextPathNodes(), nodes[0])) { nodes=(String[])ArrayUtils.remove(nodes, 0); } } return nodes; }
Example 3
Source File: DisplayOptionsParser.java From smarthome with Eclipse Public License 2.0 | 6 votes |
/** * Returns all possible options from the given datapoint. */ private String[] getAvailableOptions(HmChannel channel, String datapointName) { HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, datapointName); HmDatapoint dp = channel.getDatapoint(dpInfo); if (dp != null) { String[] options = (String[]) ArrayUtils.remove(dp.getOptions(), 0); for (String onOffString : onOff) { int onIdx = ArrayUtils.indexOf(options, onOffString); if (onIdx != -1) { options[onIdx] = datapointName + "_" + onOffString; } } return options; } return new String[0]; }
Example 4
Source File: MessageStructureUtils.java From rice with Educational Community License v2.0 | 6 votes |
/** * Process the additional properties beyond index 0 of the tag (that was split into parts). * * <p>This will evaluate and set each of properties on the component passed in. This only allows * setting of properties that can easily be converted to/from/are String type by Spring.</p> * * @param component component to have its properties set * @param tagParts the tag split into parts, index 0 is ignored * @return component with its properties set found in the tag's parts */ private static Component processAdditionalProperties(Component component, String[] tagParts) { String componentString = tagParts[0]; tagParts = (String[]) ArrayUtils.remove(tagParts, 0); for (String part : tagParts) { String[] propertyValue = part.split("="); if (propertyValue.length == 2) { String path = propertyValue[0]; String value = propertyValue[1].trim(); value = StringUtils.removeStart(value, "'"); value = StringUtils.removeEnd(value, "'"); ObjectPropertyUtils.setPropertyValue(component, path, value); } else { throw new RuntimeException( "Invalid Message structure for component defined as " + componentString + " around " + part); } } return component; }
Example 5
Source File: RestrictionsManager.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public synchronized static void deactivate(Restrictions restriction) { for (RestrictionMode mode : RestrictionMode.VALUES) { Restrictions[] restrictions = RESTRICTIONS[mode.ordinal()]; for (int index; (index = ArrayUtils.indexOf(restrictions, restriction)) != -1;) { restrictions = (Restrictions[]) ArrayUtils.remove(restrictions, index); } RESTRICTIONS[mode.ordinal()] = restrictions; } }
Example 6
Source File: Http.java From ripme with MIT License | 5 votes |
private Map<String, String> cookiesForURL(String u) { Map<String, String> cookiesParsed = new HashMap<>(); String cookieDomain = ""; try { URL parsed = new URL(u); String cookieStr = ""; String[] parts = parsed.getHost().split("\\."); // if url is www.reddit.com, we should also use cookies from reddit.com; // this rule is applied for all subdomains (for all rippers); e.g. also // old.reddit.com, new.reddit.com while (parts.length > 1) { String domain = String.join(".", parts); // Try to get cookies for this host from config cookieStr = Utils.getConfigString("cookies." + domain, ""); if (cookieStr.equals("")) { cookieDomain = domain; // we found something, start parsing break; } parts = (String[]) ArrayUtils.remove(parts, 0); } if (!cookieStr.equals("")) { cookiesParsed = RipUtils.getCookiesFromString(cookieStr.trim()); } } catch (MalformedURLException e) { logger.warn("Parsing url " + u + " while getting cookies", e); } if (cookiesParsed.size() > 0) { logger.info("Cookies for " + cookieDomain + " have been added to this request"); } return cookiesParsed; }
Example 7
Source File: RemoteControlOptionParser.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Returns all possible value items from the remote control. */ private String[] getValueItems(String parameterName) { DatapointConfig dpConfig = new DatapointConfig(remoteControlAddress, "18", parameterName); HmValueItem hmValueItem = context.getStateHolder().getState(dpConfig); if (hmValueItem != null) { String[] valueList = (String[]) ArrayUtils.remove(hmValueItem.getValueList(), 0); int onIdx = ArrayUtils.indexOf(valueList, "ON"); if (onIdx != -1) { valueList[onIdx] = parameterName + "_ON"; } return valueList; } return new String[0]; }
Example 8
Source File: I18NHelper.java From yiistorm with MIT License | 5 votes |
public static String[] findMessageSource(String category, String protectedPath, Project project) { String[] parts = category.split("\\."); String catName = ""; if (parts.length > 1) { catName = parts[parts.length - 1]; parts = (String[]) ArrayUtils.remove(parts, parts.length - 1); } if (parts.length > 0) { if (parts[0].equals("app")) { parts = (String[]) ArrayUtils.remove(parts, 0); } String subpath = StringUtils.join(parts, "/"); String subpathAlias = StringUtils.join(parts, "."); String lang = I18NHelper.getLang(project); String subpathModules = protectedPath + "/modules/" + subpath + "/messages/" + lang; VirtualFile subDir = project.getBaseDir().findFileByRelativePath(subpathModules); if (subDir != null) { return new String[]{subpathModules, subpathAlias, catName}; } subDir = project.getBaseDir().findFileByRelativePath( protectedPath + "/components/" + subpath + "/messages/" + lang); if (subDir != null) { return new String[]{protectedPath + "/components/" + subpath + "/messages/" + lang, subpathAlias, catName}; } } return null; }
Example 9
Source File: CubeDesc.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
private void initDerivedMap(TblColRef[] hostCols, DeriveType type, JoinDesc join, 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); 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, whatsLeft.toArray(new TblColRef[whatsLeft.size()]), false)); } }
Example 10
Source File: EmoServiceWithZK.java From emodb with Apache License 2.0 | 4 votes |
public static void main(String... args) throws Exception { // Remove all nulls and empty strings from the argument list. This can happen as if the maven command // starts the service with no permission YAML files. args = Arrays.stream(args).filter(arg -> !Strings.isNullOrEmpty(arg)).toArray(String[]::new); // Start cassandra if necessary (cassandra.yaml is provided) ArgumentParser parser = ArgumentParsers.newArgumentParser("java -jar emodb-web-local*.jar"); parser.addArgument("server").required(true).help("server"); parser.addArgument("emo-config").required(true).help("config.yaml - EmoDB's config file"); parser.addArgument("emo-config-ddl").required(true).help("config-ddl.yaml - EmoDB's cassandra schema file"); parser.addArgument("cassandra-yaml").nargs("?").help("cassandra.yaml - Cassandra configuration file to start an" + " in memory embedded Cassandra."); parser.addArgument("-z","--zookeeper").dest("zookeeper").action(Arguments.storeTrue()).help("Starts zookeeper"); parser.addArgument("-p","--permissions-yaml").dest("permissions").nargs("*").help("Permissions file(s)"); // Get the path to cassandraYaml or if zookeeper is available Namespace result = parser.parseArgs(args); String cassandraYaml = result.getString("cassandra-yaml"); boolean startZk = result.getBoolean("zookeeper"); String emoConfigYaml = result.getString("emo-config"); List<String> permissionsYamls = result.getList("permissions"); String[] emoServiceArgs = args; // Start ZooKeeper TestingServer zooKeeperServer = null; if (startZk) { zooKeeperServer = isLocalZooKeeperRunning() ? null : startLocalZooKeeper(); emoServiceArgs = (String[]) ArrayUtils.removeElement(args, "-z"); emoServiceArgs = (String[]) ArrayUtils.removeElement(emoServiceArgs, "--zookeeper"); } boolean success = false; if (cassandraYaml != null) { // Replace $DIR$ so we can correctly specify location during runtime File templateFile = new File(cassandraYaml); String baseFile = Files.toString(templateFile, Charset.defaultCharset()); // Get the jar location String path = EmoServiceWithZK.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String parentDir = new File(path).getParent(); String newFile = baseFile.replace("$DATADIR$", new File(parentDir, "data").getAbsolutePath()); newFile = newFile.replace("$COMMITDIR$", new File(parentDir, "commitlog").getAbsolutePath()); newFile = newFile.replace("$CACHEDIR$", new File(parentDir, "saved_caches").getAbsolutePath()); File newYamlFile = new File(templateFile.getParent(), "emo-cassandra.yaml"); Files.write(newFile, newYamlFile, Charset.defaultCharset()); startLocalCassandra(newYamlFile.getAbsolutePath()); emoServiceArgs = (String[]) ArrayUtils.removeElement(emoServiceArgs, cassandraYaml); } // If permissions files were configured remove them from the argument list int permissionsIndex = Math.max(ArrayUtils.indexOf(emoServiceArgs, "-p"), ArrayUtils.indexOf(emoServiceArgs, "--permissions-yaml")); if (permissionsIndex >= 0) { int permissionsArgCount = 1 + permissionsYamls.size(); for (int i=0; i < permissionsArgCount; i++) { emoServiceArgs = (String[]) ArrayUtils.remove(emoServiceArgs, permissionsIndex); } } try { EmoService.main(emoServiceArgs); success = true; setPermissionsFromFiles(permissionsYamls, emoConfigYaml); } catch (Throwable t) { t.printStackTrace(); } finally { // The main web server command returns immediately--don't stop ZooKeeper/Cassandra in that case. if (zooKeeperServer != null && !(success && args.length > 0 && "server".equals(args[0]))) { zooKeeperServer.stop(); service.shutdown(); } } }
Example 11
Source File: AutoSensitivity.java From egads with GNU General Public License v3.0 | 4 votes |
public static Float getLowDensitySensitivity(Float[] data, float sDAutoSensitivy, float amntAutoSensitivity) { Float toReturn = Float.POSITIVE_INFINITY; Arrays.sort(data, Collections.reverseOrder()); while (data.length > 0) { ArrayList<Float> fData = new ArrayList<Float>(); fData.add(data[0]); data = ((Float[]) ArrayUtils.remove(data, 0)); Float centroid = (float) fData.get(0); Float maxDelta = (float) sDAutoSensitivy * StatsUtils.getSD(data, StatsUtils.getMean(data)); logger.debug("AutoSensitivity: Adding: " + fData.get(0) + " SD: " + maxDelta); // Add points while it's in the same cluster or not part of the other cluster. String localDebug = null; while (data.length > 0 && (centroid - data[0]) <= ((float) (maxDelta))) { float maxDeltaInit = maxDelta; fData.add(data[0]); data = ((Float[]) ArrayUtils.remove(data, 0)); Float[] tmp = new Float[fData.size()]; tmp = fData.toArray(tmp); centroid = StatsUtils.getMean(tmp); if (data.length > 0) { Float sdOtherCluster = (float) StatsUtils.getSD(data, StatsUtils.getMean(data)); maxDelta = sDAutoSensitivy * sdOtherCluster; logger.debug("AutoSensitivity: Adding: " + data[0] + " SD: " + maxDeltaInit + " SD': " + maxDelta); } } if (data.length > 0) { logger.debug("AutoSensitivity: Next Point I would have added is " + data[0]); } if (((double) fData.size() / (double) data.length) > amntAutoSensitivity) { // Cannot do anomaly detection. logger.debug("AutoSensitivity: Returning " + toReturn + " data size: " + data.length + " fData.size: " + fData.size()); return toReturn; } toReturn = fData.get(fData.size() - 1); logger.debug("AutoSensitivity: Updating toReturn: " + toReturn + " SD: " + maxDelta); return toReturn; } return toReturn; }
Example 12
Source File: CubeDesc.java From kylin with Apache License 2.0 | 4 votes |
private void initDerivedMap(TblColRef[] hostCols, DeriveType type, JoinDesc join, 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); 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, whatsLeft.toArray(new TblColRef[whatsLeft.size()]), false)); } }
Example 13
Source File: AllFormWidget.java From dynaform with Artistic License 2.0 | 4 votes |
private void disable(int indexDisplayed) { // Remove an index int[] newIndexes = ArrayUtils.remove(selectedIndexes, indexDisplayed); listener.selectIndexes(newIndexes); }
Example 14
Source File: TabCompleter.java From Lukkit with MIT License | 4 votes |
@Override public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] args) { List<String> tabComplete = new ArrayList<>(); if (command.getName().startsWith("lukkit")) if (args.length == 1) { return getFilteredCompletions(args[0], subCommands); } else if (args.length == 2) { // Set the String "cmd" to the first arg and remove the arg from the "args" array. String cmd = args[0]; // Get a new array with the first arg omitted args = (String[]) ArrayUtils.remove(args, 0); if (cmd.equalsIgnoreCase("dev")) { List<String> plugins = new ArrayList<>(); // Iterate over the plugins and add them to the map by lower-cased name Main.instance.iteratePlugins(p -> plugins.add(p.getName())); String[] pluginArr = plugins.toArray(new String[plugins.size()]); if (args.length == 1) { return getFilteredCompletions(args[0], devSubCommands); } else if (args.length == 2) { if (args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("unload") || args[0].equalsIgnoreCase("pack") || args[0].equalsIgnoreCase("unpack")) { return getFilteredCompletions(args[1], pluginArr); } } else if (args[0].equalsIgnoreCase("errors")) { Optional<Stream<Exception>> errors = LuaEnvironment.getErrors(); errors.ifPresent(exceptionStream -> exceptionStream.forEach(new Consumer<Exception>() { int count = 0; @Override public void accept(Exception e) { tabComplete.add(String.valueOf(count)); count++; } })); } } } return tabComplete; }
Example 15
Source File: NibeHeatPumpDataParser.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
public static Hashtable<Integer, Short> ParseData(byte[] data) throws NibeHeatPumpException { if (data[0] == (byte) 0x5C && data[1] == (byte) 0x00 && data[2] == (byte) 0x20 && data[3] == (byte) 0x68 && data[4] >= (byte) 0x50) { int datalen = data[4]; int msglen = 5 + datalen; byte checksum = 0; // calculate XOR checksum for (int i = 2; i < msglen; i++) { checksum ^= data[i]; } byte msgChecksum = data[msglen]; // if checksum is 0x5C (start character), heat pump seems to send 0xC5 checksum if (checksum == msgChecksum || (checksum == (byte) 0x5C && msgChecksum == (byte) 0xC5)) { if (datalen > 0x50) { // if data contains 0x5C (start character), // data seems to contains double 0x5C characters // let's remove doubles for (int i = 1; i < msglen; i++) { if (data[i] == (byte) 0x5C) { data = ArrayUtils.remove(data, i); msglen--; } } } // parse data to hash table Hashtable<Integer, Short> values = new Hashtable<Integer, Short>(); try { for (int i = 5; i < (msglen - 1); i += 4) { int id = ((data[i + 1] & 0xFF) << 8 | (data[i + 0] & 0xFF)); short value = (short) ((data[i + 3] & 0xFF) << 8 | (data[i + 2] & 0xFF)); if (id != 0xFFFF) { values.put(id, value); } } } catch (ArrayIndexOutOfBoundsException e) { throw new NibeHeatPumpException("Error occurred during data parsing", e); } return values; } else { throw new NibeHeatPumpException("Checksum does not match"); } } else { return null; } }
Example 16
Source File: ArangoDBVertex.java From arangodb-tinkerpop-provider with Apache License 2.0 | 4 votes |
@Override public <V> VertexProperty<V> property( Cardinality cardinality, String key, V value, Object... keyValues) { logger.debug("setting vertex property {} = {} ({})", key, value, keyValues); ElementHelper.validateProperty(key, value); ElementHelper.legalPropertyKeyValueArray(keyValues); Optional<Object> idValue = ElementHelper.getIdValue(keyValues); String id = null; if (idValue.isPresent()) { if (graph.features().vertex().willAllowId(idValue.get())) { id = idValue.get().toString(); if (id.toString().contains("/")) { String fullId = id.toString(); String[] parts = fullId.split("/"); // The collection name is the last part of the full name String[] collectionParts = parts[0].split("_"); String collectionName = collectionParts[collectionParts.length-1]; if (collectionName.contains(ArangoDBGraph.ELEMENT_PROPERTIES_COLLECTION)) { id = parts[1]; } } Matcher m = ArangoDBUtil.DOCUMENT_KEY.matcher((String)id); if (!m.matches()) { throw new ArangoDBGraphException(String.format("Given id (%s) has unsupported characters.", id)); } } else { throw VertexProperty.Exceptions.userSuppliedIdsOfThisTypeNotSupported(); } int idIndex = 0; for (int i = 0; i < keyValues.length; i+=2) { if (keyValues[i] == T.id) { idIndex = i; break; } } keyValues = ArrayUtils.remove(keyValues, idIndex); keyValues = ArrayUtils.remove(keyValues, idIndex); } final Optional<VertexProperty<V>> optionalVertexProperty = ElementHelper.stageVertexProperty(this, cardinality, key, value, keyValues); if (optionalVertexProperty.isPresent()) return optionalVertexProperty.get(); ArangoDBVertexProperty<V> p = ArangoDBUtil.createArangoDBVertexProperty(id, key, value, this); ElementHelper.attachProperties(p, keyValues); return p; }