@Test public void WriteDBInt_lastKey_set_middle() { int numberOfRecords = 1000; /* Creates connections to MapDB */ DB db1 = DBMaker.memoryDB().transactionDisable().make(); /* Creates maps */ NavigableSet<Integer> map1 = db1.treeSet("column1"); /* Inserts initial values in maps */ for (int i = 0; i < numberOfRecords; i++) { map1.add(i); } assertEquals((Object) (numberOfRecords - 1), map1.last()); map1.clear(); /* Inserts some values in maps */ for (int i = 100; i < 110; i++) { map1.add(i); } assertEquals(10, map1.size()); assertFalse(map1.isEmpty()); assertEquals((Object) 109, map1.last()); assertEquals((Object) 100, map1.first()); }
@Test public void testUnsignedTreeSetSerializable() { NavigableSet<Integer> set = new TreeSet<>( (Comparator<Integer> & Serializable) ((x, y) -> Integer.compareUnsigned(x, y))); set.addAll(Arrays.asList(-100, 0, 100)); assertEquals(0, set.first().intValue()); assertEquals(-100, set.last().intValue()); byte[] serializedSet = writeSetToBytes(set, true); NavigableSet<Integer> set1 = readSetFromBytes(serializedSet); assertEquals(0, set1.first().intValue()); assertEquals(-100, set1.last().intValue()); assertEquals(set, set1); }
public ImmutableMap<String, Method> build() { final ImmutableMap.Builder<String, Method> lResultBuilder = new ImmutableMap.Builder<String, Method>(); // iterate based on mMethodsOrdered to maintain // the order for (String lBeanPropName : mMethodsOrdered) { final NavigableSet<Method> lAllMethods = mMethodCache.getUnchecked(lBeanPropName); final Method lMostPreciseMethod = lAllMethods.last(); LOGGER.trace( "propName [{}] selected method [{}] all methods[{}]", new Object[] {lBeanPropName, lMostPreciseMethod, lAllMethods}); if (mBeanMethodFilter.accepts(lMostPreciseMethod, lBeanPropName)) { lResultBuilder.put(lBeanPropName, lMostPreciseMethod); } else { LOGGER.trace("rejected [{}]", lBeanPropName); } } return lResultBuilder.build(); }
/** * 右ノードに送信するノード集合を計算する. * * @param right 右ノード * @return 右ノードに送信するノード集合. */ Set<Link> computeSetForRNode(boolean addMe, Link right) { NavigableSet<Link> propset = leftNbrSet.clone(); if (addMe) { propset.add(me); } // propsetから,右ノードと同じノードと,それ以降のノードを削除する (if any) propset = propset.headSet(right, false); /* // 最後に送った集合と近いほうから比較し,i(>=0)番目のノードが異なるとする. // i >= NEIGHBOR_SET_SIZE ならばなにもしない. // i < IMMED_PROP_THRESHOLD ならば直ぐに右ノードに通知する. // i >= IMMED_PROP_THRESHOLD ならば,一定時間後に右ノードに通知するようにタイマをセットする. Iterator<Link> it1 = prevset.iterator(); Iterator<Link> it2 = propset.iterator(); int i = 0; for (; it1.hasNext() && it2.hasNext(); i++) { Link link1 = it1.next(); Link link2 = it2.next(); if (!link1.equals(link2)) { break; } } if (i >= NEIGHBOR_SET_SIZE) { return; }*/ while (propset.size() > capacity) { propset.remove(propset.last()); } // create a copy of propset. propset has a reference to our // customized Comparator, which has a reference to NeighborSet. Set<Link> copy = new HashSet<Link>(); copy.addAll(propset); return copy; }
public void testKeyPutRandomUniform() throws Exception { final NavigableSet<Integer> keys = new TreeSet<Integer>(); long seed = System.currentTimeMillis(); System.out.println("testKeyPutRandomUniform seed : " + seed); final MersenneTwisterFast random = new MersenneTwisterFast(seed); while (keys.size() < KEYS_COUNT) { int key = random.nextInt(Integer.MAX_VALUE); sbTree.put(key, createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); keys.add(key); doReset(); } Assert.assertEquals(sbTree.firstKey(), keys.first()); doReset(); Assert.assertEquals(sbTree.lastKey(), keys.last()); doReset(); for (int key : keys) { Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); doReset(); } }
@Test public void testUnsignedTreeSetMRef() { NavigableSet<Integer> set = new TreeSet<>(Integer::compareUnsigned); set.addAll(Arrays.asList(-100, 0, 100)); assertEquals(0, set.first().intValue()); assertEquals(-100, set.last().intValue()); }
void addAll(Collection<Link> nodes) { NavigableSet<Link> propset = leftNbrSet.clone(); propset.addAll(nodes); while (capacity > 0 && propset.size() > capacity) { propset.remove(propset.last()); } set(propset); }
/** * Creates a new OpenDJ upgrader. * * @param installRoot The installation root of the embedded OpenDS instance, which is usually * {@code ~/openam/opends}. */ public OpenDJUpgrader(final String installRoot, final ServletContext servletCtx) { this.installRoot = installRoot; this.servletCtx = servletCtx; this.upgradeMarker = new File(installRoot + "/.upgrade_marker"); // Determine the current version. Note that if the upgrade marker exists // then that implies that OpenDS was only partially upgraded. this.newVersion = readNewVersion(); this.versionHistory = getVersionHistory(); if (upgradeMarker.exists() && versionHistory.last() == newVersion) { // Previous upgrade has not completed, so the last version is not // accurate. this.currentVersion = versionHistory.lower(newVersion); } else { this.currentVersion = versionHistory.last(); } }
@Test public void testUnsignedTreeSetNotSerializable() { NavigableSet<Integer> set = new TreeSet<>((x, y) -> Integer.compareUnsigned(x, y)); set.addAll(Arrays.asList(-100, 0, 100)); assertEquals(0, set.first().intValue()); assertEquals(-100, set.last().intValue()); byte[] serializedSet = writeSetToBytes(set, false); assertEquals(null, serializedSet); }
public void testKeyDeleteRandomGaussian() throws Exception { NavigableSet<Integer> keys = new TreeSet<Integer>(); long seed = System.currentTimeMillis(); System.out.println("testKeyDeleteRandomGaussian seed : " + seed); MersenneTwisterFast random = new MersenneTwisterFast(seed); while (keys.size() < KEYS_COUNT) { int key = (int) (random.nextGaussian() * Integer.MAX_VALUE / 2 + Integer.MAX_VALUE); if (key < 0) continue; sbTree.put(key, createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); keys.add(key); Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); doReset(); } Iterator<Integer> keysIterator = keys.iterator(); while (keysIterator.hasNext()) { int key = keysIterator.next(); if (key % 3 == 0) { sbTree.remove(key); keysIterator.remove(); } doReset(); } Assert.assertEquals(sbTree.firstKey(), keys.first()); doReset(); Assert.assertEquals(sbTree.lastKey(), keys.last()); doReset(); for (int key : keys) { if (key % 3 == 0) { Assert.assertNull(sbTree.get(key)); } else { Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); } doReset(); } }
protected boolean useLogarithmicProblemScale(List<XYSeries> seriesList) { NavigableSet<Double> xValueSet = new TreeSet<Double>(); int xValueListSize = 0; for (XYSeries series : seriesList) { for (XYDataItem dataItem : (List<XYDataItem>) series.getItems()) { xValueSet.add(dataItem.getXValue()); xValueListSize++; } } if (xValueListSize < LOG_SCALE_MIN_DATASETS_COUNT) { return false; } // If 60% of the points are in 20% of the value space, use a logarithmic scale double threshold = 0.2 * (xValueSet.last() - xValueSet.first()); int belowThresholdCount = xValueSet.headSet(threshold).size(); return belowThresholdCount >= (0.6 * xValueSet.size()); }
public void testKeyDeleteRandomUniform() throws Exception { NavigableSet<Integer> keys = new TreeSet<Integer>(); for (int i = 0; i < KEYS_COUNT; i++) { sbTree.put(i, createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); keys.add(i); doReset(); } Iterator<Integer> keysIterator = keys.iterator(); while (keysIterator.hasNext()) { int key = keysIterator.next(); if (key % 3 == 0) { sbTree.remove(key); keysIterator.remove(); } doReset(); } Assert.assertEquals(sbTree.firstKey(), keys.first()); doReset(); Assert.assertEquals(sbTree.lastKey(), keys.last()); doReset(); for (int key : keys) { if (key % 3 == 0) { Assert.assertNull(sbTree.get(key)); } else { Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); } doReset(); } }
RandomSelection select(boolean narrow, boolean mixInNotPresentItems, boolean permitReversal) { ThreadLocalRandom random = ThreadLocalRandom.current(); NavigableSet<Integer> canonicalSet = this.canonical; BTreeSet<Integer> testAsSet = this.test; List<Integer> canonicalList = new ArrayList<>(canonicalSet); BTreeSet<Integer> testAsList = this.test; Assert.assertEquals(canonicalSet.size(), testAsSet.size()); Assert.assertEquals(canonicalList.size(), testAsList.size()); // sometimes select keys first, so we cover full range List<Integer> allKeys = randomKeys(canonical, mixInNotPresentItems); List<Integer> keys = allKeys; int narrowCount = random.nextInt(3); while (narrow && canonicalList.size() > 10 && keys.size() > 10 && narrowCount-- > 0) { boolean useLb = random.nextBoolean(); boolean useUb = random.nextBoolean(); if (!(useLb | useUb)) continue; // select a range smaller than the total span when we have more narrowing iterations left int indexRange = keys.size() / (narrowCount + 1); boolean lbInclusive = true; Integer lbKey = canonicalList.get(0); int lbKeyIndex = 0, lbIndex = 0; boolean ubInclusive = true; Integer ubKey = canonicalList.get(canonicalList.size() - 1); int ubKeyIndex = keys.size(), ubIndex = canonicalList.size(); if (useLb) { lbKeyIndex = random.nextInt(0, indexRange - 1); Integer candidate = keys.get(lbKeyIndex); if (useLb = (candidate > lbKey && candidate <= ubKey)) { lbInclusive = random.nextBoolean(); lbKey = keys.get(lbKeyIndex); lbIndex = Collections.binarySearch(canonicalList, lbKey); if (lbIndex >= 0 && !lbInclusive) lbIndex++; else if (lbIndex < 0) lbIndex = -1 - lbIndex; } } if (useUb) { ubKeyIndex = random.nextInt(Math.max(lbKeyIndex, keys.size() - indexRange), keys.size() - 1); Integer candidate = keys.get(ubKeyIndex); if (useUb = (candidate < ubKey && candidate >= lbKey)) { ubInclusive = random.nextBoolean(); ubKey = keys.get(ubKeyIndex); ubIndex = Collections.binarySearch(canonicalList, ubKey); if (ubIndex >= 0 && ubInclusive) { ubIndex++; } else if (ubIndex < 0) ubIndex = -1 - ubIndex; } } if (ubIndex < lbIndex) { ubIndex = lbIndex; ubKey = lbKey; ubInclusive = false; } canonicalSet = !useLb ? canonicalSet.headSet(ubKey, ubInclusive) : !useUb ? canonicalSet.tailSet(lbKey, lbInclusive) : canonicalSet.subSet(lbKey, lbInclusive, ubKey, ubInclusive); testAsSet = !useLb ? testAsSet.headSet(ubKey, ubInclusive) : !useUb ? testAsSet.tailSet(lbKey, lbInclusive) : testAsSet.subSet(lbKey, lbInclusive, ubKey, ubInclusive); keys = keys.subList(lbKeyIndex, ubKeyIndex); canonicalList = canonicalList.subList(lbIndex, ubIndex); testAsList = testAsList.subList(lbIndex, ubIndex); Assert.assertEquals(canonicalSet.size(), testAsSet.size()); Assert.assertEquals(canonicalList.size(), testAsList.size()); } // possibly restore full set of keys, to test case where we are provided existing keys that // are out of bounds if (keys != allKeys && random.nextBoolean()) keys = allKeys; Comparator<Integer> comparator = naturalOrder(); if (permitReversal && random.nextBoolean()) { if (allKeys != keys) keys = new ArrayList<>(keys); if (canonicalSet != canonical) canonicalList = new ArrayList<>(canonicalList); Collections.reverse(keys); Collections.reverse(canonicalList); testAsList = testAsList.descendingSet(); canonicalSet = canonicalSet.descendingSet(); testAsSet = testAsSet.descendingSet(); comparator = reverseOrder(); } Assert.assertEquals(canonicalSet.size(), testAsSet.size()); Assert.assertEquals(canonicalList.size(), testAsList.size()); if (!canonicalSet.isEmpty()) { Assert.assertEquals(canonicalSet.first(), canonicalList.get(0)); Assert.assertEquals(canonicalSet.last(), canonicalList.get(canonicalList.size() - 1)); Assert.assertEquals(canonicalSet.first(), testAsSet.first()); Assert.assertEquals(canonicalSet.last(), testAsSet.last()); Assert.assertEquals(canonicalSet.first(), testAsList.get(0)); Assert.assertEquals(canonicalSet.last(), testAsList.get(testAsList.size() - 1)); } return new RandomSelection( keys, canonicalSet, testAsSet, canonicalList, testAsList, comparator); }
public static serverObjects respond( final RequestHeader header, final serverObjects post, final serverSwitch env) { // return variable that accumulates replacements final serverObjects prop = new serverObjects(); final Switchboard sb = (Switchboard) env; // set if this should be visible if (yacyBuildProperties.isPkgManager()) { prop.put("candeploy", "2"); return prop; } else if (OS.canExecUnix || OS.isWindows) { // we can deploy a new system with (i.e.) // cd DATA/RELEASE;tar xfz $1;cp -Rf yacy/* ../../;rm -Rf yacy prop.put("candeploy", "1"); } else { prop.put("candeploy", "0"); } prop.put("candeploy_configCommit", "0"); prop.put("candeploy_autoUpdate", "0"); prop.put("candeploy_downloadsAvailable", "0"); if (post != null) { // check if update is supposed to be installed and a release is defined if (post.containsKey("update") && !post.get("releaseinstall", "").isEmpty()) { prop.put("forwardToSteering", "1"); prop.putHTML("forwardToSteering_release", post.get("releaseinstall", "")); prop.put("deploys", "1"); prop.put("candeploy", "2"); // display nothing else return prop; } if (post.containsKey("downloadRelease")) { // download a release final String release = post.get("releasedownload", ""); if (!release.isEmpty()) { try { yacyRelease versionToDownload = new yacyRelease(new DigestURI(release)); // replace this version with version which contains public key final yacyRelease.DevAndMainVersions allReleases = yacyRelease.allReleases(false, false); final Set<yacyRelease> mostReleases = versionToDownload.isMainRelease() ? allReleases.main : allReleases.dev; for (final yacyRelease rel : mostReleases) { if (rel.equals(versionToDownload)) { versionToDownload = rel; break; } } versionToDownload.downloadRelease(); } catch (final IOException e) { // TODO Auto-generated catch block Log.logException(e); } } } if (post.containsKey("checkRelease")) { yacyRelease.allReleases(true, false); } if (post.containsKey("deleteRelease")) { final String release = post.get("releaseinstall", ""); if (!release.isEmpty()) { try { FileUtils.deletedelete(new File(sb.releasePath, release)); FileUtils.deletedelete(new File(sb.releasePath, release + ".sig")); } catch (final NullPointerException e) { sb.getLog() .logSevere( "AUTO-UPDATE: could not delete release " + release + ": " + e.getMessage()); } } } if (post.containsKey("autoUpdate")) { final yacyRelease updateVersion = yacyRelease.rulebasedUpdateInfo(true); if (updateVersion == null) { prop.put("candeploy_autoUpdate", "2"); // no more recent release found } else { // there is a version that is more recent. Load it and re-start with it sb.getLog() .logInfo("AUTO-UPDATE: downloading more recent release " + updateVersion.getUrl()); final File downloaded = updateVersion.downloadRelease(); prop.putHTML("candeploy_autoUpdate_downloadedRelease", updateVersion.getName()); final boolean devenvironment = new File(sb.getAppPath(), ".svn").exists(); if (devenvironment) { sb.getLog() .logInfo("AUTO-UPDATE: omitting update because this is a development environment"); prop.put("candeploy_autoUpdate", "3"); } else if ((downloaded == null) || (!downloaded.exists()) || (downloaded.length() == 0)) { sb.getLog() .logInfo( "AUTO-UPDATE: omitting update because download failed (file cannot be found, is too small or signature was bad)"); prop.put("candeploy_autoUpdate", "4"); } else { yacyRelease.deployRelease(downloaded); sb.terminate(10, "manual release update to " + downloaded.getName()); sb.getLog().logInfo("AUTO-UPDATE: deploy and restart initiated"); prop.put("candeploy_autoUpdate", "1"); } } } if (post.containsKey("configSubmit")) { prop.put("candeploy_configCommit", "1"); sb.setConfig( "update.process", ("manual".equals(post.get("updateMode", "manual"))) ? "manual" : "auto"); sb.setConfig("update.cycle", Math.max(12, post.getLong("cycle", 168))); sb.setConfig("update.blacklist", post.get("blacklist", "")); sb.setConfig( "update.concept", ("any".equals(post.get("releaseType", "any"))) ? "any" : "main"); sb.setConfig( "update.onlySignedFiles", (post.getBoolean("onlySignedFiles", false)) ? "1" : "0"); } } // version information final String versionstring = yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision(); prop.putHTML("candeploy_versionpp", versionstring); final boolean devenvironment = new File(sb.getAppPath(), ".svn").exists(); float thisVersion = Float.parseFloat(yacyBuildProperties.getVersion()); // cut off the SVN Rev in the Version try { thisVersion = (float) (Math.round(thisVersion * 1000.0) / 1000.0); } catch (final NumberFormatException e) { } // list downloaded releases final File[] downloadedFiles = sb.releasePath.listFiles(); // list can be null if RELEASE directory has been deleted manually final int downloadedFilesNum = (downloadedFiles == null) ? 0 : downloadedFiles.length; prop.put( "candeploy_deployenabled", (downloadedFilesNum == 0) ? "0" : ((devenvironment) ? "1" : "2")); // prevent that a developer-version is over-deployed final NavigableSet<yacyRelease> downloadedReleases = new TreeSet<yacyRelease>(); for (final File downloaded : downloadedFiles) { try { final yacyRelease release = new yacyRelease(downloaded); downloadedReleases.add(release); } catch (final RuntimeException e) { // not a valid release // can be also a restart- or deploy-file final File invalid = downloaded; if (!(invalid.getName().endsWith(".bat") || invalid.getName().endsWith(".sh") || invalid .getName() .endsWith(".sig"))) { // Windows & Linux don't like deleted scripts while execution! invalid.deleteOnExit(); } } } // latest downloaded release final yacyVersion dflt = (downloadedReleases.isEmpty()) ? null : downloadedReleases.last(); // check if there are any downloaded releases and if there are enable the update buttons prop.put("candeploy_downloadsAvailable", (downloadedReleases.isEmpty()) ? "0" : "1"); prop.put( "candeploy_deployenabled_buttonsActive", (downloadedReleases.isEmpty() || devenvironment) ? "0" : "1"); int relcount = 0; for (final yacyRelease release : downloadedReleases) { prop.put( "candeploy_downloadedreleases_" + relcount + "_name", ((release.isMainRelease()) ? "main" : "dev") + " " + release.getReleaseNr() + "/" + release.getSvn()); prop.put( "candeploy_downloadedreleases_" + relcount + "_signature", (release.getSignatureFile().exists() ? "1" : "0")); prop.putHTML("candeploy_downloadedreleases_" + relcount + "_file", release.getName()); prop.put( "candeploy_downloadedreleases_" + relcount + "_selected", (release == dflt) ? "1" : "0"); relcount++; } prop.put("candeploy_downloadedreleases", relcount); // list remotely available releases final yacyRelease.DevAndMainVersions releasess = yacyRelease.allReleases(false, false); relcount = 0; final ArrayList<yacyRelease> rlist = new ArrayList<yacyRelease>(); final Set<yacyRelease> remoteDevReleases = releasess.dev; remoteDevReleases.removeAll(downloadedReleases); for (final yacyRelease release : remoteDevReleases) { rlist.add(release); } final Set<yacyRelease> remoteMainReleases = releasess.main; remoteMainReleases.removeAll(downloadedReleases); for (final yacyRelease release : remoteMainReleases) { rlist.add(release); } yacyRelease release; for (int i = rlist.size() - 1; i >= 0; i--) { release = rlist.get(i); prop.put( "candeploy_availreleases_" + relcount + "_name", ((release.isMainRelease()) ? "main" : "dev") + " " + release.getReleaseNr() + "/" + release.getSvn()); prop.put("candeploy_availreleases_" + relcount + "_url", release.getUrl().toString()); prop.put( "candeploy_availreleases_" + relcount + "_signatures", (release.getPublicKey() != null ? "1" : "0")); prop.put("candeploy_availreleases_" + relcount + "_selected", (relcount == 0) ? "1" : "0"); relcount++; } prop.put("candeploy_availreleases", relcount); // properties for automated system update prop.put( "candeploy_manualUpdateChecked", ("manual".equals(sb.getConfig("update.process", "manual"))) ? "1" : "0"); prop.put( "candeploy_autoUpdateChecked", ("auto".equals(sb.getConfig("update.process", "manual"))) ? "1" : "0"); prop.put("candeploy_cycle", sb.getConfigLong("update.cycle", 168)); prop.putHTML("candeploy_blacklist", sb.getConfig("update.blacklist", "")); prop.put( "candeploy_releaseTypeMainChecked", ("any".equals(sb.getConfig("update.concept", "any"))) ? "0" : "1"); prop.put( "candeploy_releaseTypeAnyChecked", ("any".equals(sb.getConfig("update.concept", "any"))) ? "1" : "0"); prop.put("candeploy_lastlookup", (sb.getConfigLong("update.time.lookup", 0) == 0) ? "0" : "1"); prop.put( "candeploy_lastlookup_time", new Date(sb.getConfigLong("update.time.lookup", 0)).toString()); prop.put( "candeploy_lastdownload", (sb.getConfigLong("update.time.download", 0) == 0) ? "0" : "1"); prop.put( "candeploy_lastdownload_time", new Date(sb.getConfigLong("update.time.download", 0)).toString()); prop.put("candeploy_lastdeploy", (sb.getConfigLong("update.time.deploy", 0) == 0) ? "0" : "1"); prop.put( "candeploy_lastdeploy_time", new Date(sb.getConfigLong("update.time.deploy", 0)).toString()); prop.put( "candeploy_onlySignedFiles", ("1".equals(sb.getConfig("update.onlySignedFiles", "1"))) ? "1" : "0"); /* if ((adminaccess) && (yacyVersion.latestRelease >= (thisVersion+0.01))) { // only new Versions(not new SVN) if ((yacyVersion.latestMainRelease != null) || (yacyVersion.latestDevRelease != null)) { prop.put("hintVersionDownload", 1); } else if ((post != null) && (post.containsKey("aquirerelease"))) { yacyVersion.aquireLatestReleaseInfo(); prop.put("hintVersionDownload", 1); } else { prop.put("hintVersionAvailable", 1); } } prop.put("hintVersionAvailable", 1); // for testing prop.putASIS("hintVersionDownload_versionResMain", (yacyVersion.latestMainRelease == null) ? "-" : yacyVersion.latestMainRelease.toAnchor()); prop.putASIS("hintVersionDownload_versionResDev", (yacyVersion.latestDevRelease == null) ? "-" : yacyVersion.latestDevRelease.toAnchor()); prop.put("hintVersionAvailable_latestVersion", Float.toString(yacyVersion.latestRelease)); */ return prop; }