List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:com.clicktravel.cheddar.application.retry.RetryableAspect.java
private boolean shouldRetryMethod(final Class<? extends Throwable> thrownClass, final Retryable retryable, final int attempts) { if (attempts >= retryable.maxAttempts()) { return false; }//from w w w.j ava2 s .c o m final HashSet<Class<? extends Throwable>> failClasses = new HashSet<>( Arrays.asList(retryable.failImmediatelyOn())); failClasses.addAll(alwaysImmediateFailureExceptionClasses); for (final Class<? extends Throwable> failClass : failClasses) { if (failClass.isAssignableFrom(thrownClass)) { return false; } } return true; }
From source file:org.apache.solr.analytics.AbstractAnalyticsStatsTest.java
public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) { Object result;//from w w w. j a va 2 s . com if (stat.contains("perc_")) { double[] perc = new double[] { Double.parseDouble(stat.substring(5)) / 100 }; result = PercentileCalculator.getPercentiles(list, perc).get(0); } else if (stat.equals("count")) { result = Long.valueOf(list.size()); } else if (stat.equals("unique")) { HashSet<T> set = new HashSet<>(); set.addAll(list); result = Long.valueOf((long) set.size()); } else if (stat.equals("max")) { Collections.sort(list); result = list.get(list.size() - 1); } else if (stat.equals("min")) { Collections.sort(list); result = list.get(0); } else { result = null; } return result; }
From source file:com.vsct.dt.hesperides.templating.platform.PropertiesData.java
public MustacheScope toMustacheScope(Set<KeyValueValorisationData> instanceValorisations, Set<KeyValueValorisationData> platformValorisations, Boolean buildingFile) { if (instanceValorisations == null) { instanceValorisations = new HashSet<>(); }//from w ww .j av a2s.c o m if (platformValorisations == null) { platformValorisations = new HashSet<>(); } HashSet<ValorisationData> valorisations = new HashSet<>(); valorisations.addAll(keyValueProperties); valorisations.addAll(iterableProperties); if (platformValorisations != null) { /* addAll doesn't replace existing values, but we want to, so iterate */ for (KeyValueValorisationData v : platformValorisations) { //Remove local valorisation if it exists (ie has the same name even if the value is different) for (Iterator<ValorisationData> it = valorisations.iterator(); it.hasNext();) { ValorisationData existingValorisation = it.next(); if (existingValorisation.getName().equals(v.getName())) { it.remove(); } } valorisations.add(v); } } /* Prepare what will be injected in the values */ Map<String, String> injectableKeyValueValorisations = keyValueProperties.stream() .collect(Collectors.toMap(ValorisationData::getName, KeyValueValorisationData::getValue)); Map<String, String> injectablePlatformValorisations = platformValorisations.stream() .collect(Collectors.toMap(ValorisationData::getName, KeyValueValorisationData::getValue)); /* Erase local valorisations by platform valorisations */ injectableKeyValueValorisations.putAll(injectablePlatformValorisations); Map<String, String> injectableInstanceProperties = instanceValorisations.stream() .collect(Collectors.toMap(ValorisationData::getName, KeyValueValorisationData::getValue)); injectableKeyValueValorisations.replaceAll((key, value) -> value.replace("$", "\\$")); injectableInstanceProperties.replaceAll((key, value) -> value.replace("$", "\\$")); InjectableMustacheScope injectable = MustacheScope.from(valorisations) /* First re-inject keyValueValorisations, so they can refer to themselves */ .inject(injectableKeyValueValorisations) /* Do it a second time in case global properties where referring to themselves */ .inject(injectableKeyValueValorisations) /* Finally inject instance valorisations */ .inject(injectableInstanceProperties) /* Do it a third time in case instances properties where referring to global properties */ .inject(injectableKeyValueValorisations); MustacheScope mustacheScope = injectable.create(); if (mustacheScope.getMissingKeyValueProperties().size() > 0 && buildingFile) { Map<String, String> missing_valuation = new HashMap<>(); Set<KeyValuePropertyModel> missing = mustacheScope.getMissingKeyValueProperties(); missing.stream().forEach(prop -> { missing_valuation.put(prop.getName(), ""); }); mustacheScope = injectable.inject(missing_valuation).create(); } return mustacheScope; }
From source file:ductive.console.commands.register.DefaultCommandRegistry.java
private void register(String[] path, int step, CommandNode node, CommandType command) { Validate.isTrue(path.length > 0); Validate.isTrue(step < path.length); String name = path[step];/*from w w w .ja v a2 s . c om*/ if (step == path.length - 1) { if (node.subnodes.containsKey(name)) { CommandNode n = node.subnodes.get(name); HashSet<String> conflicting = Sets.newHashSet(n.commands.keySet()); conflicting.addAll(n.subnodes.keySet()); throw new RuntimeException(String.format( "error registering command %s: conflicts with subcommand paths %s", toString(command.path), toString(ArrayUtils.subarray(path, 0, step + 1), conflicting))); } if (node.commands.containsKey(name)) throw new RuntimeException(String.format("error registering command %s: already registered", Arrays.toString(command.path))); node.commands.put(name, command); } else { if (node.commands.get(name) != null) throw new RuntimeException( String.format("error registering command %s: conflicts with registered command %s", toString(command.path), toString(ArrayUtils.subarray(path, 0, step + 1)))); CommandNode subnode = node.subnodes.get(name); if (subnode == null) node.subnodes.put(name, subnode = new CommandNode()); register(path, ++step, subnode, command); } }
From source file:com.daiv.android.twitter.services.WidgetRefreshService.java
@Override public void onHandleIntent(Intent intent) { // it is refreshing elsewhere, so don't start if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning || !MainActivity.canSwitch) { return;/*from ww w .ja v a 2s. co m*/ } WidgetRefreshService.isRunning = true; sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.refreshing) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.refreshing_widget) + "...") .setProgress(100, 100, true) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark)); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); Context context = getApplicationContext(); AppSettings settings = AppSettings.getInstance(context); // if they have mobile data on and don't want to sync over mobile data if (Utils.getConnectionStatus(context) && !settings.syncMobile) { return; } Twitter twitter = Utils.getTwitter(context, settings); HomeDataSource dataSource = HomeDataSource.getInstance(context); int currentAccount = sharedPrefs.getInt("current_account", 1); List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>(); boolean foundStatus = false; Paging paging = new Paging(1, 200); long[] lastId; long id; try { lastId = dataSource.getLastIds(currentAccount); id = lastId[0]; } catch (Exception e) { WidgetRefreshService.isRunning = false; return; } paging.setSinceId(id); for (int i = 0; i < settings.maxTweetsRefresh; i++) { try { if (!foundStatus) { paging.setPage(i + 1); List<Status> list = twitter.getHomeTimeline(paging); statuses.addAll(list); if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) { Log.v("Test_inserting", "found status"); foundStatus = true; } else { Log.v("Test_inserting", "haven't found status"); foundStatus = false; } } } catch (Exception e) { // the page doesn't exist foundStatus = true; } catch (OutOfMemoryError o) { // don't know why... } } Log.v("Test_pull", "got statuses, new = " + statuses.size()); // hash set to remove duplicates I guess HashSet hs = new HashSet(); hs.addAll(statuses); statuses.clear(); statuses.addAll(hs); Log.v("Test_inserting", "tweets after hashset: " + statuses.size()); lastId = dataSource.getLastIds(currentAccount); int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId); if (inserted > 0 && statuses.size() > 0) { sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit(); } if (settings.preCacheImages) { startService(new Intent(this, PreCacheService.class)); } context.sendBroadcast(new Intent("com.daiv.android.Test.UPDATE_WIDGET")); getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); mNotificationManager.cancel(6); WidgetRefreshService.isRunning = false; }
From source file:com.klinker.android.twitter.services.WidgetRefreshService.java
@Override public void onHandleIntent(Intent intent) { // it is refreshing elsewhere, so don't start if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning || !MainActivity.canSwitch) { return;/* w w w . ja va 2 s . c om*/ } WidgetRefreshService.isRunning = true; sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.refreshing) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.refreshing_widget) + "...") .setProgress(100, 100, true) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark)); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); Context context = getApplicationContext(); AppSettings settings = AppSettings.getInstance(context); // if they have mobile data on and don't want to sync over mobile data if (Utils.getConnectionStatus(context) && !settings.syncMobile) { return; } Twitter twitter = Utils.getTwitter(context, settings); HomeDataSource dataSource = HomeDataSource.getInstance(context); int currentAccount = sharedPrefs.getInt("current_account", 1); List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>(); boolean foundStatus = false; Paging paging = new Paging(1, 200); long[] lastId; long id; try { lastId = dataSource.getLastIds(currentAccount); id = lastId[0]; } catch (Exception e) { WidgetRefreshService.isRunning = false; return; } paging.setSinceId(id); for (int i = 0; i < settings.maxTweetsRefresh; i++) { try { if (!foundStatus) { paging.setPage(i + 1); List<Status> list = twitter.getHomeTimeline(paging); statuses.addAll(list); if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) { Log.v("talon_inserting", "found status"); foundStatus = true; } else { Log.v("talon_inserting", "haven't found status"); foundStatus = false; } } } catch (Exception e) { // the page doesn't exist foundStatus = true; } catch (OutOfMemoryError o) { // don't know why... } } Log.v("talon_pull", "got statuses, new = " + statuses.size()); // hash set to remove duplicates I guess HashSet hs = new HashSet(); hs.addAll(statuses); statuses.clear(); statuses.addAll(hs); Log.v("talon_inserting", "tweets after hashset: " + statuses.size()); lastId = dataSource.getLastIds(currentAccount); int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId); if (inserted > 0 && statuses.size() > 0) { sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit(); } if (settings.preCacheImages) { startService(new Intent(this, PreCacheService.class)); } context.sendBroadcast(new Intent("com.klinker.android.talon.UPDATE_WIDGET")); getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); mNotificationManager.cancel(6); WidgetRefreshService.isRunning = false; }
From source file:org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest.java
public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) { Object result;//from www.j a v a 2 s.c om if (stat.contains("perc_")) { ArrayList<Integer> percs = new ArrayList<>(1); int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5)) / 100 * list.size()) - 1; percs.add(ord); OrdinalCalculator.putOrdinalsInPosition(list, percs); result = list.get(percs.get(0)); } else if (stat.equals("count")) { result = Long.valueOf(list.size()); } else if (stat.equals("unique")) { HashSet<T> set = new HashSet<>(); set.addAll(list); result = Long.valueOf((long) set.size()); } else if (stat.equals("max")) { Collections.sort(list); result = list.get(list.size() - 1); } else if (stat.equals("min")) { Collections.sort(list); result = list.get(0); } else { result = null; } return result; }
From source file:com.cyclopsgroup.waterview.impl.servlet.ServletRequestParameters.java
/** * Override method doGetAttributeNames in class ServletRequestValueParser * * @see com.cyclopsgroup.waterview.Attributes#doGetAttributeNames() */// w w w . ja va2s. com @Override protected Set<String> doGetAttributeNames() { HashSet<String> names = new HashSet<String>(); CollectionUtils.addAll(names, httpServletRequest.getParameterNames()); if (!extra.isEmpty()) { names.addAll(extra.keySet()); } return names; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.PROJECT) { return false; }// ww w . j a va 2 s . co m ProjectOperator pi = (ProjectOperator) op; Mutable<ILogicalOperator> opRef2 = pi.getInputs().get(0); HashSet<LogicalVariable> toPush = new HashSet<LogicalVariable>(); toPush.addAll(pi.getVariables()); Pair<Boolean, Boolean> p = pushThroughOp(toPush, opRef2, op, context); boolean smthWasPushed = p.first; if (p.second) { // the original projection is redundant opRef.setValue(op.getInputs().get(0).getValue()); smthWasPushed = true; } return smthWasPushed; }
From source file:com.helpinput.spring.refresher.SessiontRefresher.java
@SuppressWarnings("unchecked") ManagedList<Object> getManageList(DefaultListableBeanFactory dlbf, PropertyValue oldPropertyValue) { Set<String> oldClasses = null; if (oldPropertyValue != null) { Object value = oldPropertyValue.getValue(); if (value != null && value instanceof ManagedList) { ManagedList<Object> real = (ManagedList<Object>) value; oldClasses = new HashSet<>(real.size() >>> 1); ClassLoader parentClassLoader = ClassUtils.getDefaultClassLoader(); for (Object object : real) { TypedStringValue typedStringValue = (TypedStringValue) object; String className = typedStringValue.getValue(); try { parentClassLoader.loadClass(className); oldClasses.add(className); } catch (ClassNotFoundException e) { }//from w w w . ja v a 2s.c om } } } int oldClassSize = (Utils.hasLength(oldClasses) ? oldClasses.size() : 0); Map<String, Object> beans = dlbf.getBeansWithAnnotation(Entity.class); HashSet<String> totalClasses = new HashSet<>(beans.size() + oldClassSize); if (oldClassSize > 0) { totalClasses.addAll(oldClasses); } for (Object entity : beans.values()) { String clzName = entity.getClass().getName(); if (!totalClasses.contains(clzName)) { totalClasses.add(clzName); } } ManagedList<Object> list = new ManagedList<>(totalClasses.size()); for (String clzName : totalClasses) { TypedStringValue typedStringValue = new TypedStringValue(clzName); list.add(typedStringValue); } return list; }