private List<Line> createStructure(GUIText text) { char[] chars = text.getTextString().toCharArray(); List<Line> lines = new ArrayList<Line>(); Line currentLine = new Line(metaData.getSpaceWidth(), text.getFontSize(), text.getMaxLineSize()); Word currentWord = new Word(text.getFontSize()); for (char c : chars) { int ascii = (int) c; if (ascii == SPACE_ASCII) { boolean added = currentLine.attemptToAddWord(currentWord); if (!added) { lines.add(currentLine); currentLine = new Line(metaData.getSpaceWidth(), text.getFontSize(), text.getMaxLineSize()); currentLine.attemptToAddWord(currentWord); } currentWord = new Word(text.getFontSize()); continue; } Character character = metaData.getCharacter(ascii); currentWord.addCharacter(character); } completeStructure(lines, currentLine, currentWord, text); return lines; }
public String getPodcastEmailSummary() { StringBuilder sb = new StringBuilder(); if (currentPodcastInPlayer < metaHolder.getSize()) { MetaFile mf = currentMeta(); if (mf != null) { sb.append("\nWanted to let you know about this podcast:\n\n"); sb.append("\nTitle: " + mf.getTitle()); String searchName = mf.getFeedName(); sb.append("\nFeed Title: " + searchName); List<Subscription> subs = getSubscriptions(); for (Subscription sub : subs) { if (sub.name.equals(searchName)) { sb.append("\nFeed URL: " + sub.url); break; } } if (mf.getUrl() != null) { sb.append("\nPodcast URL: " + mf.getUrl()); } } } sb.append("\n\n\n"); sb.append("This email sent from " + CarCastApplication.getAppTitle() + "."); return sb.toString(); }
/** * Synchronizes two {@link MetaFile}. If <code>matcher</code> is not <code>null</code> then <code> * MetaFile</code> tree is sifted before synchronization using <code>matcher</code>. * * @param first first <code>MetaFile</code>. * @param second second <code>MetaFile</code>. * @param matcher matcher to be used to filter files taking part in synchronization. * @return synchronization patch contained information about changes or <code>null</code> if there * are no differences. * @throws NullPointerException if both <code>MetaFiles</code> are <code>null</code>. * @throws SynchronizationException * @see SyncPatch */ public static SyncPatch sync( MetaFile first, MetaFile second, FileMatcher matcher, String hashFunc) throws NullPointerException, SynchronizationException, IOException { if ((first == null) && (second == null)) { throw new NullPointerException(); } if (matcher != null) { FileSieve sieve = new FileSieve(matcher); first = first != null ? sieve.sift(first) : null; second = second != null ? sieve.sift(second) : null; } if (first == null) { return new SyncPatch(second, null); } if (second == null) { return new SyncPatch(first, null); } if (first.isFile() && !second.isFile() || !first.isFile() && second.isFile()) { throw new SynchronizationException("Synchronization impossible between file and directory"); } return recurSync(first, second, hashFunc); }
private static MetaFile getMaster(MetaFile first, MetaFile second) throws SynchronizationException { if (first.getTime() > second.getTime()) { return first; } else if (first.getTime() < second.getTime()) { return second; } else { throw new SynchronizationException("The same time for conflicted files"); } }
private static SyncPatch diffSync(MetaFile fileOwner, MetaFile other, MetaFile file) throws SynchronizationException { if (fileOwner.getTime() > other.getTime()) { return new SyncPatch(file, null); } else if (fileOwner.getTime() < other.getTime()) { return new SyncPatch(null, file.getName()); } else { throw new SynchronizationException("The same time for conflicted directories"); } }
private TextMeshData createQuadVertices(GUIText text, List<Line> lines) { text.setNumberOfLines(lines.size()); double curserX = 0f; double curserY = 0f; List<Float> vertices = new ArrayList<Float>(); List<Float> textureCoords = new ArrayList<Float>(); for (Line line : lines) { if (text.isCentered()) { curserX = (line.getMaxLength() - line.getLineLength()) / 2; } for (Word word : line.getWords()) { for (Character letter : word.getCharacters()) { addVerticesForCharacter(curserX, curserY, letter, text.getFontSize(), vertices); addTexCoords( textureCoords, letter.getxTextureCoord(), letter.getyTextureCoord(), letter.getXMaxTextureCoord(), letter.getYMaxTextureCoord()); curserX += letter.getxAdvance() * text.getFontSize(); } curserX += metaData.getSpaceWidth() * text.getFontSize(); } curserX = 0; curserY += LINE_HEIGHT * text.getFontSize(); } return new TextMeshData(listToArray(vertices), listToArray(textureCoords)); }
public void setValue(Object value) throws MetaParameterFormatException { if (supportsValue(value)) { super.setValue(value); } else { throw new MetaParameterFormatException( "Cannot assign object of type " + value.getClass() + " to a MetaDocument parameter."); } }
private void completeStructure( List<Line> lines, Line currentLine, Word currentWord, GUIText text) { boolean added = currentLine.attemptToAddWord(currentWord); if (!added) { lines.add(currentLine); currentLine = new Line(metaData.getSpaceWidth(), text.getFontSize(), text.getMaxLineSize()); currentLine.attemptToAddWord(currentWord); } lines.add(currentLine); }
// private stuff // ============================================================================================= private static SyncPatch recurSync(MetaFile first, MetaFile second, String hashFunc) throws SynchronizationException, IOException { if (first.isFile()) { if (first.getSize() == second.getSize()) { InputStream fis = first.getInputStream(); InputStream sis = second.getInputStream(); if (hashFunc == null) { if (FileUtils.isEqual(fis, sis)) { return null; } } else { byte[] hash1 = first.getHash(hashFunc); byte[] hash2 = second.getHash(hashFunc); if ((hash1 == null) && (hash2 == null) || ((hash1 == null) || (hash2 == null)) && (HashManager.getHashManager().getCalculator(hashFunc) == null)) { if (FileUtils.isEqual(fis, sis)) { return null; } } if (hash1 == null) { hash1 = HashManager.getHashManager().getCalculator(hashFunc).calculate(fis); } if (hash2 == null) { hash2 = HashManager.getHashManager().getCalculator(hashFunc).calculate(sis); } if (Arrays.equals(hash1, hash2)) { return null; } } } if (first.getTime() > second.getTime()) { return new SyncPatch(first, second.getName()); } else if (first.getTime() < second.getTime()) { return new SyncPatch(second, first.getName()); } else { throw new SynchronizationException("The same time for conflicted files"); } } else { // directories Set<SyncPatch> syncs = new HashSet<>(); boolean same = true; Set<String> remained = new HashSet<>(second.getFiles().keySet()); for (String name : first.getFiles().keySet()) { if (remained.remove(name)) { // if file exist in second directory MetaFile fc = first.getFiles().get(name); MetaFile sc = second.getFiles().get(name); // if the one is file and the other is directory if (fc.isFile() && !sc.isFile() || !fc.isFile() && sc.isFile()) { same = false; syncs.add(new SyncPatch(getMaster(fc, sc), null)); } else { // both files or directories exist SyncPatch si = recurSync(fc, sc, hashFunc); if (si != null) { syncs.add(si); } } } else { // file exist only in first directory same = false; syncs.add(diffSync(first, second, first.getFiles().get(name))); } } if (!remained.isEmpty()) { same = false; for (String name : remained) { syncs.add(diffSync(second, first, second.getFiles().get(name))); } } if (same) { if (syncs.isEmpty()) { return null; } else { return new SyncPatch(first, second.getName(), syncs); } } else { if (first.getTime() >= second.getTime()) { return new SyncPatch(first, second.getName(), syncs); } else { return new SyncPatch(second, first.getName(), syncs); } } } }