Java Code Examples for java.util.HashMap#Entry

The following examples show how to use java.util.HashMap#Entry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToggleParameterSetEditor.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ValueType getValue() {
  ObservableList<ToggleButton> buttons = segmentedButton.getButtons();
  for (ToggleButton button : buttons) {
    if (button.isSelected()) {
      String buttonText = button.getText();

      for (HashMap.Entry<String, ParameterSet> entry : toggleValues.entrySet()) {
        segmentedButton.getButtons().add(new ToggleButton(entry.getKey()));
        if (entry.getKey().equals(buttonText)) {
          return (ValueType) entry.getKey();
        }
      }

    }
  }
  return null;
}
 
Example 2
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void cleanupCache() {
    if (Math.abs(SystemClock.elapsedRealtime() - lastCleanupTime) < 60 * 10 * 1000) {
        return;
    }
    lastCleanupTime = SystemClock.elapsedRealtime();

    ArrayList<String> keysToDelete = null;
    for (HashMap.Entry<String, CachedResult> entry : responseCache.entrySet()) {
        CachedResult cachedResult = entry.getValue();
        if (Math.abs(SystemClock.elapsedRealtime() - cachedResult.firstQueryTime) >= 60 * 10 * 1000) {
            if (keysToDelete == null) {
                keysToDelete = new ArrayList<>();
            }
            keysToDelete.add(entry.getKey());
        }
    }
    if (keysToDelete != null) {
        for (int a = 0, size = keysToDelete.size(); a < size; a++) {
            responseCache.remove(keysToDelete.get(a));
        }
    }
}
 
Example 3
Source File: DataDstWriterNode.java    From xresloader with MIT License 6 votes vote down vote up
public ArrayList<DataDstFieldDescriptor> getSortedFields() {
    if (fields == null) {
        return null;
    }

    if (sortedFields != null && sortedFields.size() == fields.size()) {
        return sortedFields;
    }

    sortedFields = new ArrayList<DataDstFieldDescriptor>();
    sortedFields.ensureCapacity(fields.size());
    for (HashMap.Entry<String, DataDstFieldDescriptor> d : fields.entrySet()) {
        sortedFields.add(d.getValue());
    }
    sortedFields.sort((l, r) -> {
        return Integer.compare(l.getIndex(), r.getIndex());
    });
    return sortedFields;
}
 
Example 4
Source File: WebappRegistry.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the data of all web apps whose url matches |urlFilter|.
 * @param urlFilter The filter object to check URLs.
 */
@VisibleForTesting
void unregisterWebappsForUrlsImpl(UrlFilter urlFilter) {
    Iterator<HashMap.Entry<String, WebappDataStorage>> it = mStorages.entrySet().iterator();
    while (it.hasNext()) {
        HashMap.Entry<String, WebappDataStorage> entry = it.next();
        WebappDataStorage storage = entry.getValue();
        if (urlFilter.matchesUrl(storage.getUrl())) {
            storage.delete();
            it.remove();
        }
    }

    if (mStorages.isEmpty()) {
        mPreferences.edit().clear().apply();
    } else {
        mPreferences.edit().putStringSet(KEY_WEBAPP_SET, mStorages.keySet()).apply();
    }
}
 
Example 5
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updatePhotosCounter() {
    if (counterTextView == null) {
        return;
    }
    boolean hasVideo = false;
    for (HashMap.Entry<Object, Object> entry : selectedPhotos.entrySet()) {
        MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry.getValue();
        if (photoEntry.isVideo) {
            hasVideo = true;
            break;
        }
    }
    if (hasVideo) {
        counterTextView.setText(LocaleController.formatPluralString("Media", selectedPhotos.size()).toUpperCase());
    } else {
        counterTextView.setText(LocaleController.formatPluralString("Photos", selectedPhotos.size()).toUpperCase());
    }
}
 
