List of usage examples for java.util Collections binarySearch
@SuppressWarnings("unchecked") public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c)
From source file:com.zyk.launcher.AsyncTaskCallback.java
private void addAppsWithoutInvalidate(ArrayList<AppInfo> list) { // We add it in place, in alphabetical order int count = list.size(); for (int i = 0; i < count; ++i) { AppInfo info = list.get(i);//from w w w. j a va 2 s . c o m int index = Collections.binarySearch(mApps, info, LauncherModel.getAppNameComparator()); if (index < 0) { mApps.add(-(index + 1), info); } } }
From source file:com.android.launcher2.AsyncTaskCallback.java
private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { // We add it in place, in alphabetical order int count = list.size(); for (int i = 0; i < count; ++i) { ApplicationInfo info = list.get(i); int index = Collections.binarySearch(mApps, info, LauncherModel.getAppNameComparator()); if (index < 0) { mApps.add(-(index + 1), info); }//from www .ja va2 s . com } }
From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java
private void addAppsWithoutInvalidate(ArrayList<AppInfo> list) { // We add it in place, in alphabetical order int count = list.size(); for (int i = 0; i < count; ++i) { AppInfo info = list.get(i);/*from w w w . j ava 2s . com*/ int index = Collections.binarySearch(mApps, info, getComparatorForSortMode()); if (index < 0) { mApps.add(-(index + 1), info); } } }
From source file:com.microsoft.tfs.core.clients.versioncontrol.internal.localworkspace.LocalDataAccessLayer.java
public static GetOperation[] undoPendingChanges(final Workspace workspace, final LocalWorkspaceProperties wp, final WorkspaceVersionTable lv, final LocalPendingChangesTable pc, final Iterable<LocalPendingChange> pendingChanges, final ChangeType selectiveUndo, final AtomicReference<Failure[]> failures, final AtomicBoolean onlineOperationRequired) { // Our collection of GetOperations that we will return. There will be // one GetOperation for every undone pending change and for every item // affected by an undone recursive pending change. The dictionary is // keyed by (SourceServerItem, IsCommitted) just like the local version // table./*from w w w .ja va 2s .c o m*/ final Map<ServerItemIsCommittedTuple, GetOperation> getOps = new HashMap<ServerItemIsCommittedTuple, GetOperation>(); // The UndoneChange structure encapsulates a pending change and its // destination server item in pending space (RevertToServerItem). final List<UndoneChange> undoneChanges = new ArrayList<UndoneChange>(); // A hash table where we can check quickly to see if a server path has a // pending change being undone (by target server item) final Map<String, UndoneChange> undoneChangesMap = new HashMap<String, UndoneChange>(); // When a recursive pending change is undone, there may be affected // child pending changes that are not undone. We store in this queue a // list of updates that need to be processed (atomically!). final List<RenamedPendingChange> renamedPendingChanges = new ArrayList<RenamedPendingChange>(); // When undoing a rename, we need to make sure that the current target // server item isn't at or below a workspace mapping. List<String> workingFolderServerItems = null; // Failures generated by undo final List<Failure> failureList = new ArrayList<Failure>(); int undoRenameCount = 0; // The RevertToServerItem starts out with the CommittedServerItem of the // pending change. for (final LocalPendingChange pcEntry : pendingChanges) { final ChangeType changeType = pcEntry.getChangeType().retain(selectiveUndo); final UndoneChange undoneChange = new UndoneChange(pcEntry, pcEntry.getServerItem(), changeType); // Add this item to our data structures undoneChanges.add(undoneChange); undoneChangesMap.put(undoneChange.getPendingChange().getTargetServerItem(), undoneChange); // We can't undo a checkin lock without going to the server. If we // match one, the entire undo operation needs to go to the server. if (undoneChange.isUndoingLock() || (undoneChange.isUndoingRename() && undoneChange.getPendingChange().isLock())) { return sendToServer(failures, onlineOperationRequired); } // Count how many renames we are undoing and make sure the rename is // not at or under a workspace mapping if (undoneChange.isUndoingRename()) { undoRenameCount++; // The first rename will initialize our list of working folders // and sort it if (null == workingFolderServerItems) { final WorkingFolder[] workingFolders = wp.getWorkingFolders(); workingFolderServerItems = new ArrayList<String>(workingFolders.length); for (final WorkingFolder workingFolder : workingFolders) { workingFolderServerItems.add(workingFolder.getServerItem()); } Collections.sort(workingFolderServerItems, new Comparator<String>() { @Override public int compare(final String x, final String y) { return ServerPath.compareTopDown(x, y); } }); } // Check to see if undoing this rename would modify the // workspace mappings final int index = Collections.binarySearch(workingFolderServerItems, pcEntry.getTargetServerItem(), ServerPath.TOP_DOWN_COMPARATOR); if (index >= 0 || (~index < workingFolderServerItems.size() && ServerPath .isChild(pcEntry.getTargetServerItem(), workingFolderServerItems.get(~index)))) { return sendToServer(failures, onlineOperationRequired); } } } // Sort by target server item descending Collections.sort(undoneChanges, new Comparator<UndoneChange>() { @Override public int compare(final UndoneChange x, final UndoneChange y) { return ServerPath.compareTopDown(y.getPendingChange().getTargetServerItem(), x.getPendingChange().getTargetServerItem()); } }); // Pass 1: Calculate the RevertToServerItem for each undone pending // change. if (undoRenameCount > 0) { // We should come up with a faster way of figuring out whether the // user is undoing all renames in the workspace. int totalRenameCount = 0; final List<LocalPendingChange> remainingFolderRenames = new ArrayList<LocalPendingChange>(); for (final LocalPendingChange pcEntry : pc.queryByTargetServerItem(ServerPath.ROOT, RecursionType.FULL, null)) { if (pcEntry.isRename()) { totalRenameCount++; if (pcEntry.isRecursiveChange()) { final UndoneChange undoneChange = undoneChangesMap.get(pcEntry.getTargetServerItem()); if (undoneChange == null || !undoneChange.isUndoingRename()) { remainingFolderRenames.add(pcEntry); } } } } if (undoneChanges.size() != pc.getCount()) { // We are not undoing all the changes in the workspace, so we // need to make sure that we do not have any pending changes // that are not being undone that have a target server item that // is at or underneath the source of a pending rename. Otherwise // there will be a collision when we undo the rename and it goes // back to the source. for (final UndoneChange undoneChange : undoneChanges) { final LocalPendingChange lpc = undoneChange.getPendingChange(); // TODO: What kinds of bad situations can we end up with // when you have a merge of a deleted item under a rename -- // a pending merge on a deleted item if (0 == lpc.getDeletionID() && lpc.isCommitted() && undoneChange.isUndoingRename() && !ServerPath.equals(lpc.getCommittedServerItem(), lpc.getTargetServerItem())) { // Check to see if there is a namespace-additive pending // change blocking this item from reverting to its // committed server item for (final LocalPendingChange pcEntry : pc.queryByTargetServerItem( undoneChange.getPendingChange().getCommittedServerItem(), RecursionType.FULL, null)) { if (pcEntry.isAdd() || pcEntry.isBranch() || pcEntry.isRename()) { final UndoneChange collision = undoneChangesMap.get(pcEntry.getTargetServerItem()); if (collision == null || !collision.getUndoneChangeType() .containsAny(ChangeType.ADD_BRANCH_OR_RENAME)) { final String format = Messages .getString("LocalDataAccessLayer.PartialRenameConflictExceptionFormat"); //$NON-NLS-1$ throw new PartialRenameConflictException( MessageFormat.format(format, pcEntry.getTargetServerItem())); } } } } } } if (undoRenameCount != totalRenameCount) { // Only some of the renames in the workspace are being undone // Find a pending folder rename (PARENT\a->PARENT\b) that is // NOT being undone which is affecting a pending folder rename // (PARENT\A\SUB -> OUTSIDE) that IS being undone Where the // depth of the target name for the rename being undone // (OUTSIDE) is less than the depth of the target name that is // NOT being undone (PARENT\B). for (final LocalPendingChange remainingFolderRename : remainingFolderRenames) { for (final LocalPendingChange pcEntry : pc.queryByCommittedServerItem( remainingFolderRename.getCommittedServerItem(), RecursionType.FULL, null)) { if (pcEntry.isRename() && pcEntry.isRecursiveChange()) { final UndoneChange undoneChange = undoneChangesMap.get(pcEntry.getTargetServerItem()); final int targetFolderDepth = ServerPath.getFolderDepth(pcEntry.getTargetServerItem()); final int remainFolderDepth = ServerPath .getFolderDepth(remainingFolderRename.getTargetServerItem()); if (undoneChange != null && undoneChange.isUndoingRename() && targetFolderDepth < remainFolderDepth) { final String format = Messages .getString("LocalDataAccessLayer.PartialRenameConflictExceptionFormat"); //$NON-NLS-1$ throw new PartialRenameConflictException( MessageFormat.format(format, pcEntry.getCommittedServerItem())); } } } } // Calculate new names for all namespace-changing pending // changes. // Map of key server item (current target server item) to the // data structure used for the name calculation. We'll use this // later to sub in the new names. final Map<String, RenameCalculationEntry> newNames = new HashMap<String, RenameCalculationEntry>(); // Our algorithm wants to walk the set of pending renames only. final List<RenameCalculationEntry> pendingRenamesOnly = new ArrayList<RenameCalculationEntry>( totalRenameCount); for (final UndoneChange undoneChange : undoneChanges) { final RenameCalculationEntry rcEntry = new RenameCalculationEntry( undoneChange.getPendingChange().getTargetServerItem(), undoneChange.getPendingChange().getServerItem(), undoneChange.getPendingChange(), undoneChange.isUndoingRename()); newNames.put(undoneChange.getPendingChange().getTargetServerItem(), rcEntry); if (undoneChange.getPendingChange().isRename()) { pendingRenamesOnly.add(rcEntry); } } for (final LocalPendingChange pcEntry : pc.queryByTargetServerItem(ServerPath.ROOT, RecursionType.FULL, null)) { if ((pcEntry.isRename() || pcEntry.isAdd() || pcEntry.isBranch()) && !undoneChangesMap.containsKey(pcEntry.getTargetServerItem())) { final RenameCalculationEntry rcEntry = new RenameCalculationEntry( pcEntry.getTargetServerItem(), pcEntry.getServerItem(), pcEntry, false); newNames.put(pcEntry.getTargetServerItem(), rcEntry); if (pcEntry.isRename()) { pendingRenamesOnly.add(rcEntry); } } } // Our algorithm wants to walk the set of pending renames only, // by source server item ascending. Collections.sort(pendingRenamesOnly, new Comparator<RenameCalculationEntry>() { @Override public int compare(final RenameCalculationEntry x, final RenameCalculationEntry y) { return ServerPath.compareTopDown(x.getPendingChange().getCommittedServerItem(), y.getPendingChange().getCommittedServerItem()); } }); for (final RenameCalculationEntry newName : pendingRenamesOnly) { // Capture the data from newName into local variables, since // we will be checking/editing values on the very same // instance of RenameCalculationEntry in our up coming // for each loops final String sourceServerItem = newName.getSourceServerItem(); final String targetServerItem = newName.getTargetServerItem(); if (!newName.isUndoingChange()) { for (final RenameCalculationEntry rcEntry : newNames.values()) { final String entrySourceServerItem = rcEntry.getSourceServerItem(); if (ServerPath.isChild(sourceServerItem, entrySourceServerItem)) { final String entryTargetServerItem = rcEntry.getTargetServerItem(); final String pendingTargetServerItem = rcEntry.getPendingChange() .getTargetServerItem(); if (!ServerPath.equals(entrySourceServerItem, entryTargetServerItem) || ServerPath.equals(pendingTargetServerItem, entrySourceServerItem)) { rcEntry.setSourceServerItem(targetServerItem + entrySourceServerItem.substring(sourceServerItem.length())); } } } } else { for (final RenameCalculationEntry rcEntry : newNames.values()) { final String entryTargetServerItem = rcEntry.getTargetServerItem(); if (ServerPath.isChild(targetServerItem, entryTargetServerItem)) { final String entrySourceServerItem = rcEntry.getSourceServerItem(); final String pendingTargetServerItem = rcEntry.getPendingChange() .getTargetServerItem(); if (!ServerPath.equals(entrySourceServerItem, entryTargetServerItem) || ServerPath.equals(pendingTargetServerItem, entrySourceServerItem)) { rcEntry.setTargetServerItem(sourceServerItem + entryTargetServerItem.substring(targetServerItem.length())); } } } } } // If there are duplicate TargetServerItem values in the set of // RenameCalculationEntry objects, that indicates we have a // collision and cannot perform the undo. Sort by target server // item so that duplicates will be adjacent. final RenameCalculationEntry[] rcEntries = newNames.values() .toArray(new RenameCalculationEntry[newNames.size()]); Arrays.sort(rcEntries, new Comparator<RenameCalculationEntry>() { @Override public int compare(final RenameCalculationEntry x, final RenameCalculationEntry y) { return ServerPath.compareTopDown(x.getTargetServerItem(), y.getTargetServerItem()); } }); // The loop is complicated because we need to exclude pending // renames on deleted items from consideration. int duplicateCheckIndex = -1; for (int i = 1; i < rcEntries.length; i++) { // Only allow rcEntries[duplicateCheckIndex] to point to a // pending change which meets our criteria if (rcEntries[i - 1].getPendingChange().getDeletionID() == 0 || !rcEntries[i - 1].getPendingChange().isRename()) { duplicateCheckIndex = i - 1; } // This pending change must also meet the criteria, we must // have something to compare it against, and the target // server items need to be the same. if (duplicateCheckIndex >= 0 && (rcEntries[i].getPendingChange().getDeletionID() == 0 || !rcEntries[i].getPendingChange().isRename()) && ServerPath.equals(rcEntries[i].getTargetServerItem(), rcEntries[duplicateCheckIndex].getTargetServerItem())) { throw new PartialRenameConflictException(MessageFormat.format( Messages.getString("LocalDataAccessLayer.PartialRenameConflictExceptionFormat"), //$NON-NLS-1$ , rcEntries[i].getTargetServerItem())); } } for (final UndoneChange undoneChange : undoneChanges) { final RenameCalculationEntry rcEntry = newNames .get(undoneChange.getPendingChange().getTargetServerItem()); if (rcEntry != null) { undoneChange.setRevertToServerItem(rcEntry.getTargetServerItem()); } } } else { // All renames in the workspace are being undone. for (final UndoneChange undoneChange : undoneChanges) { if (undoneChange.getPendingChange().isCommitted()) { // Committed changes have their revert to server item // already calculated. undoneChange .setRevertToServerItem(undoneChange.getPendingChange().getCommittedServerItem()); } else { // Find the closest rename that affects this uncommitted // item and unrename it. undoneChange.setRevertToServerItem(pc.getCommittedServerItemForTargetServerItem( undoneChange.getPendingChange().getTargetServerItem())); } } } } else { // Even though we are not undoing a rename, there could be a // parental rename. So set the revert to server item based upon // existing parental renames. for (final UndoneChange undoneChange : undoneChanges) { undoneChange.setRevertToServerItem(undoneChange.getPendingChange().getTargetServerItem()); } } // Pass 1: One GetOperation for every LocalPendingChange being undone for (final UndoneChange undoneChange : undoneChanges) { if (undoneChange.getRevertToServerItem().length() > VersionControlConstants.MAX_SERVER_PATH_SIZE) { throw createPathTooLongException(undoneChange.getRevertToServerItem()); } final LocalPendingChange pcEntry = undoneChange.getPendingChange(); final WorkspaceLocalItem lvEntry = lv.getByPendingChange(undoneChange.getPendingChange()); final GetOperation getOp = new GetOperation(); getOp.setTargetServerItem(undoneChange.getRevertToServerItem()); getOp.setSourceServerItem( pcEntry.isCommitted() ? pcEntry.getCommittedServerItem() : pcEntry.getTargetServerItem()); if (null != lvEntry && !lvEntry.isDeleted()) { getOp.setSourceLocalItem(lvEntry.getLocalItem()); // If we're undoing a pending add, mark the path as changed in // the scanner. This is because when the pending change is // undone, the item in question will not actually be touched on // disk. But we want to have it marked, so that we re-detect the // item as a candidate add. if (undoneChange.isUndoingAdd()) { workspace.getWorkspaceWatcher().markPathChanged(lvEntry.getLocalItem()); LocalWorkspaceTransaction.getCurrent().setRaisePendingChangeCandidatesChanged(true); } } if ((0 == pcEntry.getDeletionID() || undoneChange.getRemainingChangeType().contains(ChangeType.UNDELETE)) && !undoneChange.isUndoingBranch()) { final String targetLocalItem = WorkingFolder .getLocalItemForServerItem(undoneChange.getRevertToServerItem(), wp.getWorkingFolders()); if (null != lvEntry) { getOp.setTargetLocalItem(targetLocalItem); // We never want the client to delete adds -- even if the // target is cloaked. if (pcEntry.isAdd() && null == getOp.getTargetLocalItem()) { getOp.setTargetLocalItem(getOp.getSourceLocalItem()); } } else { // We don't have a local version entry for this pending // change, so we can't restore the content. getOp.setTargetLocalItem(null); if (null != targetLocalItem) { final String format = "OfflineUndoNoLocalVersionEntry"; //$NON-NLS-1$ failureList .add(new Failure(MessageFormat.format(format, undoneChange.getRevertToServerItem()), FailureCodes.BASELINE_UNAVAILABLE_EXCEPTION, SeverityType.WARNING, undoneChange.getRevertToServerItem())); } } if (null != getOp.getTargetLocalItem()) { getOp.setLocalVersionEntry(lv.getByLocalItem(getOp.getTargetLocalItem())); } } // This is the current encoding on the pending change -- we need the // committed encoding, which is on the local version entry if we // have one, but if we don't, we're in trouble and need to go to the // server. if (!pcEntry.getChangeType().contains(ChangeType.ENCODING)) { // If we aren't changing the encoding, then the local pending // change row's encoding is the encoding for the item. getOp.setEncoding(pcEntry.getEncoding()); } else if (null != lvEntry) { getOp.setEncoding(lvEntry.getEncoding()); } else { // We don't have the committed encoding for this item stored // locally. We need to process this undo operation on the // server. // TODO: Issue a warning and not download the change? The user // can go to the server and get it later, we don't want to // completely block them while they're offline return sendToServer(failures, onlineOperationRequired); } getOp.setChangeType(undoneChange.getUndoneChangeType()); // If we are undoing an uncommitted pending change then do not add // in parent recursive changetypes if (!undoneChange.isUndoingAdd() && !undoneChange.isUndoingBranch()) { ChangeType inheritedChangeType = ChangeType.NONE; // The ChangeType on the item being undone is equal to the // ChangeType on the item itself, plus the recursive ChangeType // on its parent pending changes which are also being undone. for (final LocalPendingChange parentPcEntry : pc .queryParentsOfTargetServerItem(pcEntry.getTargetServerItem())) { final UndoneChange checkChange = undoneChangesMap.get(parentPcEntry.getTargetServerItem()); if (!parentPcEntry.isRecursiveChange() || checkChange == null) { continue; } if (checkChange.getUndoneChangeType().contains(ChangeType.RENAME)) { inheritedChangeType = inheritedChangeType.combine(ChangeType.RENAME); } if (checkChange.getUndoneChangeType().contains(ChangeType.DELETE)) { inheritedChangeType = inheritedChangeType.combine(ChangeType.DELETE); } } getOp.setChangeType(inheritedChangeType.combine(getOp.getChangeType())); } getOp.setDeletionID(pcEntry.getDeletionID()); getOp.setItemType(pcEntry.getItemType()); getOp.setPendingChangeID(LocalPendingChange.LOCAL_PENDING_CHANGE_ID); getOp.setItemID(pcEntry.getItemID()); if (null != lvEntry) { if (lvEntry.isCommitted() && !lvEntry.isDirectory()) { getOp.setBaselineFileGUID( lvEntry.hasBaselineFileGUID() ? lvEntry.getBaselineFileGUID() : new byte[16]); } getOp.setHashValue(lvEntry.getHashValue()); getOp.setVersionLocal(lvEntry.isDeleted() ? 0 : lvEntry.getVersion()); getOp.setVersionServer(lvEntry.getVersion()); getOp.setVersionServerDate((-1 == lvEntry.getCheckinDate()) ? DotNETDate.MIN_CALENDAR : DotNETDate.fromWindowsFileTimeUTC(lvEntry.getCheckinDate())); getOp.setPropertyValues(pcEntry.getPropertyValues()); } else { getOp.setVersionServer(pcEntry.getVersion()); } getOps.put(new ServerItemIsCommittedTuple(getOp.getSourceServerItem(), pcEntry.isCommitted()), getOp); // Remove local version rows for adds, branches where the item is an // add, or we are syncing an item on top of an undone branch. if (undoneChange.isUndoingAdd() || (undoneChange.isUndoingBranch() && getOp.getTargetLocalItem() != null)) { if (null != lvEntry) { lv.removeByServerItem(lvEntry.getServerItem(), lvEntry.isCommitted(), true); } } } // Pass 2: Affected items underneath undone recursive changes for (final UndoneChange undoneChange : undoneChanges) { if (!undoneChange.isUndoingRecursiveChange()) { continue; } // The sort order means that undoneChange is always the closest // recursive operation affecting the item for (final WorkspaceLocalItem lvEntry : ParsedItemSpec.queryLocalVersionsByTargetServerItem(lv, pc, undoneChange.getPendingChange().getTargetServerItem(), RecursionType.FULL, null, ParsedItemSpecOptions.INCLUDE_DELETED)) { if (getOps.containsKey( new ServerItemIsCommittedTuple(lvEntry.getServerItem(), lvEntry.isCommitted()))) { continue; } final String currentServerItem = lvEntry.isCommitted() ? pc.getTargetServerItemForCommittedServerItem(lvEntry.getServerItem()) : lvEntry.getServerItem(); final GetOperation getOp = new GetOperation(); getOp.setSourceLocalItem(lvEntry.isDeleted() ? null : lvEntry.getLocalItem()); getOp.setTargetServerItem(undoneChange.getRevertToServerItem() + currentServerItem .substring(undoneChange.getPendingChange().getTargetServerItem().length())); if (getOp.getTargetServerItem().length() > VersionControlConstants.MAX_SERVER_PATH_SIZE) { throw createPathTooLongException(getOp.getTargetServerItem()); } getOp.setSourceServerItem( lvEntry.isCommitted() ? lvEntry.getServerItem() : getOp.getTargetServerItem()); getOp.setTargetLocalItem(WorkingFolder.getLocalItemForServerItem(getOp.getTargetServerItem(), wp.getWorkingFolders())); if (null != getOp.getTargetLocalItem()) { getOp.setLocalVersionEntry(lv.getByLocalItem(getOp.getTargetLocalItem())); } getOp.setDeletionID(0); getOp.setEncoding(lvEntry.getEncoding()); getOp.setItemType(lvEntry.isDirectory() ? ItemType.FOLDER : ItemType.FILE); getOp.setPropertyValues(lvEntry.getPropertyValues()); // Even if this item has a pending change which is not being // undone -- we return 0 here getOp.setPendingChangeID(0); getOp.setItemID(lvEntry.getItemID()); if (!ServerPath.equals(currentServerItem, getOp.getTargetServerItem())) { if (!lvEntry.isCommitted() && !ServerPath.equals(currentServerItem, getOp.getTargetServerItem())) { // Uncommitted items have the itemid of the target // server item, and we're changing paths, so set the // item id to 0 because we have no idea what the item id // of the target server item is getOp.setItemID(0); } final LocalPendingChange pcEntry = pc.getByTargetServerItem(currentServerItem); if (null != pcEntry) { if (pcEntry.isLock()) { // We cannot change the path of an item with a // pending lock locally. return sendToServer(failures, onlineOperationRequired); } if (pcEntry.hasMergeConflict()) { throw new CannotRenameDueToChildConflictException( undoneChange.getPendingChange().getTargetServerItem(), pcEntry.getTargetServerItem()); } // Queue this pending change for a later update of its // target path and itemid (if it still exists after // removing those pending changes that are being undone) renamedPendingChanges .add(new RenamedPendingChange(currentServerItem, getOp.getTargetServerItem())); } } if (lvEntry.isCommitted() && !lvEntry.isDirectory()) { getOp.setBaselineFileGUID( lvEntry.hasBaselineFileGUID() ? lvEntry.getBaselineFileGUID() : new byte[16]); } getOp.setHashValue(lvEntry.getHashValue()); getOp.setVersionLocal(lvEntry.isDeleted() ? 0 : lvEntry.getVersion()); getOp.setVersionServer(lvEntry.getVersion()); getOp.setVersionServerDate((-1 == lvEntry.getCheckinDate()) ? DotNETDate.MIN_CALENDAR : DotNETDate.fromWindowsFileTimeUTC(lvEntry.getCheckinDate())); getOp.setChangeType(ChangeType.NONE); // We'll take a quick look at the parents of this target server // item to determine if the item is still deleted. On this same // pass, we'll compute the ChangeType of the GetOperation to // generate. Since there was no pending change being undone on // this item, the ChangeType is equal to the union of the // recursive changetype bits on parent pending changes which are // being undone. boolean stillDeleted = false; for (final LocalPendingChange parentPcEntry : pc .queryParentsOfTargetServerItem(currentServerItem)) { final UndoneChange checkChange = undoneChangesMap.get(parentPcEntry.getTargetServerItem()); if (checkChange == null) { if (parentPcEntry.isDelete()) { stillDeleted = true; // Who cares what the ChangeType on the GetOperation // is, if we're not going to emit it? break; } } else { ChangeType changeType = getOp.getChangeType(); changeType = changeType.combine(checkChange.getUndoneChangeType()); changeType = changeType.combine(ChangeType.RENAME_OR_DELETE); getOp.setChangeType(changeType); } } if (!lvEntry.isDeleted() || !stillDeleted) { if (null != getOp.getTargetLocalItem() || null != getOp.getSourceLocalItem()) { getOps.put(new ServerItemIsCommittedTuple(lvEntry.getServerItem(), lvEntry.isCommitted()), getOp); } } } } // Remove the pending change rows, putting back modified changes for // those entries which were selective undoes. Do this in two loops so // the changes are atomic. final List<LocalPendingChange> selectiveUndoChanges = new ArrayList<LocalPendingChange>(); for (final UndoneChange undoneChange : undoneChanges) { pc.remove(undoneChange.getPendingChange()); // If this was a selective undo, add an entry to the table if (!undoneChange.getUndoneChangeType().equals(undoneChange.getPendingChange().getChangeType())) { final LocalPendingChange newChange = undoneChange.getPendingChange().clone(); newChange.setChangeType( undoneChange.getPendingChange().getChangeType().remove(undoneChange.getUndoneChangeType())); newChange.setTargetServerItem(undoneChange.getRevertToServerItem()); selectiveUndoChanges.add(newChange); } } // Second loop -- pend the selective undo changes. for (final LocalPendingChange pcEntry : selectiveUndoChanges) { pc.pendChange(pcEntry); } // Update the pending changes that were not undone but were affected by // parental renames. // Do this in two loops (remove+capture, modify+apply) so the changes // are atomic. for (final RenamedPendingChange renamedPendingChange : renamedPendingChanges) { final LocalPendingChange pcEntry = pc .getByTargetServerItem(renamedPendingChange.getOldTargetServerItem()); if (null != pcEntry) { pc.remove(pcEntry); renamedPendingChange.setPendingChange(pcEntry); if (!pcEntry.isCommitted()) { final WorkspaceLocalItem lvEntry = lv .getByServerItem(renamedPendingChange.getOldTargetServerItem(), false); if (null != lvEntry) { renamedPendingChange.setLocalVersion(lvEntry); lv.removeByServerItem(lvEntry.getServerItem(), lvEntry.isCommitted(), true); } } } } // Second loop -- apply the data to the tables after modifying it for (final RenamedPendingChange renamedPendingChange : renamedPendingChanges) { final LocalPendingChange pcEntry = renamedPendingChange.getPendingChange(); final WorkspaceLocalItem lvEntry = renamedPendingChange.getLocalVersion(); if (null != pcEntry) { pcEntry.setTargetServerItem(renamedPendingChange.getTargetServerItem()); if (!pcEntry.isCommitted()) { pcEntry.setItemID(0); } pc.pendChange(pcEntry); } if (null != lvEntry) { lvEntry.setServerItem(renamedPendingChange.getTargetServerItem()); lvEntry.setItemID(0); lv.add(lvEntry); } } failures.set(failureList.toArray(new Failure[failureList.size()])); onlineOperationRequired.set(false); return getOps.values().toArray(new GetOperation[getOps.size()]); }
From source file:pe.gob.mef.gescon.web.ui.PreguntaMB.java
public void onListTipoConocimientoChange(AjaxBehaviorEvent event) { try {/*from w ww . j a v a 2s. c om*/ if (event != null) { final BigDecimal id = (BigDecimal) ((SelectOneMenu) event.getSource()).getValue(); this.setIdTipoConocimiento(id); if (id != null) { HashMap filters = new HashMap(); filters.put("ntipoconocimientoid", id); ConocimientoService service = (ConocimientoService) ServiceFinder .findBean("ConocimientoService"); if (this.getSelectedPregunta() != null) { filters.put("nconocimientoid", this.getSelectedPregunta().getNpreguntaid().toString()); this.setListaTargetVinculos(new ArrayList()); List<Consulta> lista = service.getConcimientosVinculados(filters); Collections.sort(lista, Consulta.Comparators.ID); if (id.equals(Constante.BASELEGAL)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosBL(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosBL().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); } else if (id.equals(Constante.PREGUNTAS)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosPR(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosPR().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); } else if (id.equals(Constante.WIKI)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosWK(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosWK().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); } else if (id.equals(Constante.CONTENIDO)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosCT(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosCT().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); } else if (id.equals(Constante.BUENAPRACTICA)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosBP(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosBP().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosOM(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosOM().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); } } else { if (id.equals(Constante.BASELEGAL)) { this.setListaTargetVinculos(this.getListaTargetVinculosBL()); } else if (id.equals(Constante.PREGUNTAS)) { this.setListaTargetVinculos(this.getListaTargetVinculosPR()); } else if (id.equals(Constante.WIKI)) { this.setListaTargetVinculos(this.getListaTargetVinculosWK()); } else if (id.equals(Constante.CONTENIDO)) { this.setListaTargetVinculos(this.getListaTargetVinculosCT()); } else if (id.equals(Constante.BUENAPRACTICA)) { this.setListaTargetVinculos(this.getListaTargetVinculosBP()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { this.setListaTargetVinculos(this.getListaTargetVinculosOM()); } } if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { List<String> ids = new ArrayList<String>(); for (Consulta c : this.getListaTargetVinculos()) { ids.add(c.getIdconocimiento().toString()); } String filter = StringUtils.join(ids, ','); if (id.equals(Constante.WIKI)) { filter = filter.concat(",") .concat(this.getSelectedPregunta().getNpreguntaid().toString()); } filters.put("nconocimientovinc", filter); } if (id.equals(Constante.BASELEGAL)) { this.setListaSourceVinculosBL(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosBL()); } else if (id.equals(Constante.PREGUNTAS)) { this.setListaSourceVinculosPR(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosPR()); } else if (id.equals(Constante.WIKI)) { this.setListaSourceVinculosWK(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosWK()); } else if (id.equals(Constante.CONTENIDO)) { this.setListaSourceVinculosCT(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosCT()); } else if (id.equals(Constante.BUENAPRACTICA)) { this.setListaSourceVinculosBP(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosBP()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { this.setListaSourceVinculosOM(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosOM()); } this.setPickListPregunta(new DualListModel<Consulta>(this.getListaSourceVinculos(), this.getListaTargetVinculos())); } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.PreguntaMB.java
public void onTransferPreguntas(TransferEvent event) { int index;/* w ww. ja v a 2s. co m*/ try { if (event != null) { BigDecimal id = this.getIdTipoConocimiento(); if (event.isAdd()) { Collections.sort(this.getListaSourceVinculos(), Consulta.Comparators.ID); for (Consulta ele : (List<Consulta>) event.getItems()) { index = Collections.binarySearch(this.getListaSourceVinculos(), ele, Consulta.Comparators.ID); if (this.getListaTargetVinculos() == null) { this.setListaTargetVinculos(new ArrayList<Consulta>()); } this.getListaTargetVinculos().add(this.getListaSourceVinculos().get(index)); this.getListaSourceVinculos().remove(index); } } if (event.isRemove()) { Collections.sort(this.getListaTargetVinculos(), Consulta.Comparators.ID); for (Consulta ele : (List<Consulta>) event.getItems()) { index = Collections.binarySearch(this.getListaTargetVinculos(), ele, Consulta.Comparators.ID); if (this.getListaSourceVinculos() == null) { this.setListaSourceVinculos(new ArrayList<Consulta>()); } this.getListaSourceVinculos().add(this.getListaTargetVinculos().get(index)); this.getListaTargetVinculos().remove(index); } } if (id.equals(Constante.BASELEGAL)) { this.setListaSourceVinculosBL(this.getListaSourceVinculos()); this.setListaTargetVinculosBL(this.getListaTargetVinculos()); } else if (id.equals(Constante.PREGUNTAS)) { this.setListaSourceVinculosPR(this.getListaSourceVinculos()); this.setListaTargetVinculosPR(this.getListaTargetVinculos()); } else if (id.equals(Constante.WIKI)) { this.setListaSourceVinculosWK(this.getListaSourceVinculos()); this.setListaTargetVinculosWK(this.getListaTargetVinculos()); } else if (id.equals(Constante.CONTENIDO)) { this.setListaSourceVinculosCT(this.getListaSourceVinculos()); this.setListaTargetVinculosCT(this.getListaTargetVinculos()); } else if (id.equals(Constante.BUENAPRACTICA)) { this.setListaSourceVinculosBP(this.getListaSourceVinculos()); this.setListaTargetVinculosBP(this.getListaTargetVinculos()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { this.setListaSourceVinculosOM(this.getListaSourceVinculos()); this.setListaTargetVinculosOM(this.getListaTargetVinculos()); } this.listaTargetVinculosConocimiento = new ArrayList<Consulta>(); if (this.getListaTargetVinculosBL() == null) { } else { this.getListaTargetVinculosConocimiento().addAll(this.getListaTargetVinculosBL()); } if (this.getListaTargetVinculosBP() == null) { } else { this.getListaTargetVinculosConocimiento().addAll(this.getListaTargetVinculosBP()); } if (this.getListaTargetVinculosCT() == null) { } else { this.getListaTargetVinculosConocimiento().addAll(this.getListaTargetVinculosCT()); } if (this.getListaTargetVinculosOM() == null) { } else { this.getListaTargetVinculosConocimiento().addAll(this.getListaTargetVinculosOM()); } // if (this.getListaTargetVinculosPR() == null) { // } else { // this.getListaTargetVinculosPR().addAll(this.getListaTargetVinculosPR()); // } if (this.getListaTargetVinculosWK() == null) { } else { this.getListaTargetVinculosConocimiento().addAll(this.getListaTargetVinculosWK()); } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.BaseLegalMB.java
public void onTransfer(TransferEvent event) { int index;// ww w . ja v a 2 s .c om try { if (event != null) { if (event.isAdd()) { Collections.sort(this.getListaSource(), BaseLegal.Comparators.ID); for (BaseLegal ele : (List<BaseLegal>) event.getItems()) { index = Collections.binarySearch(this.getListaSource(), ele, BaseLegal.Comparators.ID); if (this.getListaTarget() == null) { this.setListaTarget(new ArrayList<BaseLegal>()); } this.getListaTarget().add(this.getListaSource().get(index)); this.getListaSource().remove(index); } } if (event.isRemove()) { Collections.sort(this.getListaTarget(), BaseLegal.Comparators.ID); for (BaseLegal ele : (List<BaseLegal>) event.getItems()) { index = Collections.binarySearch(this.getListaTarget(), ele, BaseLegal.Comparators.ID); if (this.getListaSource() == null) { this.setListaSource(new ArrayList<BaseLegal>()); } this.getListaSource().add(this.getListaTarget().get(index)); this.getListaTarget().remove(index); } } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.PendienteMB.java
public void onTransferBL(TransferEvent event) { int index;/*from www .j av a2s .co m*/ try { if (event != null) { if (event.isAdd()) { Collections.sort(this.getListaSource(), BaseLegal.Comparators.ID); for (BaseLegal ele : (List<BaseLegal>) event.getItems()) { index = Collections.binarySearch(this.getListaSource(), ele, BaseLegal.Comparators.ID); if (this.getListaTarget() == null) { this.setListaTarget(new ArrayList<BaseLegal>()); } this.getListaTarget().add(this.getListaSource().get(index)); this.getListaSource().remove(index); } } if (event.isRemove()) { Collections.sort(this.getListaTarget(), BaseLegal.Comparators.ID); for (BaseLegal ele : (List<BaseLegal>) event.getItems()) { index = Collections.binarySearch(this.getListaTarget(), ele, BaseLegal.Comparators.ID); if (this.getListaSource() == null) { this.setListaSource(new ArrayList<BaseLegal>()); } this.getListaSource().add(this.getListaTarget().get(index)); this.getListaTarget().remove(index); } } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.PendienteMB.java
public void onTransfer(TransferEvent event) { int index;// w w w. j a va 2 s.c om try { if (event != null) { BigDecimal id = this.getIdTipoConocimiento(); if (event.isAdd()) { Collections.sort(this.getListaSourceVinculos(), Consulta.Comparators.ID); for (Consulta ele : (List<Consulta>) event.getItems()) { index = Collections.binarySearch(this.getListaSourceVinculos(), ele, Consulta.Comparators.ID); if (this.getListaTargetVinculos() == null) { this.setListaTargetVinculos(new ArrayList<Consulta>()); } this.getListaTargetVinculos().add(this.getListaSourceVinculos().get(index)); this.getListaSourceVinculos().remove(index); } } if (event.isRemove()) { Collections.sort(this.getListaTargetVinculos(), Consulta.Comparators.ID); for (Consulta ele : (List<Consulta>) event.getItems()) { index = Collections.binarySearch(this.getListaTargetVinculos(), ele, Consulta.Comparators.ID); if (this.getListaSourceVinculos() == null) { this.setListaSourceVinculos(new ArrayList<Consulta>()); } this.getListaSourceVinculos().add(this.getListaTargetVinculos().get(index)); this.getListaTargetVinculos().remove(index); } } if (id.equals(Constante.BASELEGAL)) { this.setListaSourceVinculosBL(this.getListaSourceVinculos()); this.setListaTargetVinculosBL(this.getListaTargetVinculos()); } else if (id.equals(Constante.PREGUNTAS)) { this.setListaSourceVinculosPR(this.getListaSourceVinculos()); this.setListaTargetVinculosPR(this.getListaTargetVinculos()); } else if (id.equals(Constante.WIKI)) { this.setListaSourceVinculosWK(this.getListaSourceVinculos()); this.setListaTargetVinculosWK(this.getListaTargetVinculos()); } else if (id.equals(Constante.CONTENIDO)) { this.setListaSourceVinculosCT(this.getListaSourceVinculos()); this.setListaTargetVinculosCT(this.getListaTargetVinculos()); } else if (id.equals(Constante.BUENAPRACTICA)) { this.setListaSourceVinculosBP(this.getListaSourceVinculos()); this.setListaTargetVinculosBP(this.getListaTargetVinculos()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { this.setListaSourceVinculosOM(this.getListaSourceVinculos()); this.setListaTargetVinculosOM(this.getListaTargetVinculos()); } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.PendienteMB.java
public void onListTipoConocimientoChange(AjaxBehaviorEvent event) { try {/*from w ww .j av a 2s .com*/ if (event != null) { final BigDecimal id = (BigDecimal) ((SelectOneMenu) event.getSource()).getValue(); this.setIdTipoConocimiento(id); if (id != null) { HashMap filters = new HashMap(); filters.put("ntipoconocimientoid", id); filters.put("npreguntaid", this.getSelectedPregunta().getNpreguntaid()); PreguntaService service = (PreguntaService) ServiceFinder.findBean("PreguntaService"); if (this.getSelectedPregunta() != null) { filters.put("nconocimientoid", this.getSelectedPregunta().getNpreguntaid().toString()); this.setListaTargetVinculos(new ArrayList()); List<Consulta> lista = service.getConcimientosVinculados(filters); Collections.sort(lista, Consulta.Comparators.ID); if (id.equals(Constante.BASELEGAL)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosBL(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosBL().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); } else if (id.equals(Constante.PREGUNTAS)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosPR(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosPR().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); } else if (id.equals(Constante.WIKI)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosWK(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosWK().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); } else if (id.equals(Constante.CONTENIDO)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosCT(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosCT().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); } else if (id.equals(Constante.BUENAPRACTICA)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosBP(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosBP().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { for (Consulta ele : lista) { int pos = Collections.binarySearch(this.getListaTargetVinculosOM(), ele, Consulta.Comparators.ID); if (pos < 0) { this.getListaTargetVinculosOM().add(ele); } } this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); } } else { if (id.equals(Constante.BASELEGAL)) { this.setListaTargetVinculos(this.getListaTargetVinculosBL()); } else if (id.equals(Constante.PREGUNTAS)) { this.setListaTargetVinculos(this.getListaTargetVinculosPR()); } else if (id.equals(Constante.WIKI)) { this.setListaTargetVinculos(this.getListaTargetVinculosWK()); } else if (id.equals(Constante.CONTENIDO)) { this.setListaTargetVinculos(this.getListaTargetVinculosCT()); } else if (id.equals(Constante.BUENAPRACTICA)) { this.setListaTargetVinculos(this.getListaTargetVinculosBP()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { this.setListaTargetVinculos(this.getListaTargetVinculosOM()); } } if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { List<String> ids = new ArrayList<String>(); for (Consulta c : this.getListaTargetVinculos()) { ids.add(c.getIdconocimiento().toString()); } String filter = StringUtils.join(ids, ','); if (id.equals(Constante.WIKI)) { filter = filter.concat(",") .concat(this.getSelectedPregunta().getNpreguntaid().toString()); } filters.put("nconocimientovinc", filter); } if (id.equals(Constante.BASELEGAL)) { this.setListaSourceVinculosBL(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosBL()); } else if (id.equals(Constante.PREGUNTAS)) { this.setListaSourceVinculosPR(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosPR()); } else if (id.equals(Constante.WIKI)) { this.setListaSourceVinculosWK(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosWK()); } else if (id.equals(Constante.CONTENIDO)) { this.setListaSourceVinculosCT(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosCT()); } else if (id.equals(Constante.BUENAPRACTICA)) { this.setListaSourceVinculosBP(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosBP()); } else if (id.equals(Constante.OPORTUNIDADMEJORA)) { this.setListaSourceVinculosOM(service.getConcimientosDisponibles(filters)); this.setListaSourceVinculos(this.getListaSourceVinculosOM()); } this.setPickListPregunta(new DualListModel<Consulta>(this.getListaSourceVinculos(), this.getListaTargetVinculos())); } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }