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:org.jumpmind.symmetric.io.data.writer.MsSqlBulkDatabaseWriterTest.java
@Test public void testInsertReorderColumns() throws Exception { if (shouldTestRun(platform)) { String id = getNextId();/*from w ww .java 2s .c om*/ String[] values = { "string with space in it", "string-with-no-space", "string with space in it", "string-with-no-space", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747663", encode("string with space in it"), id }; List<CsvData> data = new ArrayList<CsvData>(); data.add(new CsvData(DataEventType.INSERT, (String[]) ArrayUtils.clone(values))); Table table = (Table) platform.getTableFromCache(getTestTable(), false).clone(); Column firstColumn = table.getColumn(0); table.removeColumn(firstColumn); table.addColumn(firstColumn); writeData(new MsSqlBulkDatabaseWriter(platform, stagingManager, new CommonsDbcpNativeJdbcExtractor(), 1000, false, uncPath, null, null), new TableCsvData(table, data)); values = (String[]) ArrayUtils.remove(values, values.length - 1); values = (String[]) ArrayUtils.add(values, 0, id); assertTestTableEquals(id, values); } }
From source file:org.kuali.rice.krad.uif.util.MessageStructureUtils.java
/** * 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 */// ww w. ja v a2 s . c o m 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; }
From source file:org.lexgrid.loader.processor.support.BeanReflectionTruncator.java
/** * Do truncate./*from w ww . j a va 2s. c om*/ * * @param path the path * @param obj the obj * @param length the length * * @throws Exception the exception */ protected void doTruncate(String[] path, Object obj, int length) throws Exception { if (path.length > 1) { doTruncate((String[]) ArrayUtils.remove(path, 0), getObject(obj, path[0]), length); } else { Object fieldObj = getObject(obj, path[0]); if (fieldObj instanceof String) { String fieldValue = (String) fieldObj; if (fieldValue.length() >= length) { this.getField(obj, path[0]).set(obj, fieldValue.substring(0, length)); } } } }
From source file:org.moneta.SearchRequestFactory.java
protected String[] deriveSearchNodes(HttpServletRequest request) { String searchUri;//from www. j ava 2 s . c o m 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; }
From source file:org.motechproject.server.decisiontree.web.VxmlController.java
/** * Handles Decision Tree Node HTTP requests and generates a VXML document based on a Velocity template. * The HTTP request should contain the Tree ID, Node ID, Patient ID and Selected Transition Key (optional) parameters * *//*w ww . j a va2s. c om*/ public ModelAndView node(HttpServletRequest request, HttpServletResponse response) { logger.info("Generating decision tree node VXML"); response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); Node node = null; String transitionPath = null; Map<String, Object> params = convertParams(request.getParameterMap()); String patientId = request.getParameter(PATIENT_ID_PARAM); String language = request.getParameter(LANGUAGE_PARAM); String treeNameString = request.getParameter(TREE_NAME_PARAM); String encodedParentTransitionPath = request.getParameter(TRANSITION_PATH_PARAM); String transitionKey = request.getParameter(TRANSITION_KEY_PARAM); logger.info(" Node HTTP request parameters: " + PATIENT_ID_PARAM + ": " + patientId + ", " + LANGUAGE_PARAM + ": " + language + ", " + TREE_NAME_PARAM + ": " + treeNameString + ", " + TRANSITION_PATH_PARAM + ": " + encodedParentTransitionPath + ", " + TRANSITION_KEY_PARAM + ": " + transitionKey); if (StringUtils.isBlank(patientId) || StringUtils.isBlank(language) || StringUtils.isBlank(treeNameString)) { logger.error("Invalid HTTP request - the following parameters: " + PATIENT_ID_PARAM + ", " + LANGUAGE_PARAM + " and " + TREE_NAME_PARAM + " are mandatory"); return getErrorModelAndView(Errors.NULL_PATIENTID_LANGUAGE_OR_TREENAME_PARAM); } String[] treeNames = treeNameString.split(TREE_NAME_SEPARATOR); String currentTree = treeNames[0]; // put only one tree name in params params.put(TREE_NAME_PARAM, currentTree); if (transitionKey == null) { // get root node try { String rootTransitionPath = TreeNodeLocator.PATH_DELIMITER; node = decisionTreeService.getNode(currentTree, rootTransitionPath); transitionPath = rootTransitionPath; } catch (Exception e) { logger.error("Can not get node by Tree Name: " + currentTree + " transition path: " + patientId, e); } } else { // get not root node String parentTransitionPath = null; try { if (encodedParentTransitionPath == null) { logger.error( "Invalid HTTP request - the " + TRANSITION_PATH_PARAM + " parameter is mandatory"); return getErrorModelAndView(Errors.NULL_TRANSITION_PATH_PARAM); } parentTransitionPath = new String(Base64.decodeBase64(encodedParentTransitionPath)); Node parentNode = decisionTreeService.getNode(currentTree, parentTransitionPath); Transition transition = parentNode.getTransitions().get(transitionKey); if (transition == null) { logger.error("Invalid Transition Key. There is no transition with key: " + transitionKey + " in the Node: " + parentNode); return getErrorModelAndView(Errors.INVALID_TRANSITION_KEY); } treeEventProcessor.sendActionsAfter(parentNode, parentTransitionPath, params); treeEventProcessor.sendTransitionActions(transition, params); node = transition.getDestinationNode(); if (node == null || (node.getPrompts().isEmpty() && node.getActionsAfter().isEmpty() && node.getActionsBefore().isEmpty() && node.getTransitions().isEmpty())) { if (treeNames.length > 1) { //reduce the current tree and redirect to the next tree treeNames = (String[]) ArrayUtils.remove(treeNames, 0); String view = String.format( "redirect:/tree/vxml/node?" + PATIENT_ID_PARAM + "=%s&" + TREE_NAME_PARAM + "=%s&" + LANGUAGE_PARAM + "=%s", patientId, StringUtils.join(treeNames, TREE_NAME_SEPARATOR), language); ModelAndView mav = new ModelAndView(view); return mav; } else { //TODO: Add support for return url ModelAndView mav = new ModelAndView(EXIT_TEMPLATE_NAME); return mav; } } else { transitionPath = parentTransitionPath + (TreeNodeLocator.PATH_DELIMITER.equals(parentTransitionPath) ? "" : TreeNodeLocator.PATH_DELIMITER) + transitionKey; } } catch (Exception e) { logger.error("Can not get node by Tree ID : " + currentTree + " and Transition Path: " + parentTransitionPath, e); } } if (node != null) { //validate node for (Map.Entry<String, Transition> transitionEntry : node.getTransitions().entrySet()) { try { Integer.parseInt(transitionEntry.getKey()); } catch (NumberFormatException e) { logger.error("Invalid node: " + node + "\n In order to be used in VXML transition keys should be an Integer"); return getErrorModelAndView(Errors.INVALID_TRANSITION_KEY_TYPE); } Transition transition = transitionEntry.getValue(); if (transition.getDestinationNode() == null) { logger.error( "Invalid node: " + node + "\n Null Destination Node in the Transition: " + transition); return getErrorModelAndView(Errors.NULL_DESTINATION_NODE); } } treeEventProcessor.sendActionsBefore(node, transitionPath, params); ModelAndView mav = new ModelAndView(); if (node.getTransitions().size() > 0) { mav.setViewName(NODE_TEMPLATE_NAME); mav.addObject("treeName", treeNameString); } else { // leaf //reduce the current tree and redirect to the next tree treeNames = (String[]) ArrayUtils.remove(treeNames, 0); mav.setViewName(LEAF_TEMPLATE_NAME); mav.addObject("treeName", StringUtils.join(treeNames, TREE_NAME_SEPARATOR)); } mav.addObject("contentPath", request.getContextPath()); mav.addObject("node", node); mav.addObject("patientId", patientId); mav.addObject("language", language); mav.addObject("transitionPath", Base64.encodeBase64URLSafeString(transitionPath.getBytes())); mav.addObject("escape", new StringEscapeUtils()); return mav; } else { return getErrorModelAndView(Errors.GET_NODE_ERROR); } }
From source file:org.openhab.binding.homematic.internal.communicator.RemoteControlOptionParser.java
/** * Returns all possible value items from the remote control. *//* w ww. j a v a 2 s . c o m*/ 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]; }
From source file:org.openhab.binding.neeo.internal.NeeoRoomProtocol.java
/** * Processes a change to the scenario (whether it's been launched or not) * * @param scenarioKey a non-null, non-empty scenario key * @param launch true if the scenario was launched, false otherwise *//*from w ww .j a va2 s. co m*/ private void processScenarioChange(String scenarioKey, boolean launch) { NeeoUtil.requireNotEmpty(scenarioKey, "scenarioKey cannot be empty"); final String[] activeScenarios = this.activeScenarios.get(); final int idx = ArrayUtils.indexOf(activeScenarios, scenarioKey); // already set that way if ((idx < 0 && !launch) || (idx >= 0 && launch)) { return; } final String[] newScenarios = idx >= 0 ? (String[]) ArrayUtils.remove(activeScenarios, idx) : (String[]) ArrayUtils.add(activeScenarios, scenarioKey); this.activeScenarios.set(newScenarios); refreshScenarioStatus(scenarioKey); }
From source file:org.openhab.binding.nibeheatpump.internal.protocol.NibeHeatPumpProtocol.java
public static byte[] checkMessageChecksumAndRemoveDoubles(byte[] data) throws NibeHeatPumpException { int msglen;/*from ww w.ja v a2s . c om*/ int startIndex; int stopIndex; if (NibeHeatPumpProtocol.isModbus40ReadRequestPdu(data) || NibeHeatPumpProtocol.isModbus40WriteRequestPdu(data)) { msglen = 3 + data[2]; startIndex = 0; stopIndex = msglen; } else { msglen = 5 + data[OFFSET_LEN]; startIndex = 2; stopIndex = msglen; } final byte checksum = calculateChecksum(data, startIndex, stopIndex); final byte msgChecksum = data[msglen]; // if checksum is 0x5C (start character), heat pump seems to send 0xC5 checksum if (checksum == msgChecksum || (checksum == FRAME_START_CHAR_FROM_NIBE && msgChecksum == (byte) 0xC5)) { // 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] == FRAME_START_CHAR_FROM_NIBE) { data = ArrayUtils.remove(data, i); msglen--; // fix message len data[OFFSET_LEN]--; } } } else { throw new NibeHeatPumpException("Checksum does not match. Checksum=" + (msgChecksum & 0xFF) + ", expected=" + (checksum & 0xFF)); } return data; }
From source file:org.openhab.binding.nibeheatpump.protocol.NibeHeatPumpDataParser.java
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];/*from ww w .j av a 2s .co m*/ 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 occured during data parsing", e); } return values; } else { throw new NibeHeatPumpException("Checksum does not match"); } } else { return null; } }
From source file:org.openhab.binding.stiebelheatpump.protocol.StiebelHeatPumpDataParser.java
public static Hashtable<Integer, Short> ParseData(byte[] data) throws StiebelHeatPumpException { 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];//w ww . j a v a2s .c o m 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 StiebelHeatPumpException("Error occured during data parsing", e); } return values; } else { throw new StiebelHeatPumpException("Checksum does not match"); } } else { return null; } }