List of usage examples for java.util TreeMap isEmpty
boolean isEmpty();
From source file:com.alibaba.rocketmq.tools.command.consumer.ConsumerSubCommand.java
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try {/*from ww w . j ava 2 s. c o m*/ defaultMQAdminExt.start(); String group = commandLine.getOptionValue('g').trim(); ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group); boolean jstack = commandLine.hasOption('s'); if (!commandLine.hasOption('i')) { int i = 1; long now = System.currentTimeMillis(); final TreeMap<String/* clientId */, ConsumerRunningInfo> criTable = new TreeMap<String, ConsumerRunningInfo>(); for (Connection conn : cc.getConnectionSet()) { try { ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(group, conn.getClientId(), jstack); if (consumerRunningInfo != null) { criTable.put(conn.getClientId(), consumerRunningInfo); String filePath = now + "/" + conn.getClientId(); MixAll.string2FileNotSafe(consumerRunningInfo.formatString(), filePath); System.out.printf("%03d %-40s %-20s %s%n", // i++, // conn.getClientId(), // MQVersion.getVersionDesc(conn.getVersion()), // filePath); } } catch (Exception e) { e.printStackTrace(); } } if (!criTable.isEmpty()) { boolean subSame = ConsumerRunningInfo.analyzeSubscription(criTable); boolean rebalanceOK = subSame && ConsumerRunningInfo.analyzeRebalance(criTable); if (subSame) { System.out.println("%n%nSame subscription in the same group of consumer"); System.out.printf("%n%nRebalance %s%n", rebalanceOK ? "OK" : "Failed"); Iterator<Entry<String, ConsumerRunningInfo>> it = criTable.entrySet().iterator(); while (it.hasNext()) { Entry<String, ConsumerRunningInfo> next = it.next(); String result = ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue()); if (result.length() > 0) { System.out.println(result); } } } else { System.out.println("\n\nWARN: Different subscription in the same group of consumer!!!"); } } } else { String clientId = commandLine.getOptionValue('i').trim(); ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(group, clientId, jstack); if (consumerRunningInfo != null) { System.out.println(consumerRunningInfo.formatString()); } } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
From source file:net.opentsdb.tree.Tree.java
/** * Retrieves a single rule from the rule set given a level and order * @param level The level where the rule resides * @param order The order in the level where the rule resides * @return The rule if found, null if not found *///from w ww . j av a2 s . co m public TreeRule getRule(final int level, final int order) { if (rules == null || rules.isEmpty()) { return null; } TreeMap<Integer, TreeRule> rule_level = rules.get(level); if (rule_level == null || rule_level.isEmpty()) { return null; } return rule_level.get(order); }
From source file:com.alibaba.rocketmq.tools.command.consumer.ConsumerStatusSubCommand.java
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try {//from ww w . j a v a 2 s . co m defaultMQAdminExt.start(); String group = commandLine.getOptionValue('g').trim(); ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group); boolean jstack = commandLine.hasOption('s'); if (!commandLine.hasOption('i')) { // ? int i = 1; long now = System.currentTimeMillis(); final TreeMap<String/* clientId */, ConsumerRunningInfo> criTable = new TreeMap<String, ConsumerRunningInfo>(); for (Connection conn : cc.getConnectionSet()) { try { ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(group, conn.getClientId(), jstack); if (consumerRunningInfo != null) { criTable.put(conn.getClientId(), consumerRunningInfo); String filePath = now + "/" + conn.getClientId(); MixAll.string2FileNotSafe(consumerRunningInfo.formatString(), filePath); System.out.printf("%03d %-40s %-20s %s\n", // i++, // conn.getClientId(), // MQVersion.getVersionDesc(conn.getVersion()), // filePath); } } catch (Exception e) { e.printStackTrace(); } } if (!criTable.isEmpty()) { boolean subSame = ConsumerRunningInfo.analyzeSubscription(criTable); boolean rebalanceOK = subSame && ConsumerRunningInfo.analyzeRebalance(criTable); if (subSame) { System.out.println("\n\nSame subscription in the same group of consumer"); System.out.printf("\n\nRebalance %s\n", rebalanceOK ? "OK" : "Failed"); Iterator<Entry<String, ConsumerRunningInfo>> it = criTable.entrySet().iterator(); while (it.hasNext()) { Entry<String, ConsumerRunningInfo> next = it.next(); String result = ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue()); if (result.length() > 0) { System.out.println(result); } } } else { System.out.println("\n\nWARN: Different subscription in the same group of consumer!!!"); } } } else { String clientId = commandLine.getOptionValue('i').trim(); ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(group, clientId, jstack); if (consumerRunningInfo != null) { System.out.println(consumerRunningInfo.formatString()); } } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
From source file:de.uzk.hki.da.sb.SIPFactory.java
/** * Creates a list of source folders/* w w w .ja v a 2 s . c o m*/ * * @param folderPath * The main source folder path * @throws Exception */ HashMap<File, String> createFolderList(String folderPath) throws Exception { HashMap<File, String> folderListWithFolderNames = new HashMap<File, String>(); File sourceFolder = new File(folderPath); switch (kindofSIPBuilding) { case MULTIPLE_FOLDERS: List<File> folderContent = Arrays.asList(sourceFolder.listFiles()); for (File file : folderContent) { if (!file.isHidden() && file.isDirectory()) folderListWithFolderNames.put(file, null); } break; case SINGLE_FOLDER: folderListWithFolderNames.put(sourceFolder, null); break; case NESTED_FOLDERS: NestedContentStructure ncs; try { TreeMap<File, String> metadataFileWithType = new FormatDetectionService(sourceFolder) .getMetadataFileWithType(); if (!metadataFileWithType.isEmpty() && (!metadataFileWithType.get(metadataFileWithType.firstKey()) .equals(C.CB_PACKAGETYPE_METS))) { messageWriter.showMessage("Es wurde eine Metadatendatei des Typs " + metadataFileWithType.get(metadataFileWithType.firstKey()) + " auf der obersten Ebene gefunden. " + "\nBitte whlen Sie diese Option ausschlielich fr die Erstellung von SIPs des Typs METS."); } else { ncs = new NestedContentStructure(sourceFolder); folderListWithFolderNames = ncs.getSipCandidates(); if (folderListWithFolderNames.isEmpty()) { messageWriter.showMessage( "Es wurde kein Unterverzeichnis mit einer METS-Metadatendatei gefunden."); } break; } } catch (IOException e) { throw new Exception(e); } default: break; } return folderListWithFolderNames; }
From source file:net.spfbl.core.Core.java
public static String getSequence(TreeMap<String, Boolean> map, String demiliter) { if (map == null) { return null; } else if (demiliter == null) { return null; } else if (map.isEmpty()) { return null; } else {//ww w . j ava 2 s . c om StringBuilder builder = new StringBuilder(); for (String key : map.keySet()) { boolean value = map.get(key); if (builder.length() > 0) { builder.append(demiliter); } builder.append(key); builder.append('='); builder.append(value); } return builder.toString(); } }
From source file:cx.ring.service.LocalService.java
public void updateTextNotifications() { Log.d(TAG, "updateTextNotifications()"); for (Conversation c : conversations.values()) { TreeMap<Long, TextMessage> texts = c.getUnreadTextMessages(); if (texts.isEmpty() || texts.lastEntry().getValue().isNotified()) { continue; } else//from w ww. j av a2s.c o m notificationManager.cancel(c.notificationId); CallContact contact = c.getContact(); if (c.notificationBuilder == null) { c.notificationBuilder = new NotificationCompat.Builder(getApplicationContext()); c.notificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH).setDefaults(NotificationCompat.DEFAULT_ALL) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(contact.getDisplayName()); } NotificationCompat.Builder noti = c.notificationBuilder; Intent c_intent = new Intent(Intent.ACTION_VIEW).setClass(this, ConversationActivity.class) .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, contact.getIds().get(0))); Intent d_intent = new Intent(ACTION_CONV_READ).setClass(this, LocalService.class) .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, contact.getIds().get(0))); noti.setContentIntent(PendingIntent.getActivity(this, new Random().nextInt(), c_intent, 0)) .setDeleteIntent(PendingIntent.getService(this, new Random().nextInt(), d_intent, 0)); if (contact.getPhoto() != null) { Resources res = getResources(); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width); noti.setLargeIcon(Bitmap.createScaledBitmap(contact.getPhoto(), width, height, false)); } if (texts.size() == 1) { TextMessage txt = texts.firstEntry().getValue(); txt.setNotified(true); noti.setContentText(txt.getMessage()); noti.setStyle(null); noti.setWhen(txt.getTimestamp()); } else { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); for (TextMessage s : texts.values()) { inboxStyle.addLine(Html.fromHtml("<b>" + DateUtils.formatDateTime(this, s.getTimestamp(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL) + "</b> " + s.getMessage())); s.setNotified(true); } noti.setContentText(texts.lastEntry().getValue().getMessage()); noti.setStyle(inboxStyle); noti.setWhen(texts.lastEntry().getValue().getTimestamp()); } notificationManager.notify(c.notificationId, noti.build()); } }
From source file:net.spfbl.core.Reverse.java
public static ArrayList<String> getMXSet(String host) throws NamingException { TreeMap<Integer, TreeSet<String>> mxMap = new TreeMap<Integer, TreeSet<String>>(); Attributes atributes = Server.getAttributesDNS(host, new String[] { "MX" }); if (atributes == null || atributes.size() == 0) { atributes = Server.getAttributesDNS(host, new String[] { "CNAME" }); Attribute attribute = atributes.get("CNAME"); if (attribute != null) { String cname = (String) attribute.get(0); return getMXSet(cname); }/* w ww . ja va 2s . c o m*/ } else { Attribute attribute = atributes.get("MX"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { try { String mx = (String) attribute.get(index); int space = mx.indexOf(' '); String value = mx.substring(0, space); int priority = Integer.parseInt(value); mx = mx.substring(space + 1); int last = mx.length() - 1; TreeSet<String> mxSet = mxMap.get(priority); if (mxSet == null) { mxSet = new TreeSet<String>(); mxMap.put(priority, mxSet); } if (Subnet.isValidIP(mx.substring(0, last))) { mxSet.add(Subnet.normalizeIP(mx.substring(0, last))); } else if (Domain.isHostname(mx)) { mxSet.add(Domain.normalizeHostname(mx, true)); } } catch (NumberFormatException ex) { } } } } ArrayList<String> mxList = new ArrayList<String>(); if (mxMap.isEmpty()) { // https://tools.ietf.org/html/rfc5321#section-5 mxList.add(Domain.normalizeHostname(host, true)); } else { for (int priority : mxMap.keySet()) { TreeSet<String> mxSet = mxMap.get(priority); for (String mx : mxSet) { if (!mxList.contains(mx)) { mxList.add(mx); } } } } return mxList; }
From source file:com.l2jfree.sql.L2DatabaseInstaller.java
public static void check() throws SAXException, IOException, ParserConfigurationException { final TreeMap<String, String> tables = new TreeMap<String, String>(); final TreeMap<Double, String> updates = new TreeMap<Double, String>(); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); // FIXME add validation factory.setIgnoringComments(true);// ww w.j a v a 2s . c o m final List<Document> documents = new ArrayList<Document>(); InputStream is = null; try { // load default database schema from resources is = L2DatabaseInstaller.class.getResourceAsStream("database_schema.xml"); documents.add(factory.newDocumentBuilder().parse(is)); } finally { IOUtils.closeQuietly(is); } final File f = new File("./config/database_schema.xml"); // load optional project specific database tables/updates (fails on already existing) if (f.exists()) documents.add(factory.newDocumentBuilder().parse(f)); for (Document doc : documents) { for (Node n1 : L2XML.listNodesByNodeName(doc, "database")) { for (Node n2 : L2XML.listNodesByNodeName(n1, "table")) { final String name = L2XML.getAttribute(n2, "name"); final String definition = L2XML.getAttribute(n2, "definition"); final String oldDefinition = tables.put(name, definition); if (oldDefinition != null) throw new RuntimeException("Found multiple tables with name " + name + "!"); } for (Node n2 : L2XML.listNodesByNodeName(n1, "update")) { final Double revision = Double.valueOf(L2XML.getAttribute(n2, "revision")); final String query = L2XML.getAttribute(n2, "query"); final String oldQuery = updates.put(revision, query); if (oldQuery != null) throw new RuntimeException("Found multiple updates with revision " + revision + "!"); } } } createRevisionTable(); final double databaseRevision = getDatabaseRevision(); if (databaseRevision == -1) // no table exists { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); installTable(tableName, tableDefinition); } if (updates.isEmpty()) insertRevision(0); else insertRevision(updates.lastKey()); } else // check for possibly required updates { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); if (L2Database.tableExists(tableName)) continue; System.err.println("Table '" + tableName + "' is missing, so the server attempts to install it."); System.err.println("WARNING! It's highly recommended to check the results manually."); installTable(tableName, tableDefinition); } for (Entry<Double, String> update : updates.entrySet()) { final double updateRevision = update.getKey(); final String updateQuery = update.getValue(); if (updateRevision > databaseRevision) { executeUpdate(updateQuery); insertRevision(updateRevision); } } } }
From source file:org.apache.hadoop.mapred.HFSPScheduler.java
/** Create a first estimation of the job duration based on available data */ private JobDurationInfo createInitialJobDurationInfo(JobInProgress jip, TaskType type) { TreeMap<JobDurationInfo, JobInProgress> sizeBasedJobQueue = this.getSizeBasedJobQueue(type); long singleTaskDuration = 0; if (!sizeBasedJobQueue.isEmpty()) { long taskDuration = 0; int trained = 0; for (Entry<JobDurationInfo, JobInProgress> entry : sizeBasedJobQueue.entrySet()) { if (this.isTrained(entry.getValue(), type)) { JobDurationInfo jdi = entry.getKey(); int numVirtualTasks = jdi.getTasks().size(); if (entry.getKey().getPhaseTotalDuration() > 0 && numVirtualTasks > 0) { trained += 1;// w ww . j a v a 2 s . co m taskDuration += Math.ceil(entry.getKey().getPhaseTotalDuration() / numVirtualTasks); } } } if (trained > 0) { singleTaskDuration = (long) Math.ceil(taskDuration / trained); } } if (singleTaskDuration == 0) { singleTaskDuration = (type == TaskType.MAP) ? initialMapTaskDuration : initialReduceTaskDuration; } float durationModifier = (type == TaskType.MAP) ? this.durationModifierMap : this.durationModifierReduce; LOG.debug(jip.getJobID() + ":" + type + " singleTaskDuration: " + singleTaskDuration + " durationModifier: " + durationModifier + " => singleTaskDuration: " + (long) (singleTaskDuration * durationModifier)); singleTaskDuration = (long) (singleTaskDuration * durationModifier); return new UniformJobDurationInfo(jip, singleTaskDuration, type); }
From source file:org.xwiki.repository.internal.RepositoryManager.java
public DocumentReference importExtension(String extensionId, ExtensionRepository repository, Type type) throws QueryException, XWikiException, ResolveException { TreeMap<Version, String> versions = new TreeMap<Version, String>(); Version lastVersion = getVersions(extensionId, repository, type, versions); if (lastVersion == null) { throw new ExtensionNotFoundException("Can't find any version for the extension [" + extensionId + "] on repository [" + repository + "]"); } else if (versions.isEmpty()) { // If no valid version import the last version versions.put(lastVersion, extensionId); } else {/*w w w .ja v a 2s . co m*/ // Select the last valid version lastVersion = versions.lastKey(); } Extension extension = repository.resolve(new ExtensionId(extensionId, lastVersion)); // Get former ids versions Collection<ExtensionId> features = extension.getExtensionFeatures(); for (ExtensionId feature : features) { try { getVersions(feature.getId(), repository, type, versions); } catch (ResolveException e) { // Ignore } } XWikiContext xcontext = this.xcontextProvider.get(); boolean needSave = false; XWikiDocument document = getExistingExtensionDocumentById(extensionId); if (document == null) { // Create document document = xcontext.getWiki().getDocument(new DocumentReference(xcontext.getWikiId(), Arrays.asList("Extension", extension.getName()), "WebHome"), xcontext); for (int i = 1; !document.isNew(); ++i) { document = xcontext.getWiki().getDocument(new DocumentReference(xcontext.getWikiId(), Arrays.asList("Extension", extension.getName() + ' ' + i), "WebHome"), xcontext); } document.readFromTemplate( this.currentResolver.resolve(XWikiRepositoryModel.EXTENSION_TEMPLATEREFERENCE), xcontext); needSave = true; } // Update document BaseObject extensionObject = document.getXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE); if (extensionObject == null) { extensionObject = document.newXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE, xcontext); needSave = true; } if (!StringUtils.equals(extensionId, getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ID, (String) null))) { extensionObject.set(XWikiRepositoryModel.PROP_EXTENSION_ID, extensionId, xcontext); needSave = true; } // Update extension informations needSave |= updateExtension(extension, extensionObject, xcontext); // Proxy marker BaseObject extensionProxyObject = document.getXObject(XWikiRepositoryModel.EXTENSIONPROXY_CLASSREFERENCE); if (extensionProxyObject == null) { extensionProxyObject = document.newXObject(XWikiRepositoryModel.EXTENSIONPROXY_CLASSREFERENCE, xcontext); extensionProxyObject.setIntValue(XWikiRepositoryModel.PROP_PROXY_AUTOUPDATE, 1); needSave = true; } needSave |= update(extensionProxyObject, XWikiRepositoryModel.PROP_PROXY_REPOSITORYID, repository.getDescriptor().getId()); needSave |= update(extensionProxyObject, XWikiRepositoryModel.PROP_PROXY_REPOSITORYTYPE, repository.getDescriptor().getType()); needSave |= update(extensionProxyObject, XWikiRepositoryModel.PROP_PROXY_REPOSITORYURI, repository.getDescriptor().getURI().toString()); // Remove unexisting versions Set<String> validVersions = new HashSet<String>(); List<BaseObject> versionObjects = document .getXObjects(XWikiRepositoryModel.EXTENSIONVERSION_CLASSREFERENCE); if (versionObjects != null) { for (BaseObject versionObject : versionObjects) { if (versionObject != null) { String version = getValue(versionObject, XWikiRepositoryModel.PROP_VERSION_VERSION); if (StringUtils.isBlank(version) || (isVersionProxyingEnabled(document) && !new DefaultVersion(version).equals(extension.getId().getVersion()))) { // Empty version OR old versions should be proxied document.removeXObject(versionObject); needSave = true; } else { if (!versions.containsKey(new DefaultVersion(version))) { // The version does not exist on remote repository if (!isVersionValid(document, versionObject, xcontext)) { // The version is invalid, removing it to not make the whole extension invalid document.removeXObject(versionObject); needSave = true; } else { // The version is valid, lets keep it validVersions.add(version); } } else { // This version exist on remote repository validVersions.add(version); } } } } } List<BaseObject> dependencyObjects = document .getXObjects(XWikiRepositoryModel.EXTENSIONDEPENDENCY_CLASSREFERENCE); if (dependencyObjects != null) { for (BaseObject dependencyObject : dependencyObjects) { if (dependencyObject != null) { String version = getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_EXTENSIONVERSION); if (!validVersions.contains(version)) { // The version is invalid, removing it to not make the whole extension invalid document.removeXObject(dependencyObject); needSave = true; } } } } // Update versions for (Map.Entry<Version, String> entry : versions.entrySet()) { Version version = entry.getKey(); String id = entry.getValue(); try { Extension versionExtension; if (version.equals(extension.getId().getVersion())) { versionExtension = extension; } else if (isVersionProxyingEnabled(document)) { continue; } else { versionExtension = repository.resolve(new ExtensionId(id, version)); } // Update version related informations needSave |= updateExtensionVersion(document, versionExtension); } catch (Exception e) { this.logger.error("Failed to resolve extension with id [" + id + "] and version [" + version + "] on repository [" + repository + "]", e); } } if (needSave) { document.setAuthorReference(xcontext.getUserReference()); if (document.isNew()) { document.setContentAuthorReference(xcontext.getUserReference()); document.setCreatorReference(xcontext.getUserReference()); } xcontext.getWiki().saveDocument(document, "Imported extension [" + extensionId + "] from repository [" + repository.getDescriptor() + "]", true, xcontext); } return document.getDocumentReference(); }