List of usage examples for java.lang String CASE_INSENSITIVE_ORDER
Comparator CASE_INSENSITIVE_ORDER
To view the source code for java.lang String CASE_INSENSITIVE_ORDER.
Click Source Link
From source file:com.microsoft.tfs.core.clients.versioncontrol.internal.localworkspace.LocalDataAccessLayer.java
private static boolean reconcileLocalWorkspaceHelper(final Workspace workspace, final WebServiceLayer webServiceLayer, final boolean unscannedReconcile, final boolean reconcileMissingFromDisk, final AtomicReference<Failure[]> failures, final AtomicBoolean pendingChangesUpdatedByServer) { Check.notNull(workspace, "workspace"); //$NON-NLS-1$ pendingChangesUpdatedByServer.set(false); final List<PendingChange> convertedAdds = new ArrayList<PendingChange>(); final boolean throwOnProjectRenamed; if (EnvironmentVariables.isDefined(EnvironmentVariables.DD_SUITES_PROJECT_RENAME_UNPATCHED_CLIENT)) { throwOnProjectRenamed = false;/*ww w. java2 s . c o m*/ } else { throwOnProjectRenamed = true; } final AtomicReference<GUID> serverPendingChangeSignature = new AtomicReference<GUID>(GUID.EMPTY); // No optimization away of reconciles when sending up MissingFromDisk // rows, since the bit in the header (lvHeader.PendingReconcile) may be // false when we actually have work to do (there are rows in the table // marked MissingFromDisk). if ((unscannedReconcile || !workspace.getWorkspaceWatcher().isScanNecessary()) && !reconcileMissingFromDisk) { // Pre-reconcile final AtomicBoolean hasPendingLocalVersionRows = new AtomicBoolean(true); LocalWorkspaceTransaction transaction = new LocalWorkspaceTransaction(workspace); try { transaction.execute(new LocalVersionHeaderTransaction() { @Override public void invoke(final WorkspaceVersionTableHeader lvh) { hasPendingLocalVersionRows.set(lvh.getPendingReconcile()); } }); } finally { try { transaction.close(); } catch (final IOException e) { throw new VersionControlException(e); } } final AtomicReference<GUID> clientPendingChangeSignature = new AtomicReference<GUID>(GUID.EMPTY); if (!hasPendingLocalVersionRows.get()) { transaction = new LocalWorkspaceTransaction(workspace); try { transaction.execute(new PendingChangesHeaderTransaction() { @Override public void invoke(final LocalPendingChangesTableHeader pch) { clientPendingChangeSignature.set(pch.getClientSignature()); } }); } finally { try { transaction.close(); } catch (final IOException e) { throw new VersionControlException(e); } } final GUID lastServerPendingChangeGuid = workspace.getOfflineCacheData() .getLastServerPendingChangeSignature(); final Calendar lastReconcileTime = workspace.getOfflineCacheData().getLastReconcileTime(); lastReconcileTime.add(Calendar.SECOND, 8); if (lastServerPendingChangeGuid != GUID.EMPTY && clientPendingChangeSignature.get().equals(lastServerPendingChangeGuid) && lastReconcileTime.after(Calendar.getInstance())) { // This reconcile was optimized away with no server call. failures.set(new Failure[0]); return false; } serverPendingChangeSignature.set( webServiceLayer.queryPendingChangeSignature(workspace.getName(), workspace.getOwnerName())); if (serverPendingChangeSignature.get() != GUID.EMPTY && clientPendingChangeSignature.get().equals(serverPendingChangeSignature)) { // This reconcile was optimized away. workspace.getOfflineCacheData() .setLastServerPendingChangeSignature(serverPendingChangeSignature.get()); workspace.getOfflineCacheData().setLastReconcileTime(Calendar.getInstance()); failures.set(new Failure[0]); return false; } } } final AtomicBoolean toReturn = new AtomicBoolean(true); final LocalWorkspaceTransaction transaction = new LocalWorkspaceTransaction(workspace); try { final AtomicReference<Failure[]> delegateFailures = new AtomicReference<Failure[]>(new Failure[0]); final AtomicBoolean delegatePCUpdated = new AtomicBoolean(false); transaction.execute(new AllTablesTransaction() { @Override public void invoke(final LocalWorkspaceProperties wp, final WorkspaceVersionTable lv, final LocalPendingChangesTable pc) { if (!unscannedReconcile) { // The line below has been commented out because we // decided not to force a full scan here, because it // causes significant degradation in UI performance. // // workspace.getWorkspaceWatcher().markPathChanged(null); // // It was an attempt to fix the bug: // Bug 6191: When using local workspaces, get latest // does not get a file that has been deleted from disk. // // The customer has to explicitly invoke // Pending Changes>Actions>Detect local changes // in Team Explorer. // // Note that none of customers reported that as an // issue. // It was detected on our tests only. workspace.getWorkspaceWatcher().scan(wp, lv, pc); } // Pre-reconcile if (!lv.getPendingReconcile() && !reconcileMissingFromDisk && GUID.EMPTY == serverPendingChangeSignature.get()) { serverPendingChangeSignature.set(webServiceLayer .queryPendingChangeSignature(workspace.getName(), workspace.getOwnerName())); if (serverPendingChangeSignature.get() != GUID.EMPTY && pc.getClientSignature().equals(serverPendingChangeSignature.get())) { // This reconcile was optimized away. delegateFailures.set(new Failure[0]); workspace.getOfflineCacheData() .setLastServerPendingChangeSignature(serverPendingChangeSignature.get()); workspace.getOfflineCacheData().setLastReconcileTime(Calendar.getInstance()); toReturn.set(true); return; } } // Acknowledgment of team project renames, if any have been // completed if (wp.getNewProjectRevisionId() > 0) { webServiceLayer.promotePendingWorkspaceMappings(workspace.getName(), workspace.getOwnerName(), wp.getNewProjectRevisionId()); wp.setNewProjectRevisionId(0); } final LocalPendingChange[] pendingChanges = pc.queryByTargetServerItem(ServerPath.ROOT, RecursionType.FULL, null); /* * TEE-specific Code * * In order to support offline property changes, which * cannot be reconciled with * WebServiceLayer.reconcileLocalWorkspace (the property * values can't be sent), we have to pull out the pended * property changes and send them to the server before * reconciling. */ final List<ChangeRequest> propertyRequests = new ArrayList<ChangeRequest>(); for (final LocalPendingChange lpc : pendingChanges) { if (lpc.getChangeType().contains(ChangeType.PROPERTY)) { final PropertyValue[] pv = lpc.getPropertyValues(); final String serverItem = lpc.getTargetServerItem(); if (pv != null && pv.length > 0 && serverItem != null) { final ChangeRequest request = new ChangeRequest( new ItemSpec(serverItem, RecursionType.NONE), new WorkspaceVersionSpec(workspace), RequestType.PROPERTY, ItemType.ANY, VersionControlConstants.ENCODING_UNCHANGED, LockLevel.UNCHANGED, 0, null, false); request.setProperties(pv); propertyRequests.add(request); } } } if (propertyRequests.size() > 0) { ((WebServiceLayerLocalWorkspaces) webServiceLayer).pendChangesInLocalWorkspace( workspace.getName(), workspace.getOwnerName(), propertyRequests.toArray(new ChangeRequest[propertyRequests.size()]), PendChangesOptions.NONE, SupportedFeatures.ALL, new AtomicReference<Failure[]>(), null, null, new AtomicBoolean(), new AtomicReference<ChangePendedFlags>()); // TODO handle failures? } // Back to normal, non-TEE behavior final AtomicBoolean outClearLocalVersionTable = new AtomicBoolean(); final ServerItemLocalVersionUpdate[] lvUpdates = lv.getUpdatesForReconcile(pendingChanges, reconcileMissingFromDisk, outClearLocalVersionTable); ReconcileResult result = webServiceLayer.reconcileLocalWorkspace(workspace.getName(), workspace.getOwnerName(), pc.getClientSignature(), pendingChanges, lvUpdates, outClearLocalVersionTable.get(), throwOnProjectRenamed); // report any failures Failure[] reconcileFailures = result.getFailures(); workspace.getClient().reportFailures(workspace, reconcileFailures); if (reconcileFailures.length > 0) { throw new ReconcileFailedException(reconcileFailures); } GUID newSignature = new GUID(result.getNewSignature()); PendingChange[] newPendingChanges = result.getNewPendingChanges(); // If the local version rows for this local workspace have // been purged from the server, then the server will set // this flag on the result of the next reconcile. if (result.isReplayLocalVersionsRequired()) { // Reconcile a second time. This time, set the // clearLocalVersionTable flag. This way, we know // we have cleared out any lingering local version rows // for this workspace. if (!outClearLocalVersionTable.get()) { result = webServiceLayer.reconcileLocalWorkspace(workspace.getName(), workspace.getOwnerName(), pc.getClientSignature(), pendingChanges, lvUpdates, true /* clearLocalVersionTable */, throwOnProjectRenamed); // Report any failures reconcileFailures = result.getFailures(); workspace.getClient().reportFailures(workspace, reconcileFailures); if (reconcileFailures.length > 0) { throw new ReconcileFailedException(reconcileFailures); } // Grab the new signature and new pending changes newSignature = new GUID(result.getNewSignature()); newPendingChanges = result.getNewPendingChanges(); } // Now, go through the local version table and replay // every row that we have. final List<ServerItemLocalVersionUpdate> replayUpdates = new ArrayList<ServerItemLocalVersionUpdate>( Math.min(lv.getLocalItemsCount(), 1000)); for (final WorkspaceLocalItem lvEntry : lv.queryByServerItem(ServerPath.ROOT, RecursionType.FULL, null, true /* includeDeleted */)) { final ServerItemLocalVersionUpdate replayUpdate = lvEntry .getLocalVersionUpdate(reconcileMissingFromDisk, true /* force */); if (replayUpdate != null) { replayUpdates.add(replayUpdate); // Batch these updates in groups of 1000 items. if (replayUpdates.size() >= 1000) { webServiceLayer.updateLocalVersion(workspace.getName(), workspace.getOwnerName(), replayUpdates.toArray( new ServerItemLocalVersionUpdate[replayUpdates.size()])); replayUpdates.clear(); } } } if (replayUpdates.size() > 0) { webServiceLayer.updateLocalVersion(workspace.getName(), workspace.getOwnerName(), replayUpdates.toArray(new ServerItemLocalVersionUpdate[replayUpdates.size()])); } } if (result.isPendingChangesUpdated()) { delegatePCUpdated.set(true); final Map<String, ItemType> newPendingDeletes = new TreeMap<String, ItemType>( String.CASE_INSENSITIVE_ORDER); for (final PendingChange pendingChange : newPendingChanges) { if (pendingChange.isAdd()) { final LocalPendingChange oldPendingChange = pc .getByTargetServerItem(pendingChange.getServerItem()); if (null == oldPendingChange || !oldPendingChange.isAdd()) { // Before calling ReconcileLocalWorkspace, // we did not have a pending add at this // target server item. convertedAdds.add(pendingChange); } } else if (pendingChange.isDelete()) { // If the server removed any of our presented // pending deletes, we want to know about it so // we can get rid of the local version rows that // we have in the deleted state. The server will // remove our pending deletes when the item has // been destroyed on the server. newPendingDeletes.put( pendingChange.getSourceServerItem() == null ? pendingChange.getServerItem() : pendingChange.getSourceServerItem(), pendingChange.getItemType()); } } for (final LocalPendingChange oldPendingChange : pc .queryByCommittedServerItem(ServerPath.ROOT, RecursionType.FULL, null)) { if (oldPendingChange.isDelete() && !newPendingDeletes.containsKey(oldPendingChange.getCommittedServerItem())) { // We presented this delete to the server for // Reconcile, but the server removed it from the // pending changes manifest. We need to get rid // of the LV rows for // oldPendingChange.CommittedServerItem since // this item is now destroyed. final List<ServerItemIsCommittedTuple> lvRowsToRemove = new ArrayList<ServerItemIsCommittedTuple>(); final RecursionType recursion = oldPendingChange.isRecursiveChange() ? RecursionType.FULL : RecursionType.NONE; // Aggregate up the deleted local version // entries at this committed server item // (or below if it's a folder), and we'll remove // them. for (final WorkspaceLocalItem lvEntry : lv.queryByServerItem( oldPendingChange.getCommittedServerItem(), recursion, null, true /* includeDeleted */)) { if (lvEntry.isDeleted()) { lvRowsToRemove.add(new ServerItemIsCommittedTuple(lvEntry.getServerItem(), lvEntry.isCommitted())); } } for (final ServerItemIsCommittedTuple tuple : lvRowsToRemove) { // We don't need to reconcile the removal of // LV entries marked IsDeleted since they // don't exist on the server anyway. lv.removeByServerItem(tuple.getCommittedServerItem(), tuple.isCommitted(), false); } } } pc.replacePendingChanges(newPendingChanges); } // If all we're doing to LV is marking it reconciled, then // don't use TxF to commit // both tables atomically as this is slower if (!lv.isDirty()) { transaction.setAllowTxF(false); } if (lvUpdates.length > 0) { lv.markAsReconciled(wp, reconcileMissingFromDisk); // If we removed all missing-from-disk items from the // local version table, then we need to remove // the corresponding candidate delete rows for those // items as well. if (reconcileMissingFromDisk) { List<String> candidatesToRemove = null; for (final LocalPendingChange candidateChange : pc .queryCandidatesByTargetServerItem(ServerPath.ROOT, RecursionType.FULL, null)) { if (candidateChange.isDelete()) { if (null == candidatesToRemove) { candidatesToRemove = new ArrayList<String>(); } candidatesToRemove.add(candidateChange.getTargetServerItem()); } } if (null != candidatesToRemove) { for (final String candidateDeleteTargetServerItem : candidatesToRemove) { pc.removeCandidateByTargetServerItem(candidateDeleteTargetServerItem); } // Set the candidates changed to true so that it // refreshes the UI LocalWorkspaceTransaction.getCurrent().setRaisePendingChangeCandidatesChanged(true); } } } newSignature = webServiceLayer.queryPendingChangeSignature(workspace.getName(), workspace.getOwnerName()); if (!newSignature.equals(pc.getClientSignature())) { pc.setClientSignature(newSignature); workspace.getOfflineCacheData().setLastServerPendingChangeSignature(newSignature); } if (!newSignature.equals(pc.getClientSignature())) { pc.setClientSignature(newSignature); workspace.getOfflineCacheData().setLastServerPendingChangeSignature(newSignature); } workspace.getOfflineCacheData().setLastReconcileTime(Calendar.getInstance()); } }); failures.set(delegateFailures.get()); pendingChangesUpdatedByServer.set(delegatePCUpdated.get()); } finally { try { transaction.close(); } catch (final IOException e) { throw new VersionControlException(e); } } if (convertedAdds.size() > 0) { final UpdateLocalVersionQueueOptions options = UpdateLocalVersionQueueOptions.UPDATE_BOTH; final UpdateLocalVersionQueue ulvq = new UpdateLocalVersionQueue(workspace, options); try { for (final PendingChange pc : convertedAdds) { // Every item in this list has a ChangeType of Add. As a // result they are uncommitted items with no committed hash // value, no committed length, and no baseline file GUID. ulvq.queueUpdate(new ClientLocalVersionUpdate(pc.getServerItem(), pc.getItemID(), pc.getLocalItem(), 0 /* localVersion */, DotNETDate.MIN_CALENDAR, pc.getEncoding(), null /* committedHashValue */, 0 /* committedLength */, null /* baselineFileGuid */, null /* pendingChangeTargetServerItem */, null /* properties */)); } } finally { ulvq.close(); } } return toReturn.get(); }
From source file:com.zimbra.cs.account.ldap.LdapProvisioning.java
private Cos copyCos(String srcCosId, String destCosName, Map<String, Object> cosAttrs) throws ServiceException { destCosName = destCosName.toLowerCase().trim(); Cos srcCos = getCosById(srcCosId, null); if (srcCos == null) throw AccountServiceException.NO_SUCH_COS(srcCosId); // bug 67716, use a case insensitive map because provided attr names may not be // the canonical name and that will cause multiple entries in the map Map<String, Object> allAttrs = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); allAttrs.putAll(srcCos.getAttrs());/*from w ww . ja v a 2 s .c o m*/ allAttrs.remove(Provisioning.A_objectClass); allAttrs.remove(Provisioning.A_zimbraId); allAttrs.remove(Provisioning.A_zimbraCreateTimestamp); allAttrs.remove(Provisioning.A_zimbraACE); allAttrs.remove(Provisioning.A_cn); allAttrs.remove(Provisioning.A_description); if (cosAttrs != null) { for (Map.Entry<String, Object> e : cosAttrs.entrySet()) { String attr = e.getKey(); Object value = e.getValue(); if (value instanceof String && Strings.isNullOrEmpty((String) value)) { allAttrs.remove(attr); } else { allAttrs.put(attr, value); } } } CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE); //get rid of deprecated attrs Map<String, Object> allNewAttrs = new HashMap<String, Object>(allAttrs); for (String attr : allAttrs.keySet()) { AttributeInfo info = AttributeManager.getInstance().getAttributeInfo(attr); if (info != null && info.isDeprecated()) { allNewAttrs.remove(attr); } } allAttrs = allNewAttrs; AttributeManager.getInstance().preModify(allAttrs, null, callbackContext, true); ZLdapContext zlc = null; try { zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_COS); ZMutableEntry entry = LdapClient.createMutableEntry(); entry.mapToAttrs(allAttrs); Set<String> ocs = LdapObjectClass.getCosObjectClasses(this); entry.addAttr(A_objectClass, ocs); String zimbraIdStr = LdapUtil.generateUUID(); entry.setAttr(A_zimbraId, zimbraIdStr); entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date())); entry.setAttr(A_cn, destCosName); String dn = mDIT.cosNametoDN(destCosName); entry.setDN(dn); zlc.createEntry(entry); Cos cos = getCosById(zimbraIdStr, zlc); AttributeManager.getInstance().postModify(allAttrs, cos, callbackContext); return cos; } catch (LdapEntryAlreadyExistException nabe) { throw AccountServiceException.COS_EXISTS(destCosName); } catch (LdapException e) { throw e; } catch (AccountServiceException e) { throw e; } catch (ServiceException e) { throw ServiceException.FAILURE("unable to create cos: " + destCosName, e); } finally { LdapClient.closeContext(zlc); } }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.java
public static int compareName(final String name1, final String name2) { if (name1 == name2) { return 0; }/*from ww w. j av a2 s. c o m*/ if (name1 == null) { return -1; } if (name2 == null) { return 1; } return String.CASE_INSENSITIVE_ORDER.compare(name1, name2); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.java
public static int compareOwner(final String owner1, final String owner2) { if (owner1 == owner2) { return 0; }//from www .j a v a2 s . c o m if (owner1 == null) { return -1; } if (owner2 == null) { return 1; } return String.CASE_INSENSITIVE_ORDER.compare(owner1, owner2); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.java
public static int compareComputer(final String computer1, final String computer2) { if (computer1 == computer2) { return 0; }//from ww w.j a v a 2 s. c o m if (computer1 == null) { return -1; } if (computer2 == null) { return 1; } return String.CASE_INSENSITIVE_ORDER.compare(computer1, computer2); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.java
public static int compareSecurityToken(final String securityToken1, final String securityToken2) { if (securityToken1 == securityToken2) { return 0; }/*from w w w . ja v a 2 s . com*/ if (securityToken1 == null) { return -1; } if (securityToken2 == null) { return 1; } return String.CASE_INSENSITIVE_ORDER.compare(securityToken1, securityToken2); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.internal.localworkspace.LocalDataAccessLayer.java
public static void syncPendingChanges(final Workspace workspace, final GetOperation[] getOperations, final String[] itemPropertyFilters) { // This method has two goals in its execution. The primary goal is to // replace the pending changes for the workspace with those that we just // downloaded from the server. The second goal is to make sure that // local version rows for uncommitted items are cleaned up if their // pending changes have disappeared. The server will have already done // this cleanup for us. // We can't remove a pending add from PC and its uncommitted local // version row from LV in a single transaction since they are in // different tables. And we would much rather have an orphaned PC row // than an orphaned LV row. So we will get rid of the local version row // first in this case. (If there are no rows to clean up from LV, we // will not open the table at all.) // To do the scan of the GetOperations to check for this condition, we // need to have the new pending changes in a tree structure. The // LocalPendingChangesTable would do this anyway when we give it the // pending changes -- so we'll cheat a little bit here on the // encapsulation and do the work for it ahead of time, so we can use the // SparseTree for our own check. final AtomicReference<GUID> outServerPendingChangeSignature = new AtomicReference<GUID>(); final PendingChange[] pendingChanges = workspace.getClient().getWebServiceLayer() .queryServerPendingChanges(workspace, outServerPendingChangeSignature); final GUID serverPendingChangeSignature = outServerPendingChangeSignature.get(); final SparseTree<LocalPendingChange> pendingChangesTarget = new SparseTree<LocalPendingChange>( ServerPath.PREFERRED_SEPARATOR_CHARACTER, String.CASE_INSENSITIVE_ORDER); for (final PendingChange pendingChange : pendingChanges) { final LocalPendingChange pcEntry = LocalPendingChange.fromPendingChange(pendingChange); pendingChangesTarget.set(pcEntry.getTargetServerItem(), pcEntry); }/*from w w w .j av a 2 s.c om*/ if (null != getOperations) { final List<KeyValuePair<String, Boolean>> localVersionsToRemove = new ArrayList<KeyValuePair<String, Boolean>>(); final List<String> localVersionsToUpdate = new ArrayList<String>(); for (final GetOperation getOp : getOperations) { // Make sure any adds still have pending changes. The server // will remove the local version row for a pending add when the // pending change is removed, and for a pending branch when we // are syncing an item on top of it. if (getOp.getChangeType().contains(ChangeType.ADD) || (getOp.getChangeType().contains(ChangeType.BRANCH) && null != getOp.getTargetLocalItem())) { final LocalPendingChange pcEntry = pendingChangesTarget.get(getOp.getTargetServerItem()); if (pcEntry == null) { localVersionsToRemove.add(new KeyValuePair<String, Boolean>(getOp.getSourceServerItem(), getOp.getVersionLocal() != 0)); } } // if the server pushed an edit to us, we need to update the // local version if (getOp.getVersionLocal() == -1) { localVersionsToUpdate.add(getOp.getSourceServerItem()); } } if (localVersionsToRemove.size() > 0 || localVersionsToUpdate.size() > 0) { final LocalWorkspaceTransaction lvTrans = new LocalWorkspaceTransaction(workspace); try { lvTrans.execute(new LocalVersionTransaction() { @Override public void invoke(final WorkspaceVersionTable lv) { for (final KeyValuePair<String, Boolean> item : localVersionsToRemove) { lv.removeByServerItem(item.getKey(), item.getValue(), false); } for (final String serverItem : localVersionsToUpdate) { final WorkspaceLocalItem item = lv.getByServerItem(serverItem, true); if (item != null && item.getVersion() != -1) { lv.removeByServerItem(item.getServerItem(), item.isCommitted(), false); item.setVersion(-1); lv.add(item); } } } }); } finally { try { lvTrans.close(); } catch (final IOException e) { throw new VersionControlException(e); } } } } final LocalWorkspaceTransaction transaction = new LocalWorkspaceTransaction(workspace); try { transaction.execute(new PendingChangesTransaction() { @Override public void invoke(final LocalPendingChangesTable pc) { // The method taking a SparseTree is a violation of // encapsulation, but having us build the SparseTree gives // us a perf benefit since we need it earlier in the method. pc.replacePendingChanges(pendingChangesTarget); pc.setClientSignature(serverPendingChangeSignature); } }); } finally { try { transaction.close(); } catch (final IOException e) { throw new VersionControlException(e); } } }
From source file:edu.mit.viral.shen.DroidFish.java
private final String[] findFilesInDirectory(String dirName, final FileNameFilter filter) { File extDir = Environment.getExternalStorageDirectory(); String sep = File.separator; File dir = new File(extDir.getAbsolutePath() + sep + dirName); File[] files = dir.listFiles(new FileFilter() { public boolean accept(File pathname) { if (!pathname.isFile()) return false; return (filter == null) || filter.accept(pathname.getAbsolutePath()); }//from www .j a va 2 s .c o m }); if (files == null) files = new File[0]; final int numFiles = files.length; String[] fileNames = new String[numFiles]; for (int i = 0; i < files.length; i++) fileNames[i] = files[i].getName(); Arrays.sort(fileNames, String.CASE_INSENSITIVE_ORDER); return fileNames; }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
public void selectRemoteShareDlg(final String remurl, String remdir, final NotifyEvent p_ntfy) { NotifyEvent ntfy = new NotifyEvent(mContext); // set thread response ntfy.setListener(new NotifyEventListener() { @Override/*w ww .j a v a2 s. c o m*/ public void positiveResponse(Context c, Object[] o) { final ArrayList<String> rows = new ArrayList<String>(); @SuppressWarnings("unchecked") ArrayList<TreeFilelistItem> rfl = (ArrayList<TreeFilelistItem>) o[0]; for (int i = 0; i < rfl.size(); i++) { if (rfl.get(i).isDir() && rfl.get(i).canRead() && !rfl.get(i).getName().endsWith("$")) // !rfl.get(i).getName().startsWith("IPC$")) rows.add(rfl.get(i).getName().replaceAll("/", "")); } boolean wk_list_empty = false; if (rows.size() < 1) { wk_list_empty = true; rows.add(mContext.getString(R.string.msgs_dir_empty)); } final boolean list_empty = wk_list_empty; Collections.sort(rows, String.CASE_INSENSITIVE_ORDER); //?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.item_select_list_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog .findViewById(R.id.item_select_list_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title); final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(mContext.getString(R.string.msgs_select_remote_share)); subtitle.setVisibility(TextView.GONE); // if (rows.size()<=2) // ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer)) // .setVisibility(TextView.VISIBLE); final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn); final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn); btn_ok.setEnabled(false); CommonDialog.setDlgBoxSizeLimit(dialog, false); final ListView lv = (ListView) dialog.findViewById(android.R.id.list); if (!list_empty) { lv.setAdapter( new ArrayAdapter<String>(mContext, R.layout.custom_simple_list_item_checked, rows)); // android.R.layout.simple_list_item_checked,rows)); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } else { lv.setAdapter(new ArrayAdapter<String>(mContext, R.layout.simple_list_item_1o, rows)); } lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { if (rows.get(idx).startsWith("---")) return; if (!list_empty) btn_ok.setEnabled(true); } }); //CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, null); } }); //OK? btn_ok.setVisibility(Button.VISIBLE); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); SparseBooleanArray checked = lv.getCheckedItemPositions(); for (int i = 0; i <= rows.size(); i++) { if (checked.get(i) == true) { p_ntfy.notifyToListener(true, new Object[] { rows.get(i) }); break; } } } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); } @Override public void negativeResponse(Context c, Object[] o) { p_ntfy.notifyToListener(false, o); } }); createRemoteFileList(remurl, remdir, ntfy, false); }
From source file:sg.ncl.MainController.java
@RequestMapping("/admin/usage") public String adminTeamUsage(Model model, @RequestParam(value = "start", required = false) String start, @RequestParam(value = "end", required = false) String end, @RequestParam(value = "organizationType", required = false) String organizationType, @RequestParam(value = "team", required = false) String team, final RedirectAttributes redirectAttributes, HttpSession session) throws IOException, WebServiceRuntimeException { if (!validateIfAdmin(session)) { return NO_PERMISSION_PAGE; }// ww w .j av a 2 s. com DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); ZonedDateTime nowDate = ZonedDateTime.now(); String now = nowDate.format(formatter); if (start == null) { start = nowDate.with(firstDayOfMonth()).format(formatter); } if (end == null) { end = now; } if (now.compareTo(start) < 0 || now.compareTo(end) < 0) { redirectAttributes.addFlashAttribute(MESSAGE, "Period selected is beyond current date (today)."); return REDIRECT_TEAM_USAGE; } // get list of teamids HttpEntity<String> request = createHttpEntityHeaderOnly(); ResponseEntity responseEntity = restTemplate.exchange(properties.getSioTeamsUrl(), HttpMethod.GET, request, String.class); JSONArray jsonArray = new JSONArray(responseEntity.getBody().toString()); List<Team2> searchTeams = new ArrayList<>(); TeamManager2 teamManager2 = new TeamManager2(); getSearchTeams(organizationType, team, jsonArray, searchTeams, teamManager2); if (!searchTeams.isEmpty()) { List<String> dates = getDates(start, end, formatter); Map<String, List<Long>> teamUsages = new HashMap<>(); Long totalUsage = 0L; for (Team2 team2 : searchTeams) { try { List<Long> usages = new ArrayList<>(); totalUsage += getTeamUsageStatistics(team2, start, end, request, usages); teamUsages.put(team2.getName(), usages); } catch (RestClientException rce) { log.warn("Error connecting to sio analytics service for team usage: {}", rce); redirectAttributes.addFlashAttribute(MESSAGE, ERR_SERVER_OVERLOAD); return REDIRECT_TEAM_USAGE; } catch (StartDateAfterEndDateException sde) { redirectAttributes.addFlashAttribute(MESSAGE, ERR_START_DATE_AFTER_END_DATE); return REDIRECT_TEAM_USAGE; } } model.addAttribute("dates", dates); model.addAttribute("teamUsages", teamUsages); model.addAttribute("totalUsage", totalUsage); } List<Team2> allTeams = new ArrayList<>(teamManager2.getTeamMap().values()); allTeams.sort(Comparator.comparing(Team2::getName, String.CASE_INSENSITIVE_ORDER)); model.addAttribute(ALL_TEAMS, allTeams); model.addAttribute("start", start); model.addAttribute("end", end); model.addAttribute("organizationType", organizationType); model.addAttribute("team", team); return "usage_statistics"; }