Example 6
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updatePhotosCounter() {
    if (counterTextView == null) {
        return;
    }
    boolean hasVideo = false;
    for (HashMap.Entry<Object, Object> entry : selectedPhotos.entrySet()) {
        MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry.getValue();
        if (photoEntry.isVideo) {
            hasVideo = true;
            break;
        }
    }
    if (hasVideo) {
        counterTextView.setText(LocaleController.formatPluralString("Media", selectedPhotos.size()).toUpperCase());
    } else {
        counterTextView.setText(LocaleController.formatPluralString("Photos", selectedPhotos.size()).toUpperCase());
    }
}
 
Example 7
Source File: DataDstWriterNode.java    From xresloader with MIT License 6 votes vote down vote up
public ArrayList<DataDstFieldDescriptor> getSortedFields() {
    if (this.fields_by_name == null) {
        return null;
    }

    if (this.sortedFields != null && this.sortedFields.size() == this.fields_by_name.size()) {
        return this.sortedFields;
    }

    this.sortedFields = new ArrayList<DataDstFieldDescriptor>();
    this.sortedFields.ensureCapacity(this.fields_by_name.size());
    for (HashMap.Entry<String, DataDstFieldDescriptor> d : this.fields_by_name.entrySet()) {
        this.sortedFields.add(d.getValue());
    }
    this.sortedFields.sort((l, r) -> {
        return Integer.compare(l.getIndex(), r.getIndex());
    });
    return this.sortedFields;
}
 
Example 8
Source File: CreateTableIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithConnLevelUpdateCacheFreq() throws Exception {
    String tableName = generateUniqueName();
    Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);

    HashMap<String, Long> expectedUCF = new HashMap<>();
    expectedUCF.put("10", new Long(10L));
    expectedUCF.put("0", new Long(0L));
    expectedUCF.put("10000", new Long(10000L));
    expectedUCF.put("ALWAYS", new Long(0L));
    expectedUCF.put("NEVER", new Long(Long.MAX_VALUE));

    for (HashMap.Entry<String, Long> entry : expectedUCF.entrySet()) {
        String connLevelUCF = entry.getKey();
        long expectedUCFInSysCat = entry.getValue();

        String createTableString = "CREATE TABLE " + tableName + " (k VARCHAR PRIMARY KEY,"
                + "v1 VARCHAR, v2 VARCHAR)";
        props.put(QueryServices.DEFAULT_UPDATE_CACHE_FREQUENCY_ATRRIB, connLevelUCF);
        verifyUCFValueInSysCat(tableName, createTableString, props, expectedUCFInSysCat);
    }
}
 
Example 9
Source File: TreeModelDataConverter.java    From Alink with Apache License 2.0 5 votes vote down vote up
@Override
public void reduce(Iterable <Row> input, Collector <Row> output) throws Exception {
	HashMap <Integer, Integer> finalMap = new HashMap <>(1000);

	for (Row value : input) {
		if ((Long)value.getField(0) == 0L || value.getField(2) != null) {
			continue;
		}
		String nodeDetail = (String) value.getField(1);
		TreeModelDataConverter.NodeSerializable lc = JsonConverter.fromJson(
			nodeDetail, TreeModelDataConverter.NodeSerializable.class);
		if (lc != null && lc.node != null) {
			int featureId = lc.node.getFeatureIndex();
			if (featureId < 0) {
				continue;
			}
			if (!finalMap.containsKey(featureId)) {
				finalMap.put(featureId, 1);
			} else {
				finalMap.put(featureId, finalMap.get(featureId) + 1);
			}
			//System.out.println("lc " + );
		}
	}
	for (HashMap.Entry <Integer, Integer> index : finalMap.entrySet()) {
		//System.out.println("key "+index.getKey()+" value "+index.getValue());
		Row row = new Row(2);
		row.setField(0, featureColNames[index.getKey()]);
		row.setField(1, (long) index.getValue());
		output.collect(row);
		//System.out.println("row "+row);
	}
}
 
Example 10
Source File: ChatAttachAlertLocationLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updatePositions() {
    if (mapView == null) {
        return;
    }
    Projection projection = mapView.getProjection();
    for (HashMap.Entry<Marker, View> entry : views.entrySet()) {
        Marker marker = entry.getKey();
        View view = entry.getValue();
        Point point = projection.toPixels(marker.getPosition(),null);
        view.setTranslationX(point.x - view.getMeasuredWidth() / 2);
        view.setTranslationY(point.y - view.getMeasuredHeight() + AndroidUtilities.dp(22));
    }
}
 
