private static void addElement( List<String> lines, Patch patch, Map<String, RevFeatureType> featureTypes) throws IOException { String[] headerTokens = lines.get(0).split("\t"); if (headerTokens.length == 4 || headerTokens.length == 3) { // feature or feature type // modified // modification if (lines.size() == 1) { // feature type FeatureTypeDiff diff = new FeatureTypeDiff( headerTokens[0], ObjectId.valueOf(headerTokens[1]), ObjectId.valueOf(headerTokens[2])); patch.addAlteredTree(diff); } else { // feature String element = Joiner.on("\n").join(lines.subList(1, lines.size())); ByteArrayInputStream stream; stream = new ByteArrayInputStream(element.getBytes(Charsets.UTF_8)); String operation = headerTokens[0].trim(); if (operation.equals("M")) { String fullPath = headerTokens[1].trim(); String oldMetadataId = headerTokens[2].trim(); String newMetadataId = headerTokens[3].trim(); RevFeatureType newRevFeatureType = featureTypes.get(newMetadataId); RevFeatureType oldRevFeatureType = featureTypes.get(oldMetadataId); Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap(); for (int i = 1; i < lines.size(); i++) { addDifference(lines.get(i), map, oldRevFeatureType, newRevFeatureType); } FeatureDiff featureDiff = new FeatureDiff(fullPath, map, oldRevFeatureType, newRevFeatureType); patch.addModifiedFeature(featureDiff); } else if (operation.equals("A") || operation.equals("R")) { String fullPath = headerTokens[1].trim(); String featureTypeId = headerTokens[2].trim(); RevFeatureType revFeatureType; revFeatureType = featureTypes.get(featureTypeId); FeatureBuilder featureBuilder = new FeatureBuilder(revFeatureType); RevFeature revFeature = (RevFeature) serializer.read(null, stream); Feature feature = featureBuilder.build(NodeRef.nodeFromPath(fullPath), revFeature); if (operation.equals("R")) { patch.addRemovedFeature(fullPath, feature, revFeatureType); } else { patch.addAddedFeature(fullPath, feature, revFeatureType); } } else { throw new IllegalArgumentException("Wrong patch content: " + lines.get(0)); } } } else if (headerTokens.length == 1) { // feature type definition String element = Joiner.on("\n").join(lines); ByteArrayInputStream stream = new ByteArrayInputStream(element.getBytes(Charsets.UTF_8)); String[] tokens = lines.get(1).split("\t"); RevFeatureType featureType = (RevFeatureType) serializer.read(null, stream); featureTypes.put(featureType.getId().toString(), featureType); } else { throw new IllegalArgumentException("Wrong patch content: " + lines.get(0)); } }
/** * Creates a patch object to apply on a GeoGig working tree * * @param reader the read from where to read the patch description * @return a Patch */ public static Patch read(BufferedReader reader) { Preconditions.checkNotNull(reader); Patch patch = new Patch(); List<String> subset = Lists.newArrayList(); Map<String, RevFeatureType> featureTypes = Maps.newHashMap(); try { String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.isEmpty() && !subset.isEmpty()) { addElement(subset, patch, featureTypes); subset.clear(); } else if (!line.isEmpty()) { subset.add(line); } } if (!subset.isEmpty()) { addElement(subset, patch, featureTypes); } Set<Entry<String, RevFeatureType>> entries = featureTypes.entrySet(); for (Iterator<Entry<String, RevFeatureType>> iterator = entries.iterator(); iterator.hasNext(); ) { Entry<String, RevFeatureType> entry = iterator.next(); patch.addFeatureType(entry.getValue()); } return patch; } catch (IOException e) { throw new IllegalArgumentException("Can't read patch: " + e.getMessage()); } }
public static void write(Writer w, Patch patch) throws IOException { StringBuilder sb = new StringBuilder(); List<RevFeatureType> featureTypes = patch.getFeatureTypes(); for (RevFeatureType featureType : featureTypes) { ByteArrayOutputStream output = new ByteArrayOutputStream(); serializer.write(featureType, output); sb.append(output.toString()); sb.append('\n'); } for (FeatureInfo feature : patch.getAddedFeatures()) { String path = feature.getPath(); sb.append("A\t" + path + "\t" + feature.getFeatureType().getId() + "\n"); ByteArrayOutputStream output = new ByteArrayOutputStream(); RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature()); try { serializer.write(revFeature, output); } catch (IOException e) { } sb.append(output.toString()); sb.append('\n'); } for (FeatureInfo feature : patch.getRemovedFeatures()) { String path = feature.getPath(); sb.append("R\t" + path + "\t" + feature.getFeatureType().getId() + "\n"); ByteArrayOutputStream output = new ByteArrayOutputStream(); RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature()); try { serializer.write(revFeature, output); } catch (IOException e) { } sb.append(output.toString()); sb.append('\n'); } for (FeatureDiff diff : patch.getModifiedFeatures()) { sb.append( "M\t" + diff.getPath() + "\t" + diff.getOldFeatureType().getId().toString() + "\t" + diff.getNewFeatureType().getId().toString() + "\n"); sb.append(diff.asText() + "\n"); } for (FeatureTypeDiff diff : patch.getAlteredTrees()) { sb.append(diff.toString() + "\n"); } w.write(sb.toString()); w.flush(); }
public XSSchemaSet getResult() throws SAXException { // run all the patchers for (Patch patcher : patchers) patcher.run(); patchers.clear(); // build the element substitutability map Iterator itr = schemaSet.iterateElementDecls(); while (itr.hasNext()) ((ElementDecl) itr.next()).updateSubstitutabilityMap(); // run all the error checkers for (Patch patcher : errorCheckers) patcher.run(); errorCheckers.clear(); if (hadError) return null; else return schemaSet; }
public Patch[] extractPatch(Patch p) { // get all bytes from the (64 * ((32*pads)+settings)) + chain + system byte[] msgs = p.getByteArray(); // create a Patch[] pa to hold the created Patches (2*Single and 64*Bank) Patch[] pa = new Patch[66]; // do 64 times this: for (int i = 0; i < NR_OF_PATCHBANKS; i++) { // create a new byte array for a CompletePatch byte[] ptchbnk = new byte[PATCHBANKSIZE]; // copy the current 915 bytes to this byte array System.arraycopy(msgs, i * PATCHBANKSIZE, ptchbnk, 0, PATCHBANKSIZE); // create a new CompletePatch with these bytes and put it in pa at the current position pa[i] = new Patch(ptchbnk, patch2Driver); // increase i with 1 or go on if i is already 63 } // all CompletePatches are created // now create the chain patch byte array chn byte[] chn = new byte[CHAINSIZE]; // copy the chain bytes into chn System.arraycopy(msgs, NR_OF_PATCHBANKS * PATCHBANKSIZE, chn, 0, CHAINSIZE); // create a new chain patch with these bytes and put it in the patcharray pa[64] = new Patch(chn, chainDriver); // now create the system byte array sstm byte[] sstm = new byte[SYSTEMSIZE]; // copy the system bytes into sstm System.arraycopy(msgs, (NR_OF_PATCHBANKS * PATCHBANKSIZE) + CHAINSIZE, sstm, 0, SYSTEMSIZE); // create a new system patch with these bytes and put it in the patcharray pa[65] = new Patch(sstm, systemDriver); // return the full array of (64*CompletePatch)+Chain+System return pa; }
@Override protected boolean build() { for (int i = 0; i < 5; i++) { int top = Random.IntRange(2, ROOM_TOP - 1); int bottom = Random.IntRange(ROOM_BOTTOM + 1, 22); Painter.fill(this, 2 + i * 4, top, 4, bottom - top + 1, Terrain.EMPTY); if (i == 2) { exit = (i * 4 + 3) + (top - 1) * WIDTH; } for (int j = 0; j < 4; j++) { if (Random.Int(2) == 0) { int y = Random.IntRange(top + 1, bottom - 1); map[i * 4 + j + y * WIDTH] = map[i * 4 + j + 1 + y * WIDTH] = map[i * 4 + j - 1 + y * WIDTH] = Terrain.WALL_DECO; } } } map[exit] = Terrain.LOCKED_EXIT; Painter.fill( this, ROOM_LEFT - 1, ROOM_TOP - 1, ROOM_RIGHT - ROOM_LEFT + 3, ROOM_BOTTOM - ROOM_TOP + 3, Terrain.WALL); Painter.fill( this, ROOM_LEFT, ROOM_TOP, ROOM_RIGHT - ROOM_LEFT + 1, ROOM_BOTTOM - ROOM_TOP + 1, Terrain.EMPTY); entrance = Random.Int(ROOM_LEFT + 1, ROOM_RIGHT - 1) + Random.Int(ROOM_TOP + 1, ROOM_BOTTOM - 1) * WIDTH; map[entrance] = Terrain.ENTRANCE; boolean[] patch = Patch.generate(0.45f, 6); for (int i = 0; i < LENGTH; i++) { if (map[i] == Terrain.EMPTY && patch[i]) { map[i] = Terrain.WATER; } } return true; }
public byte[] create() throws IOException { List<Patch> patches = this.project.getIncludedPatches(); int length = 0; length += HEADER_LENGTH; int indicesLength = Offset.SIZE * patches.size(); length += indicesLength; byte[] metadataBytes = project.getAuthor().getBytes("UTF-8"); length += metadataBytes.length; length += (Offset.SIZE * patches.size()); for (Patch patch : patches) { length += patch.getValue().getBytesLength(); } byte[] mod = new byte[length]; writeBytes(mod, new byte[] {(byte) 0xFF, 0x50, 0x54, 0x50, 0x00, (byte) patches.size()}, 0); writeBytes(mod, metadataBytes, HEADER_LENGTH + indicesLength); int patchStart = HEADER_LENGTH + indicesLength + metadataBytes.length; for (int i = 0; i < patches.size(); i++) { Patch patch = patches.get(i); writeBytes(mod, Value.intToByteArray(patchStart), HEADER_LENGTH + Offset.SIZE * i); int offsetBytesLength = writeBytes(mod, patch.getOffset().getBytes(), patchStart); int valueBytesLength = writeBytes(mod, patch.getValue().getBytes(), patchStart + Offset.SIZE); patchStart += (offsetBytesLength + valueBytesLength); } return mod; }
@Test( groups = "integration", dependsOnMethods = {"testGetCreditCard"}) public void testUpdateCreditCard() throws PayPalRESTException { logger.info("**** Update CreditCard ****"); logger.info("Generated Access Token = " + TokenHolder.accessToken); // set up patch request Patch patch = new Patch(); patch.setOp("replace"); patch.setPath("/expire_year"); patch.setValue(new Integer(2020)); List<Patch> patchRequest = new ArrayList<Patch>(); patchRequest.add(patch); // send patch request CreditCard creditCard = new CreditCard(); creditCard.setId(createdCreditCardId); CreditCard retrievedCreditCard = creditCard.update(TokenHolder.accessToken, patchRequest); logger.info("Request = " + CreditCard.getLastRequest()); logger.info("Response = " + CreditCard.getLastResponse()); Assert.assertEquals(2020, retrievedCreditCard.getExpireYear()); }
// HACK? public void setPatch(Patch inPatch) { // update the "model" this.bank.setPatch(inPatch); // give the user some nice visual feedback that the window has changed // (most likely Mac only) setBankModified(true); // update the *other* "model" - sigh int patchNumber = inPatch.getPatchNumber(); int row = patchNumber / kTableColumnCount; int col = patchNumber % kTableColumnCount; this.table.setValueAt(this.bank.getPatch(patchNumber), row, col); }
public void actionPerformed(ActionEvent inEvent) { String actionCommand = inEvent.getActionCommand(); if (actionCommand.equalsIgnoreCase("KEYBOARD_CLOSE_ACTION")) { setVisible(false); if (!isVisible()) { dispose(); } } else if (actionCommand.equalsIgnoreCase("SAVE") || actionCommand.equalsIgnoreCase("SAVE_AS")) { boolean askForFile = false; if (actionCommand.equalsIgnoreCase("SAVE_AS")) { askForFile = true; } else { if (this.file == null) { askForFile = true; } } saveBank(askForFile); } else if (actionCommand.equalsIgnoreCase("SEND_BANK")) { int response = ControlWindow.getInstance() .showConfirmDialog("Transmit", "OK to overwrite bank in Prophet?"); if (response == JOptionPane.YES_OPTION) { try { ControlWindow.getInstance().sendMidiMessage(Machine.makeBankDumpMessage(this.bank)); // this bank is now in the Prophet setBankInProphet(true); } catch (Exception inException) { ControlWindow.getInstance().showErrorDialog("Error", inException); } } } else if (actionCommand.equalsIgnoreCase("SEND_PATCH")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to send."); } else { int patchNumber = (row * kTableColumnCount) + column; Patch patch = this.bank.getPatch(patchNumber); StringBuffer buffer = new StringBuffer(); buffer.append("OK to overwrite patch "); buffer.append(patch.getPatchNumber()); buffer.append(" in Prophet?"); int response = ControlWindow.getInstance().showConfirmDialog("Transmit", buffer.toString()); if (response == JOptionPane.YES_OPTION) { try { ControlWindow.getInstance().sendMidiMessage(Machine.makePatchDumpMessage(patch)); } catch (Exception inException) { ControlWindow.getInstance().showErrorDialog("Error", inException); } } } } else if (actionCommand.equalsIgnoreCase("VARY")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to vary."); } else { int patchNumber = (row * kTableColumnCount) + column; Patch patch = this.bank.getPatchCopy(patchNumber); VaryWindow varyWindow = new VaryWindow(patch); varyWindow.setLocationRelativeTo(null); varyWindow.setVisible(true); } } else if (actionCommand.equalsIgnoreCase("COPY")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to copy."); } else { int patchNumber = (row * kTableColumnCount) + column; Patch patch = this.bank.getPatchCopy(patchNumber); TransferablePatch transferable = new TransferablePatch(patch); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, this); } } else if (actionCommand.equalsIgnoreCase("PASTE")) { int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to paste."); } else { int patchNumber = (row * kTableColumnCount) + column; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferable = clipboard.getContents(this); if (transferable != null) { DataFlavor flavour = new DataFlavor(Patch.class, "Prophet VS Patch"); try { Object data = transferable.getTransferData(flavour); if (data != null && data instanceof Patch) { Patch patch = (Patch) data; // copy the patch! // it might get pasted twice and this is only a reference Patch copy = new Patch(patch); // override the patch number in the patch // so it goes in the right place copy.setPatchNumber(patchNumber); setPatch(copy); } } catch (Exception inException) { System.err.println(inException); } } } } else if (actionCommand.equalsIgnoreCase("SWAP_PASTE")) { // this is a nondestructive paste which swaps the selection & paste buffer int row = this.table.getSelectedRow(); int column = this.table.getSelectedColumn(); if (row == -1 || column == -1) { ControlWindow.getInstance() .showErrorDialog("Error", "Please select a patch location to swap paste."); } else { int patchNumber = (row * kTableColumnCount) + column; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferable = clipboard.getContents(this); if (transferable != null) { DataFlavor flavour = new DataFlavor(Patch.class, "Prophet VS Patch"); try { Object data = transferable.getTransferData(flavour); if (data != null && data instanceof Patch) { Patch pastePatch = (Patch) data; // ok now copy the selection into the clipboard Patch copyPatch = this.bank.getPatchCopy(patchNumber); transferable = new TransferablePatch(copyPatch); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, this); // and now paste the saved patch into place // override the patch number in the patch // so it goes in the right place pastePatch.setPatchNumber(patchNumber); setPatch(pastePatch); } } catch (Exception inException) { System.err.println(inException); } } } } }
protected boolean[] grass() { return Patch.generate(this, feeling == Feeling.GRASS ? 0.55f : 0.30f, 3); }
protected boolean[] water() { return Patch.generate(this, feeling == Feeling.WATER ? 0.55f : 0.40f, 6); }
protected void addPatch(Patch patch) { patchs.add(patch); patch.setListener(this); }
protected boolean[] grass() { return Patch.generate(this, feeling == Feeling.GRASS ? 0.60f : 0.40f, 4); }
protected boolean[] water() { return Patch.generate(this, feeling == Feeling.WATER ? 0.60f : 0.45f, 5); }
protected boolean[] water() { return Patch.generate(feeling == Feeling.CHASM ? 0.60f : 0.45f, 6); }
public static void main(String[] args) { int anzVersuche = 100000; Patch p = new Patch(); Karte[] karten = new Karte[52]; Karte[] hand = new Karte[5]; Methoden m = new Methoden(); JDBC j = new JDBC(); int pz = 0, dpz = 0, fhz = 0, poz = 0, flz = 0, sz = 0, sfz = 0, rfz = 0, dz = 0; for (int i = 0; i < anzVersuche; i++) { karten = p.kartenErzeugen(); hand = p.handSuchen(karten); switch (m.ParrDrillingPoker(hand)) { // paar case (1): pz++; break; // zwei paare case (2): dpz++; break; // drilling case (3): dz++; break; // poker case (4): poz++; break; // fullhouse case (5): fhz++; break; } if ((m.IstFlush(hand) == true) && (m.Straße(hand) == false)) { flz++; } if ((m.IstFlush(hand) == true) && (m.Straße(hand) == true)) { sfz++; } if ((m.IstFlush(hand) == false) && (m.Straße(hand) == true)) { sz++; } if ((m.Royal(hand) == true) && (m.IstFlush(hand) == true)) { rfz++; } } paar = pz; doppelpaar = dpz; drilling = dz; poker = poz; fullhouse = fhz; flush = flz; straße = sz; straightFlush = sfz; roylflush = rfz; highkart = anzVersuche - paar - doppelpaar - drilling - poker - fullhouse - flush - straße - straightFlush - roylflush; j.dadenbankErzeugen(); j.tableErzeugen(); j.insertTable(); // j.drop(); j.select(); }