List of usage examples for org.apache.commons.lang ArrayUtils addAll
public static double[] addAll(double[] array1, double[] array2)
Adds all the elements of the given arrays into a new array.
From source file:com.earnstone.index.ShardedIndex.java
protected byte[] getShardKeyForIndex(T index) { if (shards.size() == 0) { return emptyIndexKey; } else {//from w ww. java2 s . c o m T shard = shards.ceilingKey(index); if (shard == null) return emptyIndexKey; else return ArrayUtils.addAll(baseIndexKey, ArrayUtils.addAll(Delim, getBytesForData(shard))); } }
From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java
public static byte[] encodeNullableFixedLong(Long value) { if (value == null) { return new byte[9]; } else {/*from w w w . ja v a2 s .c o m*/ return ArrayUtils.addAll(new byte[] { 1 }, PtBytes.toBytes(Long.MIN_VALUE ^ value)); } }
From source file:com.kstenschke.copypastestack.ToolWindow.java
/** * Bubble all color-tagged items to the top of the list (groups: yellow, green, reed, untagged) */// ww w. j a v a 2 s. c o m private void sortClipboardListByTags(boolean sortAlphabetically) { ListModel<String> listModel = this.form.listClipItems.getModel(); int amountItems = listModel.getSize(); if (amountItems > 0) { String[] itemsYellow = new String[amountItems + 1]; int indexYellow = 0; String[] itemsGreen = new String[amountItems + 1]; int indexGreen = 0; String[] itemsRed = new String[amountItems + 1]; int indexRed = 0; String[] itemsUntagged = new String[amountItems + 1]; int indexUntagged = 0; // Refill items from listModel into sortable arrays for (int i = 0; i < amountItems; i++) { String item = listModel.getElementAt(i); if (item != null && !item.trim().isEmpty()) { switch (TagManager.getIdColorByValue(item)) { case StaticValues.ID_COLOR_YELLOW: itemsYellow[indexYellow] = item; indexYellow++; break; case StaticValues.ID_COLOR_GREEN: itemsGreen[indexGreen] = item; indexGreen++; break; case StaticValues.ID_COLOR_RED: itemsRed[indexRed] = item; indexRed++; break; case StaticValues.ID_COLOR_NONE: itemsUntagged[indexUntagged] = item; indexUntagged++; break; } } } // Reduce arrays to size of actual content itemsYellow = Arrays.copyOfRange(itemsYellow, 0, indexYellow); itemsRed = Arrays.copyOfRange(itemsRed, 0, indexRed); itemsGreen = Arrays.copyOfRange(itemsGreen, 0, indexGreen); itemsUntagged = Arrays.copyOfRange(itemsUntagged, 0, indexUntagged); // Sort string items alphabetically if (sortAlphabetically) { if (itemsYellow.length > 1) Arrays.sort(itemsYellow, String.CASE_INSENSITIVE_ORDER); if (itemsGreen.length > 1) Arrays.sort(itemsGreen, String.CASE_INSENSITIVE_ORDER); if (itemsRed.length > 1) Arrays.sort(itemsRed, String.CASE_INSENSITIVE_ORDER); if (itemsUntagged.length > 1) Arrays.sort(itemsUntagged, String.CASE_INSENSITIVE_ORDER); } // Update list from sorted items this.setClipboardListData(ArrayUtils.addAll( ArrayUtils.addAll(ArrayUtils.addAll(itemsYellow, itemsGreen), itemsRed), itemsUntagged), false); } }
From source file:bdv.bigcat.label.FragmentSegmentAssignment.java
/** * Merge two segments./*from ww w. j a va 2s. co m*/ * * @param segmentId1 * @param segmentId2 */ public void mergeSegments(final long segmentId1, final long segmentId2) { if (segmentId1 == segmentId2) return; final long mergedSegmentId = idService.next(); synchronized (this) { final long[] fragments1 = ilut.get(segmentId1); final long[] fragments2 = ilut.get(segmentId2); final long[] fragments = ArrayUtils.addAll(fragments1, fragments2); for (final long fragmentId : fragments) lut.put(fragmentId, mergedSegmentId); ilut.put(mergedSegmentId, fragments); ilut.remove(segmentId1); ilut.remove(segmentId2); } }
From source file:gda.scan.ScanDataPoint.java
/** * Add a scannable to the list of scannables this object holds data on. * <p>/*from w ww. ja va2 s.c om*/ * Note that this does not read the current position of the scannable. * * @param scannable */ @Override public void addScannable(Scannable scannable) { // scannableNames = (String[]) ArrayUtils.add(scannableNames, scannable.getName()); scanInfo.setScannableNames((String[]) ArrayUtils.add(scanInfo.getScannableNames(), scannable.getName())); scannableHeader = (String[]) ArrayUtils.addAll(scannableHeader, scannable.getInputNames()); scannableHeader = (String[]) ArrayUtils.addAll(scannableHeader, scannable.getExtraNames()); scannables.add(scannable); }
From source file:net.sf.firemox.DeckBuilder.java
/** * Creates new form DeckBuilder//from w w w . j a v a2 s. co m */ private DeckBuilder() { super("DeckBuilder"); form = this; timerPanel = new TimerGlassPane(); cardLoader = new CardLoader(timerPanel); timer = new Timer(200, cardLoader); setGlassPane(timerPanel); try { setIconImage(Picture.loadImage(IdConst.IMAGES_DIR + "deckbuilder.gif")); } catch (Exception e) { // IGNORING } // Load settings loadSettings(); // Initialize components final JMenuItem newItem = UIHelper.buildMenu("menu_db_new", 'n', this); newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK)); final JMenuItem loadItem = UIHelper.buildMenu("menu_db_load", 'o', this); loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); final JMenuItem saveAsItem = UIHelper.buildMenu("menu_db_saveas", 'a', this); saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0)); final JMenuItem saveItem = UIHelper.buildMenu("menu_db_save", 's', this); saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); final JMenuItem quitItem = UIHelper.buildMenu("menu_db_exit", this); quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK)); final JMenuItem deckConstraintsItem = UIHelper.buildMenu("menu_db_constraints", 'c', this); deckConstraintsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); final JMenuItem aboutItem = UIHelper.buildMenu("menu_help_about", 'a', this); aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.SHIFT_MASK)); final JMenuItem convertDCK = UIHelper.buildMenu("menu_convert_DCK_MP", this); final JMenu mainMenu = UIHelper.buildMenu("menu_file"); mainMenu.add(newItem); mainMenu.add(loadItem); mainMenu.add(saveAsItem); mainMenu.add(saveItem); mainMenu.add(new JSeparator()); mainMenu.add(quitItem); super.optionMenu = new JMenu("Options"); final JMenu convertMenu = UIHelper.buildMenu("menu_convert"); convertMenu.add(convertDCK); final JMenuItem helpItem = UIHelper.buildMenu("menu_help_help", 'h', this); helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); final JMenu helpMenu = new JMenu("?"); helpMenu.add(helpItem); helpMenu.add(deckConstraintsItem); helpMenu.add(aboutItem); final JMenuBar menuBar = new JMenuBar(); menuBar.add(mainMenu); initAbstractMenu(); menuBar.add(optionMenu); menuBar.add(convertMenu); menuBar.add(helpMenu); setJMenuBar(menuBar); addWindowListener(this); // Build the panel containing amount of available cards final JLabel amountLeft = new JLabel("<html>0/?", SwingConstants.RIGHT); // Build the left list allListModel = new MListModel<MCardCompare>(amountLeft, false); leftList = new ThreadSafeJList(allListModel); leftList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); leftList.setLayoutOrientation(JList.VERTICAL); leftList.getSelectionModel().addListSelectionListener(this); leftList.addMouseListener(this); leftList.setVisibleRowCount(10); // Initialize the text field containing the amount to add addQtyTxt = new JTextField("1"); // Build the "Add" button addButton = new JButton(LanguageManager.getString("db_add")); addButton.setMnemonic('a'); addButton.setEnabled(false); // Build the panel containing : "Add" amount and "Add" button final Box addPanel = Box.createHorizontalBox(); addPanel.add(addButton); addPanel.add(addQtyTxt); addPanel.setMaximumSize(new Dimension(32010, 26)); // Build the panel containing the selected card name cardNameTxt = new JTextField(); new HireListener(cardNameTxt, addButton, this, leftList); final JLabel searchLabel = new JLabel(LanguageManager.getString("db_search") + " : "); searchLabel.setLabelFor(cardNameTxt); // Build the panel containing search label and card name text field final Box searchPanel = Box.createHorizontalBox(); searchPanel.add(searchLabel); searchPanel.add(cardNameTxt); searchPanel.setMaximumSize(new Dimension(32010, 26)); listScrollerLeft = new JScrollPane(leftList); MToolKit.addOverlay(listScrollerLeft); // Build the left panel containing : list, available amount, "Add" panel final JPanel srcPanel = new JPanel(null); srcPanel.add(searchPanel); srcPanel.add(listScrollerLeft); srcPanel.add(amountLeft); srcPanel.add(addPanel); srcPanel.setMinimumSize(new Dimension(220, 200)); srcPanel.setLayout(new BoxLayout(srcPanel, BoxLayout.Y_AXIS)); // Initialize constraints constraintsChecker = new ConstraintsChecker(); constraintsChecker.setBorder(new EtchedBorder()); final JScrollPane constraintsCheckerScroll = new JScrollPane(constraintsChecker); MToolKit.addOverlay(constraintsCheckerScroll); // create a pane with the oracle text for the present card oracleText = new JLabel(); oracleText.setPreferredSize(new Dimension(180, 200)); oracleText.setVerticalAlignment(SwingConstants.TOP); final JScrollPane oracle = new JScrollPane(oracleText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); MToolKit.addOverlay(oracle); // build some Pie Charts and a panel to display it initSets(); datasets = new ChartSets(); final JTabbedPane tabbedPane = new JTabbedPane(); for (ChartFilter filter : ChartFilter.values()) { final Dataset dataSet = filter.createDataSet(this); final JFreeChart chart = new JFreeChart(null, null, filter.createPlot(dataSet, painterMapper.get(filter)), false); datasets.addDataSet(filter, dataSet); ChartPanel pieChartPanel = new ChartPanel(chart, true); tabbedPane.add(pieChartPanel, filter.getTitle()); } // add the Constraints scroll panel and Oracle text Pane to the tabbedPane tabbedPane.add(constraintsCheckerScroll, LanguageManager.getString("db_constraints")); tabbedPane.add(oracle, LanguageManager.getString("db_text")); tabbedPane.setSelectedComponent(oracle); // The toollBar for color filtering toolBar = new JToolBar(); toolBar.setFloatable(false); final JButton clearButton = UIHelper.buildButton("clear"); clearButton.addActionListener(this); toolBar.add(clearButton); final JToggleButton toggleColorlessButton = new JToggleButton( UIHelper.getTbsIcon("mana/colorless/small/" + MdbLoader.unknownSmlMana), true); toggleColorlessButton.setActionCommand("0"); toggleColorlessButton.addActionListener(this); toolBar.add(toggleColorlessButton); for (int index = 1; index < IdCardColors.CARD_COLOR_NAMES.length; index++) { final JToggleButton toggleButton = new JToggleButton( UIHelper.getTbsIcon("mana/colored/small/" + MdbLoader.coloredSmlManas[index]), true); toggleButton.setActionCommand(String.valueOf(index)); toggleButton.addActionListener(this); toolBar.add(toggleButton); } // sorted card type combobox creation final List<String> idCards = new ArrayList<String>(Arrays.asList(CardFactory.exportedIdCardNames)); Collections.sort(idCards); final Object[] cardTypes = ArrayUtils.addAll(new String[] { LanguageManager.getString("db_types.any") }, idCards.toArray()); idCardComboBox = new JComboBox(cardTypes); idCardComboBox.setSelectedIndex(0); idCardComboBox.addActionListener(this); idCardComboBox.setActionCommand("cardTypeFilter"); // sorted card properties combobox creation final List<String> properties = new ArrayList<String>( CardFactory.getPropertiesName(DeckConstraints.getMinProperty(), DeckConstraints.getMaxProperty())); Collections.sort(properties); final Object[] cardProperties = ArrayUtils .addAll(new String[] { LanguageManager.getString("db_properties.any") }, properties.toArray()); propertiesComboBox = new JComboBox(cardProperties); propertiesComboBox.setSelectedIndex(0); propertiesComboBox.addActionListener(this); propertiesComboBox.setActionCommand("propertyFilter"); final JLabel colors = new JLabel(" " + LanguageManager.getString("colors") + " : "); final JLabel types = new JLabel(" " + LanguageManager.getString("types") + " : "); final JLabel property = new JLabel(" " + LanguageManager.getString("properties") + " : "); // filter Panel with colors toolBar and card type combobox final Box filterPanel = Box.createHorizontalBox(); filterPanel.add(colors); filterPanel.add(toolBar); filterPanel.add(types); filterPanel.add(idCardComboBox); filterPanel.add(property); filterPanel.add(propertiesComboBox); getContentPane().add(filterPanel, BorderLayout.NORTH); // Destination section : // Build the panel containing amount of available cards final JLabel rightAmount = new JLabel("0/?", SwingConstants.RIGHT); rightAmount.setMaximumSize(new Dimension(220, 26)); // Build the right list rightListModel = new MCardTableModel(new MListModel<MCardCompare>(rightAmount, true)); rightListModel.addTableModelListener(this); rightList = new JTable(rightListModel); rightList.setShowGrid(false); rightList.setTableHeader(null); rightList.getSelectionModel().addListSelectionListener(this); rightList.getColumnModel().getColumn(0).setMaxWidth(25); rightList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); // Build the panel containing the selected deck deckNameTxt = new JTextField("loading..."); deckNameTxt.setEditable(false); deckNameTxt.setBorder(null); final JLabel deckLabel = new JLabel(LanguageManager.getString("db_deck") + " : "); deckLabel.setLabelFor(deckNameTxt); final Box deckNamePanel = Box.createHorizontalBox(); deckNamePanel.add(deckLabel); deckNamePanel.add(deckNameTxt); deckNamePanel.setMaximumSize(new Dimension(220, 26)); // Initialize the text field containing the amount to remove removeQtyTxt = new JTextField("1"); // Build the "Remove" button removeButton = new JButton(LanguageManager.getString("db_remove")); removeButton.setMnemonic('r'); removeButton.addMouseListener(this); removeButton.setEnabled(false); // Build the panel containing : "Remove" amount and "Remove" button final Box removePanel = Box.createHorizontalBox(); removePanel.add(removeButton); removePanel.add(removeQtyTxt); removePanel.setMaximumSize(new Dimension(220, 26)); // Build the right panel containing : list, available amount, constraints final JScrollPane deskListScroller = new JScrollPane(rightList); MToolKit.addOverlay(deskListScroller); deskListScroller.setBorder(BorderFactory.createLineBorder(Color.GRAY)); deskListScroller.setMinimumSize(new Dimension(220, 200)); deskListScroller.setMaximumSize(new Dimension(220, 32000)); final Box destPanel = Box.createVerticalBox(); destPanel.add(deckNamePanel); destPanel.add(deskListScroller); destPanel.add(rightAmount); destPanel.add(removePanel); destPanel.setMinimumSize(new Dimension(220, 200)); destPanel.setMaximumSize(new Dimension(220, 32000)); // Build the panel containing the name of card in picture cardPictureNameTxt = new JLabel("<html><i>no selected card</i>"); final Box cardPictureNamePanel = Box.createHorizontalBox(); cardPictureNamePanel.add(cardPictureNameTxt); cardPictureNamePanel.setMaximumSize(new Dimension(32010, 26)); // Group the detail panels final JPanel viewCard = new JPanel(null); viewCard.add(cardPictureNamePanel); viewCard.add(CardView.getInstance()); viewCard.add(tabbedPane); viewCard.setLayout(new BoxLayout(viewCard, BoxLayout.Y_AXIS)); final Box mainPanel = Box.createHorizontalBox(); mainPanel.add(destPanel); mainPanel.add(viewCard); // Add the main panel getContentPane().add(srcPanel, BorderLayout.WEST); getContentPane().add(mainPanel, BorderLayout.CENTER); // Size this frame getRootPane().setPreferredSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT)); getRootPane().setMinimumSize(getRootPane().getPreferredSize()); pack(); }
From source file:br.unicamp.ic.recod.gpsi.applications.gpsiJGAPSelectorEvolver.java
private GPGenotype create(GPConfiguration conf, int n_bands, gpsiJGAPFitnessFunction fitness, int[] bands) throws InvalidConfigurationException { Class[] types = { CommandGene.DoubleClass }; Class[][] argTypes = { {} };/*from ww w. j a va 2 s . c om*/ CommandGene[] variables; Variable[] b = new Variable[n_bands]; CommandGene[] functions = { new Add(conf, CommandGene.DoubleClass), new Subtract(conf, CommandGene.DoubleClass), new Multiply(conf, CommandGene.DoubleClass), new gpsiJGAPProtectedDivision(conf, CommandGene.DoubleClass), new gpsiJGAPProtectedNaturalLogarithm(conf, CommandGene.DoubleClass), new gpsiJGAPProtectedSquareRoot(conf, CommandGene.DoubleClass), new Terminal(conf, CommandGene.DoubleClass, 1.0d, 1000000.0d, false) }; int i; for (i = 0; i < n_bands; i++) { b[i] = Variable.create(conf, "b" + i, CommandGene.DoubleClass); } if (bands == null) { variables = new CommandGene[n_bands]; for (i = 0; i < n_bands; i++) { variables[i] = b[i]; } } else { Arrays.sort(bands); variables = new CommandGene[bands.length]; for (i = 0; i < bands.length; i++) { variables[i] = b[bands[i]]; } } CommandGene[][] nodeSets = new CommandGene[1][]; nodeSets[0] = (CommandGene[]) ArrayUtils.addAll(variables, functions); fitness.setB(b); return GPGenotype.randomInitialGenotype(conf, types, argTypes, nodeSets, 100, true); }
From source file:com.earnstone.index.ShardedIndex.java
protected byte[] getNextNearestShardKeyForIndex(T index, boolean reversed) { if (shards.size() == 0) { return null; } else {//from w w w . j a v a 2 s . c o m T shard = shards.ceilingKey(index); if (reversed) { if (shard == null) shard = shards.lastKey(); else shard = shards.lowerKey(shard); if (shard == null) return null; } else { if (shard == null) return null; else shard = shards.higherKey(shard); if (shard == null) return emptyIndexKey; } return ArrayUtils.addAll(baseIndexKey, ArrayUtils.addAll(Delim, getBytesForData(shard))); } }
From source file:com.earnstone.index.ShardedIndex.java
protected byte[] getSubShardKeyForIndex(T index) { return ArrayUtils.addAll(baseIndexKey, ArrayUtils.addAll(SubDelim, getBytesForData(index))); }
From source file:com.oneops.inductor.ActionOrderExecutor.java
/** * Calls local or remote chef to do recipe [ciClassname::wo.getRfcCi().rfcAction] * * @param ao action order/*ww w. j ava2s .c om*/ */ private void runActionOrder(CmsActionOrderSimple ao) { // file-based request keyed by deployment record id - remotely by // class.ciName for ease of debug String remoteFileName = getRemoteFile(ao); String fileName = config.getDataDir() + "/" + ao.getActionId() + ".json"; logger.info("writing config to:" + fileName + " remote: " + remoteFileName); // build a chef request Map<String, Object> chefRequest = assembleRequest(ao); String appName = (String) chefRequest.get("app_name"); // extra ' - ' for pattern matching - daq InductorLogSink will parse // this and insert into log store // see https://github.com/oneops/daq/wiki/schema for more info String logKey = ao.getActionId() + ":" + ao.getCi().getCiId() + " - "; logger.info(logKey + " Inductor: " + config.getIpAddr()); ao.getSearchTags().put("inductor", config.getIpAddr()); // assume failed; gets set to COMPLETE at the end ao.setActionState(OpsActionState.failed); String cookbookPath = getCookbookPath(ao.getCi().getCiClassName()); logger.info("cookbookPath: " + cookbookPath); try { // write the request to a .json file //Get the file reference writeChefRequestToFile(fileName, chefRequest); // sync cookbook and chef json request to remote site String host = getActionOrderHost(ao, logKey); String user = ONEOPS_USER; // run local when no managed via if (host == null || host.isEmpty()) { runLocalActionOrder(processRunner, ao, appName, logKey, fileName, cookbookPath); removeFile(fileName); return; } String keyFile = ""; try { keyFile = writePrivateKey(ao); } catch (KeyNotFoundException e) { logger.error(e.getMessage()); return; } String port = "22"; if (host.contains(":")) { String[] parts = host.split(":"); host = parts[0]; port = parts[1]; } String baseDir = config.getCircuitDir().replace("packer", cookbookPath); String components = baseDir + "/components"; String destination = "/home/" + user + "/" + cookbookPath; String[] rsyncCmdLineWithKey = rsyncCmdLine.clone(); rsyncCmdLineWithKey[4] += "-p " + port + " -qi " + keyFile; // always sync base cookbooks/modules String[] cmdLine = (String[]) ArrayUtils.addAll(rsyncCmdLineWithKey, new String[] { components, user + "@" + host + ":" + destination }); logger.info(logKey + " ### SYNC BASE: " + components); ExecutionContext ctx = new ExecutionContext(ao, cmdLine, logKey, host, keyFile, retryCount); boolean rsynchFailed = rsynch(ctx); if (rsynchFailed) return; // rsync exec-order shared components = config.getCircuitDir().replace("packer", "shared/"); destination = "/home/" + user + "/shared/"; cmdLine = (String[]) ArrayUtils.addAll(rsyncCmdLineWithKey, new String[] { components, user + "@" + host + ":" + destination }); //add new command in the context ctx.setCmd(cmdLine); logger.info(logKey + " ### SYNC SHARED: " + components); rsynchFailed = rsynch(ctx); if (rsynchFailed) return; // put actionorder cmdLine = (String[]) ArrayUtils.addAll(rsyncCmdLineWithKey, new String[] { fileName, user + "@" + host + ":" + remoteFileName }); //add new command in the context ctx.setCmd(cmdLine); logger.info(logKey + " ### SYNC: " + remoteFileName); rsynchFailed = rsynch(ctx); if (rsynchFailed) return; String debugFlag = getDebugFlag(ao); // run the chef command String remoteCmd = "sudo shared/exec-order.rb " + ao.getCi().getImpl() + " " + remoteFileName + " " + cookbookPath + " " + debugFlag; String[] cmd = null; cmd = (String[]) ArrayUtils.addAll(sshCmdLine, new String[] { keyFile, "-p " + port, user + "@" + host, remoteCmd }); logger.info(logKey + " ### EXEC: " + user + "@" + host + " " + remoteCmd); if (isNotaTestHost(host)) { ProcessResult result = processRunner.executeProcessRetry(cmd, logKey); // set the result status if (result.getResultCode() != 0) { logger.debug(logKey + "setting to failed - got non-zero exitStatus from remote chef"); return; } // compute resultCi gets populated on compute add (down further) // and is already there if (!appName.equalsIgnoreCase(InductorConstants.COMPUTE)) { setResultCi(result, ao); } } ao.setActionState(OpsActionState.complete); removeFile(ao, keyFile); } catch (IOException e) { logger.error(e); e.printStackTrace(); } if (!isDebugEnabled(ao)) removeFile(fileName); }