Example 11
Source File: LruCache.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param maxSize the maximum size of the cache before returning. May be -1
 *     to evict even 0-sized elements.
 */
private void trimToSize(int maxSize, String justAdded) {
    synchronized (this) {
        Iterator<HashMap.Entry<String, BitmapDrawable>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            if (size <= maxSize || map.isEmpty()) {
                break;
            }
            HashMap.Entry<String, BitmapDrawable> entry = iterator.next();

            String key = entry.getKey();
            if (justAdded != null && justAdded.equals(key)) {
                continue;
            }
            BitmapDrawable value = entry.getValue();
            size -= safeSizeOf(key, value);
            iterator.remove();

            String[] args = key.split("@");
            if (args.length > 1) {
                ArrayList<String> arr = mapFilters.get(args[0]);
                if (arr != null) {
                    arr.remove(args[1]);
                    if (arr.isEmpty()) {
                        mapFilters.remove(args[0]);
                    }
                }
            }

            entryRemoved(true, key, value, null);
        }
    }
}
 
Example 12
Source File: Emoji.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void saveRecentEmoji() {
    SharedPreferences preferences = MessagesController.getGlobalEmojiSettings();
    StringBuilder stringBuilder = new StringBuilder();
    for (HashMap.Entry<String, Integer> entry : emojiUseHistory.entrySet()) {
        if (stringBuilder.length() != 0) {
            stringBuilder.append(",");
        }
        stringBuilder.append(entry.getKey());
        stringBuilder.append("=");
        stringBuilder.append(entry.getValue());
    }
    preferences.edit().putString("emojis2", stringBuilder.toString()).commit();
}
 
Example 13
Source File: WebappRegistry.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the WebappDataStorage object whose scope most closely matches the provided URL, or
 * null if a matching web app cannot be found. The most closely matching scope is the longest
 * scope which has the same prefix as the URL to open.
 * @param url The URL to search for.
 * @return The storage object for the web app, or null if one cannot be found.
 */
public WebappDataStorage getWebappDataStorageForUrl(final String url) {
    WebappDataStorage bestMatch = null;
    int largestOverlap = 0;
    for (HashMap.Entry<String, WebappDataStorage> entry : mStorages.entrySet()) {
        WebappDataStorage storage = entry.getValue();
        String scope = storage.getScope();
        if (url.startsWith(scope) && scope.length() > largestOverlap) {
            bestMatch = storage;
            largestOverlap = scope.length();
        }
    }
    return bestMatch;
}
 
Example 14
Source File: Solution.java    From JavaExercises with GNU General Public License v2.0 5 votes vote down vote up
public static void removeTheFirstNameDuplicates(HashMap<String, String> map) {
    ArrayList<String> list = new ArrayList();
    for (HashMap.Entry<String, String> item : map.entrySet()) {
        list.add(item.getValue());
    }
    for (String name : list)
        if (Collections.frequency(list, name) > 1)
            removeItemFromMapByValue(map, name);
    //System.out.println(map); // чтобы увидеть результаты
}
 
