List of usage examples for java.util IdentityHashMap put
public V put(K key, V value)
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java
/** * Helper method that can clone an Attribute Value * * @param val the AttributeValue to copy * @param sourceDestinationMap used to avoid loops by keeping track of references * @return a copy of val/* w w w . j av a2 s . c o m*/ */ public static AttributeValue clone(AttributeValue val, IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap) { if (val == null) { return null; } if (sourceDestinationMap.containsKey(val)) { return sourceDestinationMap.get(val); } AttributeValue clonedVal = new AttributeValue(); sourceDestinationMap.put(val, clonedVal); if (val.getN() != null) { clonedVal.setN(val.getN()); } else if (val.getS() != null) { clonedVal.setS(val.getS()); } else if (val.getB() != null) { clonedVal.setB(val.getB()); } else if (val.getNS() != null) { clonedVal.setNS(val.getNS()); } else if (val.getSS() != null) { clonedVal.setSS(val.getSS()); } else if (val.getBS() != null) { clonedVal.setBS(val.getBS()); } else if (val.getBOOL() != null) { clonedVal.setBOOL(val.getBOOL()); } else if (val.getNULL() != null) { clonedVal.setNULL(val.getNULL()); } else if (val.getL() != null) { List<AttributeValue> list = new ArrayList<>(val.getL().size()); for (AttributeValue listItemValue : val.getL()) { if (!sourceDestinationMap.containsKey(listItemValue)) { sourceDestinationMap.put(listItemValue, clone(listItemValue, sourceDestinationMap)); } list.add(sourceDestinationMap.get(listItemValue)); } clonedVal.setL(list); } else if (val.getM() != null) { Map<String, AttributeValue> map = new HashMap<>(val.getM().size()); for (Entry<String, AttributeValue> pair : val.getM().entrySet()) { if (!sourceDestinationMap.containsKey(pair.getValue())) { sourceDestinationMap.put(pair.getValue(), clone(pair.getValue(), sourceDestinationMap)); } map.put(pair.getKey(), sourceDestinationMap.get(pair.getValue())); } clonedVal.setM(map); } return clonedVal; }
From source file:de.codesourcery.eve.skills.ui.model.impl.MarketGroupTreeModelBuilder.java
private ITreeNode getOrCreateTreeNode(MarketGroup group, IdentityHashMap<MarketGroup, ITreeNode> nodes) { ITreeNode result = nodes.get(group); if (result == null) { result = new DefaultTreeNode(group); nodes.put(group, result); }// ww w.j a v a 2s. c o m return result; }
From source file:com.thesmartweb.swebrank.Moz.java
/** * Method that captures the various Moz metrics for the provided urls (with help of the sample here https://github.com/seomoz/SEOmozAPISamples * and ranks them accordingly//from w w w.j av a 2s. c o m * @param links the urls to analyze * @param top_count the amount of results to keep when we rerank the results according to their value of a specific Moz metric * @param moz_threshold the threshold to the Moz value to use * @param moz_threshold_option flag if we are going to use threshold in the Moz value or not * @param mozMetrics list that contains which metric to use for Moz //1st place is Page Authority,2nd external mozRank, 3rd, mozTrust, 4th DomainAuthority and 5th MozRank (it is the default) * @param config_path path that has the config files with the api keys and secret for Moz * @return an array with the links sorted according to their moz values */ public String[] perform(String[] links, int top_count, Double moz_threshold, Boolean moz_threshold_option, List<Boolean> mozMetrics, String config_path) { //=====short codes for the metrics long upa = 34359738368L;//page authority long pda = 68719476736L;//domain authority long uemrp = 1048576;//mozrank external equity long utrp = 131072;//moztrust long fmrp = 32768;//mozrank subdomain long umrp = 16384;//mozrank System.gc(); System.out.println("into Moz"); Double[] mozRanks = new Double[links.length]; DataManipulation textualmanipulation = new DataManipulation(); for (int i = 0; i < links.length; i++) { if (links[i] != null) { if (!textualmanipulation.StructuredFileCheck(links[i])) { try { Thread.sleep(10000); URLMetricsService urlMetricsservice; urlMetricsservice = authenticate(config_path); String objectURL = links[i].substring(0, links[i].length()); Gson gson = new Gson(); if (mozMetrics.get(1)) {//Domain Authority String response = urlMetricsservice.getUrlMetrics(objectURL, pda); UrlResponse res = gson.fromJson(response, UrlResponse.class); System.gc(); if (res != null && !(response.equalsIgnoreCase("{}"))) { String mozvalue_string = res.getPda(); mozRanks[i] = Double.parseDouble(mozvalue_string); } else { mozRanks[i] = Double.parseDouble("0"); } } else if (mozMetrics.get(2)) {//External MozRank String response = urlMetricsservice.getUrlMetrics(objectURL, uemrp); UrlResponse res = gson.fromJson(response, UrlResponse.class); System.gc(); if (res != null && !(response.equalsIgnoreCase("{}"))) { String mozvalue_string = res.getUemrp(); mozRanks[i] = Double.parseDouble(mozvalue_string); } else { mozRanks[i] = Double.parseDouble("0"); } } else if (mozMetrics.get(3)) {//MozRank String response = urlMetricsservice.getUrlMetrics(objectURL, umrp); UrlResponse res = gson.fromJson(response, UrlResponse.class); System.gc(); if (res != null && !(response.equalsIgnoreCase("{}"))) { String mozvalue_string = res.getUmrp(); mozRanks[i] = Double.parseDouble(mozvalue_string); } else { mozRanks[i] = Double.parseDouble("0"); } } else if (mozMetrics.get(4)) {//MozTrust String response = urlMetricsservice.getUrlMetrics(objectURL, utrp); UrlResponse res = gson.fromJson(response, UrlResponse.class); System.gc(); if (res != null && !(response.equalsIgnoreCase("{}"))) { String mozvalue_string = res.getUtrp(); mozRanks[i] = Double.parseDouble(mozvalue_string); } else { mozRanks[i] = Double.parseDouble("0"); } } else if (mozMetrics.get(5)) {//Page Authority String response = urlMetricsservice.getUrlMetrics(objectURL, upa); UrlResponse res = gson.fromJson(response, UrlResponse.class); System.gc(); if (res != null && !(response.equalsIgnoreCase("{}"))) { String mozvalue_string = res.getUpa(); mozRanks[i] = Double.parseDouble(mozvalue_string); } else { mozRanks[i] = Double.parseDouble("0"); } } else if (mozMetrics.get(6)) {//subdomain MozRank String response = urlMetricsservice.getUrlMetrics(objectURL, fmrp); UrlResponse res = gson.fromJson(response, UrlResponse.class); System.gc(); if (res != null && !(response.equalsIgnoreCase("{}"))) { String mozvalue_string = res.getFmrp(); mozRanks[i] = Double.parseDouble(mozvalue_string); } else { mozRanks[i] = Double.parseDouble("0"); } } } catch (InterruptedException | JsonSyntaxException | NumberFormatException ex) { System.out.println("exception moz:" + ex.toString()); mozRanks[i] = Double.parseDouble("0"); String[] links_out = null; return links_out; } } else { mozRanks[i] = Double.parseDouble("0"); } } } try {//ranking of the urls according to their moz score //get the scores to a list System.out.println("I am goint to rank the scores of Moz"); System.gc(); List<Double> seomozRanks_scores_list = Arrays.asList(mozRanks); //create a hashmap in order to map the scores with the indexes System.gc(); IdentityHashMap<Double, Integer> originalIndices = new IdentityHashMap<Double, Integer>(); //copy the original scores list System.gc(); for (int i = 0; i < seomozRanks_scores_list.size(); i++) { originalIndices.put(seomozRanks_scores_list.get(i), i); System.gc(); } //sort the scores List<Double> sorted_seomozRanks_scores = new ArrayList<Double>(); System.gc(); sorted_seomozRanks_scores.addAll(seomozRanks_scores_list); System.gc(); sorted_seomozRanks_scores.removeAll(Collections.singleton(null)); System.gc(); if (!sorted_seomozRanks_scores.isEmpty()) { Collections.sort(sorted_seomozRanks_scores, Collections.reverseOrder()); } //get the original indexes //the max amount of results int[] origIndex = new int[150]; if (!sorted_seomozRanks_scores.isEmpty()) { //if we want to take the top scores(for example top 10) if (!moz_threshold_option) { origIndex = new int[top_count]; for (int i = 0; i < top_count; i++) { Double score = sorted_seomozRanks_scores.get(i); System.gc(); // Lookup original index efficiently origIndex[i] = originalIndices.get(score); } } //if we have a threshold else if (moz_threshold_option) { int j = 0; int counter = 0; while (j < sorted_seomozRanks_scores.size()) { if (sorted_seomozRanks_scores.get(j).compareTo(moz_threshold) >= 0) { counter++; } j++; } origIndex = new int[counter]; for (int k = 0; k < origIndex.length - 1; k++) { System.gc(); Double score = sorted_seomozRanks_scores.get(k); origIndex[k] = originalIndices.get(score); } } } String[] links_out = new String[origIndex.length]; for (int jj = 0; jj < origIndex.length; jj++) { System.gc(); links_out[jj] = links[origIndex[jj]]; } System.gc(); System.out.println("I have ranked the scores of moz"); return links_out; } catch (Exception ex) { System.out.println("exception moz list" + ex.toString()); //Logger.getLogger(Moz.class.getName()).log(Level.SEVERE, null, ex); String[] links_out = null; return links_out; } }
From source file:ca.uhn.fhir.jpa.term.BaseHapiTerminologySvc.java
private void persistChildren(TermConcept theConcept, TermCodeSystemVersion theCodeSystem, IdentityHashMap<TermConcept, Object> theConceptsStack, int theTotalConcepts) { if (theConceptsStack.put(theConcept, PLACEHOLDER_OBJECT) != null) { return;/*from w w w . ja v a 2s.c o m*/ } if (theConceptsStack.size() == 1 || theConceptsStack.size() % 10000 == 0) { float pct = (float) theConceptsStack.size() / (float) theTotalConcepts; ourLog.info("Have processed {}/{} concepts ({}%)", theConceptsStack.size(), theTotalConcepts, (int) (pct * 100.0f)); } theConcept.setCodeSystem(theCodeSystem); theConcept.setIndexStatus(BaseHapiFhirDao.INDEX_STATUS_INDEXED); if (theConceptsStack.size() <= myDaoConfig.getDeferIndexingForCodesystemsOfSize()) { saveConcept(theConcept); } else { myConceptsToSaveLater.add(theConcept); } for (TermConceptParentChildLink next : theConcept.getChildren()) { persistChildren(next.getChild(), theCodeSystem, theConceptsStack, theTotalConcepts); } for (TermConceptParentChildLink next : theConcept.getChildren()) { if (theConceptsStack.size() <= myDaoConfig.getDeferIndexingForCodesystemsOfSize()) { saveConceptLink(next); } else { myConceptLinksToSaveLater.add(next); } } }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testAddWatch() { IdentityHashMap m = new IdentityHashMap(); m.put("watch", "watch"); assertEquals(m.get("watch"), "watch"); }
From source file:org.jamocha.rating.fraj.RatingProvider.java
private double rateBetaWithoutExistentials(final StatisticsProvider statisticsProvider, final PathNodeFilterSet toRate, final Map<Set<PathFilterList>, List<Pair<List<Set<PathFilterList>>, List<PathFilter>>>> componentToJoinOrder, final Map<Path, Set<PathFilterList>> pathToPreNetworkComponents) { final IdentityHashMap<Set<PathFilterList>, Data> preNetworkComponentToData = new IdentityHashMap<>(); for (final Set<PathFilterList> comp : componentToJoinOrder.keySet()) { preNetworkComponentToData.put(comp, statisticsProvider.getData(comp)); }//from ww w . j a v a2 s.c o m final double tupleSize = preNetworkComponentToData.values().stream().mapToDouble(Data::getTupleSize).sum(); final double tuplesPerPage = statisticsProvider.getPageSize() / tupleSize; final double rowCount = calcBetaUnfilteredSize(statisticsProvider, componentToJoinOrder, pathToPreNetworkComponents, componentToJoinOrder.keySet()); // joinsize is needed twice per component, thus pre-calculate it final Map<Set<PathFilterList>, Double> preNetworkComponentToJoinSize = preNetworkComponentToData.keySet() .stream() .collect(toMap(Function.identity(), component -> joinSize(statisticsProvider, component, componentToJoinOrder.get(component), componentToJoinOrder.keySet(), pathToPreNetworkComponents))); final double finsert = preNetworkComponentToData.entrySet().stream() .mapToDouble( entry -> entry.getValue().getFinsert() * preNetworkComponentToJoinSize.get(entry.getKey())) .sum(); final double fdelete = preNetworkComponentToData.values().stream().mapToDouble(Data::getFdelete).sum(); // publish information to statistics provider { final Set<PathFilterList> filters = new HashSet<>(); componentToJoinOrder.keySet().forEach(filters::addAll); filters.add(toRate); statisticsProvider.setData(filters, new Data(finsert, fdelete, rowCount, tupleSize)); } final double mxBeta = m(rowCount, tuplesPerPage); final double runtimeCost = preNetworkComponentToData.entrySet().stream().mapToDouble(entry -> { final Set<PathFilterList> component = entry.getKey(); final Data data = entry.getValue(); return data.getFinsert() * costPosInsVarI(statisticsProvider, component, componentToJoinOrder.get(component), componentToJoinOrder.keySet(), pathToPreNetworkComponents) + data.getFdelete() * (mxBeta + cardenas(mxBeta, preNetworkComponentToJoinSize.get(component))); }).sum(); final double memoryCost = rowCount * tupleSize; return cpuAndMemCostCombiner.applyAsDouble(runtimeCost, memoryCost); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testEntrySetRemove() { IdentityHashMap hashMap = new IdentityHashMap(); hashMap.put("A", "B"); IdentityHashMap dummy = new IdentityHashMap(); dummy.put("A", "b"); Entry bogus = (Entry) dummy.entrySet().iterator().next(); Set entrySet = hashMap.entrySet(); boolean removed = entrySet.remove(bogus); assertEquals(removed, false);/* www .j a v a 2 s . c om*/ assertEquals(hashMap.get("A"), "B"); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testKeysConflict() { IdentityHashMap hashMap = new IdentityHashMap(); hashMap.put(STRING_ZERO_KEY, STRING_ZERO_VALUE); hashMap.put(INTEGER_ZERO_KEY, INTEGER_ZERO_VALUE); hashMap.put(ODD_ZERO_KEY, ODD_ZERO_VALUE); assertEquals(hashMap.get(INTEGER_ZERO_KEY), INTEGER_ZERO_VALUE); assertEquals(hashMap.get(ODD_ZERO_KEY), ODD_ZERO_VALUE); assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE); hashMap.remove(INTEGER_ZERO_KEY);/* ww w.jav a 2s .co m*/ assertEquals(hashMap.get(ODD_ZERO_KEY), ODD_ZERO_VALUE); assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE); assertEquals(hashMap.get(INTEGER_ZERO_KEY), null); hashMap.remove(ODD_ZERO_KEY); assertEquals(hashMap.get(INTEGER_ZERO_KEY), null); assertEquals(hashMap.get(ODD_ZERO_KEY), null); assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE); hashMap.remove(STRING_ZERO_KEY); assertEquals(hashMap.get(INTEGER_ZERO_KEY), null); assertEquals(hashMap.get(ODD_ZERO_KEY), null); assertEquals(hashMap.get(STRING_ZERO_KEY), null); assertEquals(hashMap.size(), 0); }
From source file:net.datenwerke.sandbox.SandboxLoader.java
private SandboxLoader initSubLoader(IdentityHashMap<SandboxContext, SandboxLoader> loaderMap, SandboxContext context) {// ww w .ja v a2s. com if (loaderMap.containsKey(context)) return loaderMap.get(context); SandboxLoader subLoader = new SandboxLoader(this, securityManager); subLoader.init(context); loaderMap.put(context, subLoader); return subLoader; }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
/** * Test method for 'java.util.AbstractMap.toString()'. *//* w w w . j a v a2s . co m*/ public void testToString() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); hashMap.put(KEY_KEY, VALUE_VAL); String entryString = makeEntryString(KEY_KEY, VALUE_VAL); assertTrue(entryString.equals(hashMap.toString())); }