List of usage examples for java.util TreeSet size
public int size()
From source file:com.miz.mizuu.fragments.CoverSearchFragment.java
private void showContent() { mProgressBar.setVisibility(View.GONE); mAdapter.notifyDataSetChanged();//from www . j ava2s .co m TreeSet<String> languages = new TreeSet<String>(); for (int i = 0; i < mCovers.size(); i++) if (!mCovers.get(i).getLanguage().equals("Null")) languages.add(mCovers.get(i).getLanguage()); mItems = new String[languages.size() + 1]; mItems[0] = getString(R.string.stringShowAllLanguages); Iterator<String> itr = languages.iterator(); int i = 1; while (itr.hasNext()) { mItems[i] = itr.next(); i++; } getActivity().invalidateOptionsMenu(); }
From source file:org.apache.hadoop.hdfs.hoss.db.ObjectsMap.java
public void append(TreeSet<String> deletedObjs) throws IOException { long start = System.currentTimeMillis(); reader.close();/*from ww w . ja va 2 s. co m*/ File index = new File(dir, HosMetaData.INDEXFILE); HosWriter writer = Hos.append(index); if (deletedObjs.size() != 0) { for (String obj : deletedObjs) { writer.delete(obj); } } System.out.println("memMap size " + memMap.size()); //flush memory data to hos.spl putAll(memMap, writer); memMap.clear(); //writer.flush(); writer.writeHash(); writer.close(); try { reader = Hos.open(index); } catch (IOException e) { e.printStackTrace(); } LOG.info("flush memory data to hos.spl using " + (System.currentTimeMillis() - start) + " ms"); }
From source file:org.opensextant.solrtexttagger.AbstractTaggerTest.java
/** Asserts the sorted arrays are equals, with a helpful error message when not. * @param message//from www .j ava 2s. c o m * @param expecteds * @param actuals */ public void assertSortedArrayEquals(String message, Object[] expecteds, Object[] actuals) { AssertionError error = null; try { assertArrayEquals(null, expecteds, actuals); } catch (AssertionError e) { error = e; } if (error == null) return; TreeSet<Object> expectedRemaining = new TreeSet<>(Arrays.asList(expecteds)); expectedRemaining.removeAll(Arrays.asList(actuals)); if (!expectedRemaining.isEmpty()) fail(message + ": didn't find expected " + expectedRemaining.first() + " (of " + expectedRemaining.size() + "); " + error); TreeSet<Object> actualsRemaining = new TreeSet<>(Arrays.asList(actuals)); actualsRemaining.removeAll(Arrays.asList(expecteds)); fail(message + ": didn't expect " + actualsRemaining.first() + " (of " + actualsRemaining.size() + "); " + error); }
From source file:com.chingo247.structureapi.commands.StructureCommands.java
private static void showOwnerships(ICommandSender sender, CommandContext args, IStructureAPI structureAPI, OwnerType type) throws CommandException { IColors COLOR = structureAPI.getPlatform().getChatColors(); GraphDatabaseService graph = SettlerCraft.getInstance().getNeo4j(); TreeSet<String> ownerships = Sets.newTreeSet(ALPHABETICAL_ORDER); String structureName = null;/*from w w w . j av a 2 s . c o m*/ Long structureId; try (Transaction tx = graph.beginTx()) { StructureNode structure = getStructure(args, tx); structureName = structure.getName(); structureId = structure.getId(); for (SettlerNode member : structure.getOwnerDomain().getOwners(type)) { ownerships.add(member.getName()); } tx.success(); } String ownershipString = ""; int size = ownerships.size(); if (size != 0) { int count = 0; for (String ownership : ownerships) { ownershipString += COLOR.yellow() + ownership + COLOR.reset(); count++; if (count != size) { ownershipString += ", "; } } } else { ownershipString = "None"; } String ownersString; if (type == OwnerType.MASTER) { ownersString = "Masters: "; } else if (type == OwnerType.OWNER) { ownersString = "Owners: "; } else { ownersString = "Members: "; } if (size == 0) { sender.sendMessage("#" + COLOR.gold() + structureId + " - " + COLOR.blue() + structureName, COLOR.reset() + ownersString + COLOR.red() + ownershipString); } else { sender.sendMessage("#" + COLOR.gold() + structureId + " - " + COLOR.blue() + structureName, COLOR.reset() + ownersString, ownershipString); } }
From source file:com.miz.mizuu.fragments.CollectionCoverSearchFragment.java
private void showContent() { mProgressBar.setVisibility(View.GONE); mAdapter.notifyDataSetChanged();/*from w w w . j av a 2 s . c o m*/ TreeSet<String> languages = new TreeSet<String>(); for (int i = 0; i < mCovers.size(); i++) { if (!mCovers.get(i).getLanguage().equals("Null")) languages.add(mCovers.get(i).getLanguage()); } mItems = new String[languages.size() + 1]; mItems[0] = getString(R.string.stringShowAllLanguages); Iterator<String> itr = languages.iterator(); int i = 1; while (itr.hasNext()) { mItems[i] = itr.next(); i++; } getActivity().invalidateOptionsMenu(); }
From source file:com.taobao.common.tfs.impl.LocalKey.java
public int getSegmentForRead(List<SegmentData> segmentDataList, long offset, byte[] data, int start, int length) { if (offset > segmentHead.getSegmentLength()) { log.error("read offset over file length: " + offset + " > " + segmentHead.getSegmentLength()); return 0; }//www. java 2 s. c om // To read, segment info SHOULD and MUST be adjacent and completed // but not check here ... SegmentInfo segmentInfo = new SegmentInfo(); int checkLength = 0; int currentLength = 0; segmentDataList.clear(); segmentInfo.setOffset(offset); TreeSet<SegmentInfo> tailInfoSet = (TreeSet<SegmentInfo>) segmentInfoSet.tailSet(segmentInfo); if (tailInfoSet.size() == 0 || tailInfoSet.first().getOffset() != offset) { TreeSet<SegmentInfo> headInfoSet = (TreeSet<SegmentInfo>) segmentInfoSet.headSet(segmentInfo); // should NEVER happen: queried offset less than least offset(0) in stored segment info if (headInfoSet.size() == 0) { log.error("can not find segment for offset: " + offset); return TfsConstant.EXIT_GENERAL_ERROR; } SegmentInfo endInfo = headInfoSet.last(); // actually SHOULD always occur, cause adjacent and completed read segment info if (endInfo.getOffset() + endInfo.getLength() > offset) { checkLength = (int) Math.min(length, endInfo.getOffset() + endInfo.getLength() - offset); SegmentData segmentData = new SegmentData(endInfo); segmentData.setInnerOffset((int) (offset - endInfo.getOffset())); segmentData.setData(data, start, checkLength); segmentDataList.add(segmentData); } } // get following adjacent segment info Iterator it = tailInfoSet.iterator(); while (segmentDataList.size() < ClientConfig.BATCH_COUNT && checkLength < length && it.hasNext()) { segmentInfo = (SegmentInfo) it.next(); currentLength = Math.min(segmentInfo.getLength(), length - checkLength); SegmentData segmentData = new SegmentData(segmentInfo); segmentData.setData(data, start + checkLength, currentLength); segmentDataList.add(segmentData); checkLength += currentLength; } return checkLength; }
From source file:com.taobao.common.tfs.impl.LocalKey.java
public int getSegmentForWrite(List<SegmentData> segmentDataList, long offset, byte[] data, int start, int length) { long currentOffset = offset; int currentStart = start; int remainLength = length, writtenLength = 0, needWriteLength = 0, remainNwLength = 0, // remain_need_write_length totalLength = 0;//from www . j a v a 2 s .c o m List<SegmentInfo> gcSegmentList = new ArrayList<SegmentInfo>(); SegmentInfo segmentInfo = new SegmentInfo(); segmentDataList.clear(); while (segmentDataList.size() < ClientConfig.BATCH_COUNT && remainLength > 0) { writtenLength = needWriteLength = 0; remainNwLength = Math.min( (ClientConfig.BATCH_COUNT - segmentDataList.size()) * ClientConfig.SEGMENT_LENGTH, remainLength); segmentInfo.setOffset(currentOffset); TreeSet<SegmentInfo> tailInfoSet = (TreeSet<SegmentInfo>) segmentInfoSet.tailSet(segmentInfo); if (tailInfoSet.size() == 0) { needWriteLength = remainNwLength; checkOverlap(segmentInfo, gcSegmentList); } else { SegmentInfo firstInfo = tailInfoSet.first(); if (firstInfo.getOffset() != currentOffset) { needWriteLength = (int) (firstInfo.getOffset() - currentOffset); checkOverlap(segmentInfo, gcSegmentList); } if (needWriteLength > remainNwLength) { needWriteLength = remainNwLength; } else { Iterator it = tailInfoSet.iterator(); remainNwLength -= needWriteLength; while (remainNwLength > 0 && it.hasNext()) { SegmentInfo curInfo = (SegmentInfo) it.next(); int tmpCrc = 0, curLength = curInfo.getLength(); if (remainNwLength < curLength) { log.info("segment length conflict: " + curLength + " <> " + remainNwLength); needWriteLength += remainNwLength; remainNwLength = 0; } else if ((tmpCrc = TfsUtil.crc32(0, data, currentStart + needWriteLength, curLength)) != curInfo.getCrc()) { log.info("segment crc conflict: " + curInfo.getCrc() + " <> " + tmpCrc); needWriteLength += curLength; remainNwLength -= curLength; } else { // full segment crc is correct use it log.debug("segment data written: " + curInfo); writtenLength += curLength; remainNwLength = 0; break; } gcSegmentList.add(curInfo); } if (!it.hasNext()) { needWriteLength += remainNwLength; } } } getSegment(segmentDataList, currentOffset, data, currentStart, needWriteLength); totalLength = needWriteLength + writtenLength; remainLength -= totalLength; currentStart += totalLength; currentOffset += totalLength; gcSegment(gcSegmentList); } return (length - remainLength); }
From source file:org.dasein.cloud.util.APITrace.java
static public String[] listApis(@Nonnull String provider, @Nonnull String cloud) { provider = provider.replaceAll(DELIMITER_REGEX, "_"); cloud = cloud.replaceAll(DELIMITER_REGEX, "_"); TreeSet<String> list = new TreeSet<String>(); synchronized (apiCount) { for (String call : apiCount.keySet()) { String[] parts = call.split(DELIMITER_REGEX); if (parts.length > 3 && parts[0].equals(provider) && parts[1].equals(cloud)) { if (parts.length == 4) { list.add(parts[3]);/*from w ww .j a va 2 s. c o m*/ } else { StringBuilder tmp = new StringBuilder(); for (int i = 3; i < parts.length; i++) { tmp.append(parts[i]); if (i < parts.length - 1) { tmp.append(DELIMITER); } } list.add(tmp.toString()); } } } } return list.toArray(new String[list.size()]); }
From source file:de.tudarmstadt.tk.statistics.test.StatsProcessor.java
/** * Determine order of significant differences between models Cf. Eugster, M. * J. A., Hothorn, T., & Leisch, F. (2008). Exploratory and inferential * analysis of benchmark experiments. Retrieved from * http://epub.ub.uni-muenchen.de/4134/ Determine topological ordering of a * DAG of the significance model-pairs. In addition to Eugster et al., we * also check whether relations between topological groups are valid. * * /*from w w w.j a v a 2 s .c om*/ * @return a HashMap mapping from levels of the topological ordering to the * models on that level */ private HashMap<Integer, TreeSet<Integer>> calcOrderOfSignificantDifferences( ImprovedDirectedGraph<Integer, DefaultEdge> directedGraph) { // If nodes are on the same level of the graph, they are not // significantly different and form a group // One higher group is significantly different from all lower groups as // a whole (!), if there exists an edge from each element of the higher // group to each element of the lower groups HashMap<Integer, TreeSet<Integer>> ordering = directedGraph.getTopologicalOrder(); int nodesLeft = 0; for (TreeSet<Integer> s : ordering.values()) { nodesLeft += s.size(); } for (int level = 0; level < ordering.keySet().size() - 1; level++) { TreeSet<Integer> nodes = ordering.get(level); nodesLeft -= nodes.size(); for (Integer n : nodes) { if (directedGraph.outDegreeOf(n) != nodesLeft) { // Not a valid ordering return null; } } } return ordering; }
From source file:com.BibleQuote.ui.ReaderActivity.java
@Override public void onReaderViewChange(ChangeCode code) { if (code == ChangeCode.onChangeReaderMode) { updateActivityMode();//from w ww.j a v a2 s . com } else if (code == ChangeCode.onUpdateText || code == ChangeCode.onScroll) { viewChapterNav(); } else if (code == ChangeCode.onChangeSelection) { TreeSet<Integer> selVerses = vWeb.getSelectedVerses(); if (selVerses.size() == 0) { disableActionMode(); } else if (currActionMode == null) { currActionMode = startActionMode(new ActionSelectText()); } } else if (code == ChangeCode.onLongPress) { viewChapterNav(); if (vWeb.getMode() == ReaderWebView.Mode.Read) onChooseChapterClick(); } else if (code == ChangeCode.onUpNavigation) { vWeb.pageUp(false); } else if (code == ChangeCode.onDownNavigation) { vWeb.pageDown(false); } else if (code == ChangeCode.onLeftNavigation) { prevChapter(); } else if (code == ChangeCode.onRightNavigation) { nextChapter(); } }