Example 15
Source File: AndroidAppIPackageManager.java    From Android-Plugin-Framework with MIT License 5 votes vote down vote up
@Override
public Object beforeInvoke(Object target, Method method, Object[] args) {
    LogUtil.d("authorities", args[0]);
    ArrayList<PluginDescriptor> plugins = PluginManager.getPlugins();
    PluginProviderInfo info = null;
    PluginDescriptor pluginDescriptor = null;
    if (plugins != null) {
        for(PluginDescriptor descriptor:plugins) {
            HashMap<String, PluginProviderInfo> pluginProviderInfoMap = descriptor.getProviderInfos();
            Iterator<HashMap.Entry<String, PluginProviderInfo>> iterator = pluginProviderInfoMap.entrySet().iterator();
            while (iterator.hasNext()) {
                HashMap.Entry<String, PluginProviderInfo> entry = iterator.next();
                if (args[0].equals(entry.getValue().getAuthority())) {
                    //如果插件中有重复的配置,先到先得
                    LogUtil.d("如果插件中有重复的配置,先到先得 authorities ", args[0]);
                    info = entry.getValue();
                    pluginDescriptor = descriptor;
                    break;
                }
            }
            if (info != null) {
                break;
            }
        }
    }
    if (info != null) {
        ProviderInfo providerInfo = new ProviderInfo();
        providerInfo.name = info.getName();
        providerInfo.packageName = getPackageName(pluginDescriptor);
        providerInfo.icon = pluginDescriptor.getApplicationIcon();
        providerInfo.metaData = pluginDescriptor.getMetaData();
        providerInfo.enabled = true;
        providerInfo.exported = info.isExported();
        providerInfo.applicationInfo = getApplicationInfo(pluginDescriptor);
        providerInfo.authority = info.getAuthority();
        return providerInfo;
    }
    return null;
}
 
Example 16
Source File: RLottieImageView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setAnimation(RLottieDrawable lottieDrawable) {
    drawable = lottieDrawable;
    if (autoRepeat) {
        drawable.setAutoRepeat(1);
    }
    if (layerColors != null) {
        drawable.beginApplyLayerColors();
        for (HashMap.Entry<String, Integer> entry : layerColors.entrySet()) {
            drawable.setLayerColor(entry.getKey(), entry.getValue());
        }
        drawable.commitApplyLayerColors();
    }
    drawable.setAllowDecodeSingleFrame(true);
    setImageDrawable(drawable);
}
 
Example 17
Source File: ToggleParameterSetParameter.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void loadValueFromXML(@Nonnull Element xmlElement) {
  String stringValue = xmlElement.getTextContent();
  for (HashMap.Entry<String, ParameterSet> entry : toggleValues.entrySet()) {
    if (entry.getKey().toString().equals(stringValue)) {
      setValue(entry.getKey());
      break;
    }
  }
}
 
Example 18
Source File: MediaActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public MediaActivity(Bundle args, int[] media, SharedMediaLayout.SharedMediaData[] mediaData, int initTab) {
    super(args);
    hasMedia = media;
    initialTab = initTab;
    dialog_id = args.getLong("dialog_id", 0);
    for (int a = 0; a < sharedMediaData.length; a++) {
        sharedMediaData[a] = new SharedMediaLayout.SharedMediaData();
        sharedMediaData[a].max_id[0] = ((int) dialog_id) == 0 ? Integer.MIN_VALUE : Integer.MAX_VALUE;
        if (mergeDialogId != 0 && info != null) {
            sharedMediaData[a].max_id[1] = info.migrated_from_max_id;
            sharedMediaData[a].endReached[1] = false;
        }
        if (mediaData != null) {
            sharedMediaData[a].totalCount = mediaData[a].totalCount;
            sharedMediaData[a].messages.addAll(mediaData[a].messages);
            sharedMediaData[a].sections.addAll(mediaData[a].sections);
            for (HashMap.Entry<String, ArrayList<MessageObject>> entry : mediaData[a].sectionArrays.entrySet()) {
                sharedMediaData[a].sectionArrays.put(entry.getKey(), new ArrayList<>(entry.getValue()));
            }
            for (int i = 0; i < 2; i++) {
                sharedMediaData[a].endReached[i] = mediaData[a].endReached[i];
                sharedMediaData[a].messagesDict[i] = mediaData[a].messagesDict[i].clone();
                sharedMediaData[a].max_id[i] = mediaData[a].max_id[i];
            }
        }
    }
}
 
Example 19
Source File: Sample.java    From manifold with Apache License 2.0 4 votes vote down vote up
private HashMap.Entry<String, String> innerClassParam( HashMap.Entry<String, String> param )
{
  return param;
}
 
Example 20
Source File: L2FastMap.java    From L2jBrasil with GNU General Public License v3.0 votes vote down vote up
public Map.Entry<K, V> getNext(HashMap.Entry<K, V> priv);