List of usage examples for java.util Set clear
void clear();
From source file:org.apache.lens.cube.parse.TestDateUtil.java
@Test public void testTimeDiff() throws SemanticException { ArrayList<String> minusFourDays = Lists.newArrayList("-4 days", "-4days", "-4day", "-4 day", "- 4days", "- 4 day"); ArrayList<String> plusFourDays = Lists.newArrayList("+4 days", "4 days", "+4days", "4day", "4 day", "+ 4days", "+ 4 day", "+4 day"); Set<TimeDiff> diffs = Sets.newHashSet(); for (String diffStr : minusFourDays) { diffs.add(TimeDiff.parseFrom(diffStr)); }/*from w w w . j a v a 2s . co m*/ assertEquals(diffs.size(), 1); TimeDiff minusFourDaysDiff = diffs.iterator().next(); assertEquals(minusFourDaysDiff.quantity, -4); assertEquals(minusFourDaysDiff.calendarField, DAY_OF_MONTH); diffs.clear(); for (String diffStr : plusFourDays) { diffs.add(TimeDiff.parseFrom(diffStr)); } assertEquals(diffs.size(), 1); TimeDiff plusFourDaysDiff = diffs.iterator().next(); assertEquals(plusFourDaysDiff.quantity, 4); assertEquals(plusFourDaysDiff.calendarField, DAY_OF_MONTH); Date now = new Date(); assertEquals(minusFourDaysDiff.offsetFrom(plusFourDaysDiff.offsetFrom(now)), now); assertEquals(plusFourDaysDiff.offsetFrom(minusFourDaysDiff.offsetFrom(now)), now); assertEquals(minusFourDaysDiff.negativeOffsetFrom(now), plusFourDaysDiff.offsetFrom(now)); assertEquals(minusFourDaysDiff.offsetFrom(now), plusFourDaysDiff.negativeOffsetFrom(now)); }
From source file:mitm.application.djigzo.impl.DefaultDomainManager.java
private void addInheritedPreferences(String domain, UserPreferences newDomainPreferences) throws HierarchicalPropertiesException, CloseableIteratorException { boolean isWildcardDomain = DomainUtils.isWildcardDomain(domain); if (isWildcardDomain) { /*//from w ww .ja v a 2s . c om * Wildcard domains will always inherit the global preferences */ newDomainPreferences.getInheritedUserPreferences() .add(globalPreferencesManager.getGlobalUserPreferences()); /* * Since we are adding a wild card domain, we need to check whether there are already domains * that match the wild card domain because those domains will inherit from the wild card domain * * Note: we MUST use the stateful version to get all domains to make sure that domains added * within the same transaction are used */ CloseableIterator<String> domainIterator = getUserPreferencesManager().getStatefulNameIterator(); try { while (domainIterator.hasNext()) { String toCheckDomain = domainIterator.next(); if (DomainUtils.isWildcardDomain(toCheckDomain)) { /* * Wilcard domains do not inherit other domains */ continue; } if (DomainUtils.isWildcardMatchDomain(toCheckDomain, domain)) { /* * It could be that there is already a higher prio wildcard domain. For example * sub.example.com should inherit from *.sub.example.com and not from *.example.com. * Only do this check if the domain to check is not the domain we are about to add */ String toCheckWildcardDomain = "*." + toCheckDomain; if (!toCheckWildcardDomain.equals(domain) && getDomainPreferences(toCheckWildcardDomain) != null) { /* * There is a higher prio domain */ continue; } UserPreferences toCheckDomainPrefs = getDomainPreferences(toCheckDomain); if (toCheckDomainPrefs != null) { Set<UserPreferences> inherited = toCheckDomainPrefs.getInheritedUserPreferences(); /* * The domain will inherit from the wildcard domain only so we will clear * the 'live' set of inherited preferences first */ inherited.clear(); /* * Inherit from the new wildcard domain */ inherited.add(newDomainPreferences); } } } } finally { CloseableIteratorUtils.closeQuietly(domainIterator); } } else { /* * The new domain is not a wildcard domain. We now need to check if there is already a wildcard * domain because the new domain need to inherit the wildcard domain. * * First check if there is a wildcard domain with appending * and then check upper level. * * Example: * * if domain is sub.example.com, if *.sub.example.com exists, it's used. If not, it's checked * whether *.example.com exist */ UserPreferences wildcardDomain = getDomainPreferences("*." + domain); if (wildcardDomain == null) { /* * Now check if there is a wildcard domain for the upper level domain */ String upperDomain = DomainUtils.getUpperLevelDomain(domain); if (StringUtils.isNotEmpty(upperDomain)) { wildcardDomain = getDomainPreferences("*." + upperDomain); } } if (wildcardDomain != null) { /* * Inherit from the new domain */ newDomainPreferences.getInheritedUserPreferences().add(wildcardDomain); } else { /* * There was no wildcard domain so the new domain must inherit the global preferences */ newDomainPreferences.getInheritedUserPreferences() .add(globalPreferencesManager.getGlobalUserPreferences()); } } }
From source file:org.apache.syncope.core.logic.report.ReconciliationReportlet.java
private void doExtract(final ContentHandler handler, final List<? extends Any<?>> anys) throws SAXException, ReportException { final Set<Missing> missing = new HashSet<>(); final Set<Misaligned> misaligned = new HashSet<>(); for (Any<?> any : anys) { missing.clear(); misaligned.clear();//from w w w. ja v a 2s . c o m AnyUtils anyUtils = anyUtilsFactory.getInstance(any); for (final ExternalResource resource : anyUtils.getAllResources(any)) { Provision provision = resource.getProvision(any.getType()); MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); final String connObjectKeyValue = connObjectKeyItem == null ? StringUtils.EMPTY : mappingManager.getConnObjectKeyValue(any, provision); if (provision != null && connObjectKeyItem != null && StringUtils.isNotBlank(connObjectKeyValue)) { // 1. read from the underlying connector Connector connector = connFactory.getConnector(resource); ConnectorObject connectorObject = connector.getObject(provision.getObjectClass(), new Uid(connObjectKeyValue), MappingUtils.buildOperationOptions(provision.getMapping().getItems().iterator())); if (connectorObject == null) { // 2. not found on resource? LOG.error("Object {} with class {} not found on resource {}", connObjectKeyValue, provision.getObjectClass(), resource); missing.add(new Missing(resource.getKey(), connObjectKeyValue)); } else { // 3. found but misaligned? Pair<String, Set<Attribute>> preparedAttrs = mappingManager.prepareAttrs(any, null, false, null, provision); preparedAttrs.getRight().add(AttributeBuilder.build(Uid.NAME, preparedAttrs.getLeft())); preparedAttrs.getRight().add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), preparedAttrs.getLeft())); final Map<String, Set<Object>> syncopeAttrs = new HashMap<>(); for (Attribute attr : preparedAttrs.getRight()) { syncopeAttrs.put(attr.getName(), attr.getValue() == null ? null : new HashSet<>(attr.getValue())); } final Map<String, Set<Object>> resourceAttrs = new HashMap<>(); for (Attribute attr : connectorObject.getAttributes()) { if (!OperationalAttributes.PASSWORD_NAME.equals(attr.getName()) && !OperationalAttributes.ENABLE_NAME.equals(attr.getName())) { resourceAttrs.put(attr.getName(), attr.getValue() == null ? null : new HashSet<>(attr.getValue())); } } IterableUtils.forEach( CollectionUtils.subtract(syncopeAttrs.keySet(), resourceAttrs.keySet()), new Closure<String>() { @Override public void execute(final String name) { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, name, syncopeAttrs.get(name), Collections.emptySet())); } }); for (Map.Entry<String, Set<Object>> entry : resourceAttrs.entrySet()) { if (syncopeAttrs.containsKey(entry.getKey())) { if (!Objects.equals(syncopeAttrs.get(entry.getKey()), entry.getValue())) { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), syncopeAttrs.get(entry.getKey()), entry.getValue())); } } else { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), Collections.emptySet(), entry.getValue())); } } } } } if (!missing.isEmpty() || !misaligned.isEmpty()) { doExtract(handler, any, missing, misaligned); } } }
From source file:org.apache.syncope.core.provisioning.java.job.report.ReconciliationReportlet.java
private void doExtract(final ContentHandler handler, final List<? extends Any<?>> anys) throws SAXException, ReportException { final Set<Missing> missing = new HashSet<>(); final Set<Misaligned> misaligned = new HashSet<>(); for (Any<?> any : anys) { missing.clear(); misaligned.clear();/*w w w.j a va 2 s . c o m*/ AnyUtils anyUtils = anyUtilsFactory.getInstance(any); anyUtils.getAllResources(any).forEach(resource -> { Provision provision = resource.getProvision(any.getType()).orElse(null); Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); final String connObjectKeyValue = connObjectKeyItem.isPresent() ? mappingManager.getConnObjectKeyValue(any, provision).get() : StringUtils.EMPTY; if (provision != null && connObjectKeyItem.isPresent() && StringUtils.isNotBlank(connObjectKeyValue)) { // 1. read from the underlying connector Connector connector = connFactory.getConnector(resource); ConnectorObject connectorObject = connector.getObject(provision.getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue), MappingUtils.buildOperationOptions(provision.getMapping().getItems().iterator())); if (connectorObject == null) { // 2. not found on resource? LOG.error("Object {} with class {} not found on resource {}", connObjectKeyValue, provision.getObjectClass(), resource); missing.add(new Missing(resource.getKey(), connObjectKeyValue)); } else { // 3. found but misaligned? Pair<String, Set<Attribute>> preparedAttrs = mappingManager.prepareAttrs(any, null, false, null, provision); preparedAttrs.getRight().add(AttributeBuilder.build(Uid.NAME, preparedAttrs.getLeft())); preparedAttrs.getRight().add(AttributeBuilder .build(connObjectKeyItem.get().getExtAttrName(), preparedAttrs.getLeft())); final Map<String, Set<Object>> syncopeAttrs = new HashMap<>(); preparedAttrs.getRight().forEach(attr -> { syncopeAttrs.put(attr.getName(), getValues(attr)); }); final Map<String, Set<Object>> resourceAttrs = new HashMap<>(); connectorObject.getAttributes().stream() .filter(attr -> (!OperationalAttributes.PASSWORD_NAME.equals(attr.getName()) && !OperationalAttributes.ENABLE_NAME.equals(attr.getName()))) .forEachOrdered(attr -> { resourceAttrs.put(attr.getName(), getValues(attr)); }); syncopeAttrs.keySet().stream() .filter(syncopeAttr -> !resourceAttrs.containsKey(syncopeAttr)).forEach(name -> { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, name, syncopeAttrs.get(name), Collections.emptySet())); }); resourceAttrs.entrySet().forEach(entry -> { if (syncopeAttrs.containsKey(entry.getKey())) { if (!Objects.equals(syncopeAttrs.get(entry.getKey()), entry.getValue())) { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), syncopeAttrs.get(entry.getKey()), entry.getValue())); } } else { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), Collections.emptySet(), entry.getValue())); } }); } } }); if (!missing.isEmpty() || !misaligned.isEmpty()) { doExtract(handler, any, missing, misaligned); } } }
From source file:com.alibaba.napoli.gecko.service.timer.HashedWheelTimer.java
public synchronized Set<Timeout> stop() { if (!this.shutdown.compareAndSet(false, true)) { return Collections.emptySet(); }/* w w w . j a va 2 s .c o m*/ boolean interrupted = false; while (this.workerThread.isAlive()) { this.workerThread.interrupt(); try { this.workerThread.join(100); } catch (final InterruptedException e) { interrupted = true; } } if (interrupted) { Thread.currentThread().interrupt(); } activeInstances.decrementAndGet(); final Set<Timeout> unprocessedTimeouts = new HashSet<Timeout>(); for (final Set<HashedWheelTimeout> bucket : this.wheel) { unprocessedTimeouts.addAll(bucket); bucket.clear(); } return Collections.unmodifiableSet(unprocessedTimeouts); }
From source file:com.daiv.android.twitter.settings.SettingsActivityOld.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit); AppSettings.invalidate();//ww w .j a v a2 s.c o m setUpTheme(); setContentView(R.layout.settings_main); DrawerArrayAdapter.current = 0; linkItems = new String[] { getResources().getString(R.string.get_help_settings), getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new), getResources().getString(R.string.rate_it) }; settingsItems = new String[] { getResources().getString(R.string.ui_settings), getResources().getString(R.string.timelines_settings), getResources().getString(R.string.sync_settings), getResources().getString(R.string.notification_settings), getResources().getString(R.string.browser_settings), getResources().getString(R.string.advanced_settings), getResources().getString(R.string.memory_manage) }; sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); if (sharedPrefs.getBoolean("version_1.20_1", true)) { // necessary because i didnt start out by using sets boolean led = sharedPrefs.getBoolean("led", true); boolean sound = sharedPrefs.getBoolean("sound", true); boolean vibrate = sharedPrefs.getBoolean("vibrate", true); boolean wakeScreen = sharedPrefs.getBoolean("wake", true); boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true); boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true); boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true); boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true); boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true); boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true); Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>()); alert.clear(); if (vibrate) { alert.add("1"); } if (led) { alert.add("2"); } if (wakeScreen) { alert.add("3"); } if (sound) { alert.add("4"); } sharedPrefs.edit().putStringSet("alert_types", alert).commit(); Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>()); timeline.clear(); if (timelineNot) { timeline.add("1"); } if (mentionsNot) { timeline.add("2"); } if (dmsNot) { timeline.add("3"); } sharedPrefs.edit().putStringSet("timeline_set", timeline).commit(); Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>()); interactions.clear(); if (favoritesNot) { interactions.add("1"); } if (retweetNot) { interactions.add("2"); } if (followersNot) { interactions.add("3"); } sharedPrefs.edit().putStringSet("interactions_set", interactions).commit(); sharedPrefs.edit().putBoolean("version_1.20_1", false).commit(); recreate(); } mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START); otherList = (ListView) findViewById(R.id.other_list); settingsList = (ListView) findViewById(R.id.settings_list); mDrawer = (LinearLayout) findViewById(R.id.drawer); // Set the adapter for the list view otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems)))); settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems)))); // Set the list's click listener settingsList.setOnItemClickListener( new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer)); otherList.setOnItemClickListener( new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer)); findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switchToSettingsList(true); settingsLinksActive = true; findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE); findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE); } }); findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switchToSettingsList(false); settingsLinksActive = false; findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE); findViewById(R.id.otherSelector).setVisibility(View.VISIBLE); } }); if (settingsLinksActive) { settingsList.setVisibility(View.VISIBLE); otherList.setVisibility(View.GONE); findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE); findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE); } else { settingsList.setVisibility(View.GONE); otherList.setVisibility(View.VISIBLE); findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE); findViewById(R.id.otherSelector).setVisibility(View.VISIBLE); } TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon }); int resource = a.getResourceId(0, 0); a.recycle(); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ resource, /* nav drawer icon to replace 'Up' caret */ R.string.app_name, /* "open drawer" description */ R.string.app_name /* "close drawer" description */ ); mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false); mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { public void onPageScrollStateChanged(int state) { } public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } public void onPageSelected(int position) { DrawerArrayAdapter.current = position; otherList.invalidateViews(); settingsList.invalidateViews(); } }); if (!userKnows) { mDrawerLayout.openDrawer(mDrawer); } HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by); HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number); try { String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; String text = getResources().getString(R.string.created_by) + " daiv"; String text2 = getResources().getString(R.string.version) + " " + versionName; createdBy.setText(text); versionNumber.setText(text2); } catch (Exception e) { String text = getResources().getString(R.string.created_by) + " daiv"; String text2 = getResources().getString(R.string.version) + " 0.00"; createdBy.setText(text); versionNumber.setText(text2); } LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=daiv+Apps"))); } }); mDrawerLayout.openDrawer(Gravity.START); }
From source file:com.klinker.android.twitter.settings.SettingsActivityOld.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit); AppSettings.invalidate();/* w ww .j av a 2 s. c o m*/ setUpTheme(); setContentView(R.layout.settings_main); DrawerArrayAdapter.current = 0; linkItems = new String[] { getResources().getString(R.string.get_help_settings), getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new), getResources().getString(R.string.rate_it) }; settingsItems = new String[] { getResources().getString(R.string.ui_settings), getResources().getString(R.string.timelines_settings), getResources().getString(R.string.sync_settings), getResources().getString(R.string.notification_settings), getResources().getString(R.string.browser_settings), getResources().getString(R.string.advanced_settings), getResources().getString(R.string.memory_manage) }; sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); if (sharedPrefs.getBoolean("version_1.20_1", true)) { // necessary because i didnt start out by using sets boolean led = sharedPrefs.getBoolean("led", true); boolean sound = sharedPrefs.getBoolean("sound", true); boolean vibrate = sharedPrefs.getBoolean("vibrate", true); boolean wakeScreen = sharedPrefs.getBoolean("wake", true); boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true); boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true); boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true); boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true); boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true); boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true); Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>()); alert.clear(); if (vibrate) { alert.add("1"); } if (led) { alert.add("2"); } if (wakeScreen) { alert.add("3"); } if (sound) { alert.add("4"); } sharedPrefs.edit().putStringSet("alert_types", alert).commit(); Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>()); timeline.clear(); if (timelineNot) { timeline.add("1"); } if (mentionsNot) { timeline.add("2"); } if (dmsNot) { timeline.add("3"); } sharedPrefs.edit().putStringSet("timeline_set", timeline).commit(); Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>()); interactions.clear(); if (favoritesNot) { interactions.add("1"); } if (retweetNot) { interactions.add("2"); } if (followersNot) { interactions.add("3"); } sharedPrefs.edit().putStringSet("interactions_set", interactions).commit(); sharedPrefs.edit().putBoolean("version_1.20_1", false).commit(); recreate(); } mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START); otherList = (ListView) findViewById(R.id.other_list); settingsList = (ListView) findViewById(R.id.settings_list); mDrawer = (LinearLayout) findViewById(R.id.drawer); // Set the adapter for the list view otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems)))); settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems)))); // Set the list's click listener settingsList.setOnItemClickListener( new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer)); otherList.setOnItemClickListener( new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer)); findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switchToSettingsList(true); settingsLinksActive = true; findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE); findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE); } }); findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switchToSettingsList(false); settingsLinksActive = false; findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE); findViewById(R.id.otherSelector).setVisibility(View.VISIBLE); } }); if (settingsLinksActive) { settingsList.setVisibility(View.VISIBLE); otherList.setVisibility(View.GONE); findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE); findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE); } else { settingsList.setVisibility(View.GONE); otherList.setVisibility(View.VISIBLE); findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE); findViewById(R.id.otherSelector).setVisibility(View.VISIBLE); } TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon }); int resource = a.getResourceId(0, 0); a.recycle(); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ resource, /* nav drawer icon to replace 'Up' caret */ R.string.app_name, /* "open drawer" description */ R.string.app_name /* "close drawer" description */ ); mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false); mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { public void onPageScrollStateChanged(int state) { } public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } public void onPageSelected(int position) { DrawerArrayAdapter.current = position; otherList.invalidateViews(); settingsList.invalidateViews(); } }); if (!userKnows) { mDrawerLayout.openDrawer(mDrawer); } HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by); HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number); try { String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; String text = getResources().getString(R.string.created_by) + " Luke Klinker"; String text2 = getResources().getString(R.string.version) + " " + versionName; createdBy.setText(text); versionNumber.setText(text2); } catch (Exception e) { String text = getResources().getString(R.string.created_by) + " Luke Klinker"; String text2 = getResources().getString(R.string.version) + " 0.00"; createdBy.setText(text); versionNumber.setText(text2); } LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Klinker+Apps"))); } }); mDrawerLayout.openDrawer(Gravity.START); }
From source file:com.yahoo.flowetl.core.Plumber.java
/** * Translates a set of roots into a runnable object. * //from w w w . j a v a2s . c om * @param roots * * @return the pipe runner * * @throws PipeException */ public PipeRunner translate(final Set<Pipe> roots) throws PipeException { if (roots == null || roots.isEmpty()) { throw new IllegalArgumentException("No valid pipes provided"); } // first translate to a graph final DefaultDirectedGraph<Pipe, PipeEdge> runGraph = new DefaultDirectedGraph<Pipe, PipeEdge>( new EdgeFactory<Pipe, PipeEdge>() { @Override public PipeEdge createEdge(Pipe src, Pipe tgt) { StringBuilder tmp = new StringBuilder(); tmp.append("{" + src.getName() + "}"); tmp.append("->"); tmp.append("{" + tgt.getName() + "}"); return new PipeEdge(tmp.toString()); } }); // find all reachable pipes from the given roots final Set<Pipe> reachableInputs = new HashSet<Pipe>(); Set<Pipe> reachablePipesTmp = new HashSet<Pipe>(); for (Pipe p : roots) { discoverReachable(p, reachablePipesTmp); reachableInputs.addAll(reachablePipesTmp); reachableInputs.add(p); reachablePipesTmp.clear(); } // add as vertexes.. for (Pipe p : reachableInputs) { runGraph.addVertex(p); } // connect together for (Pipe v : reachableInputs) { List<Pipe> outs = v.getOutputs(); if (outs != null) { int max = v.maxOutputs(); int cur = outs.size(); if (max != -1 && (max < cur)) { throw new PipeException( "Pipe " + v + " is only allowed " + max + " outputs but it has " + cur + " outputs"); } for (Pipe t : outs) { if (t == null) { continue; } PipeEdge edgeName = runGraph.addEdge(v, t); if (logger.isEnabled(Level.INFO)) { logger.log(Level.INFO, "Connected " + v + " to " + t + " with edge " + edgeName); } } } } // do cycle detection CycleDetector<Pipe, PipeEdge> cycleDetect = new CycleDetector<Pipe, PipeEdge>(runGraph); Set<Pipe> cycleNodes = cycleDetect.findCycles(); if (cycleNodes != null && cycleNodes.isEmpty() == false) { StringBuilder msg = new StringBuilder("The following pipes are causing cycles ["); msg.append(StringUtils.join(cycleNodes, ",")); msg.append("]"); throw new PipeException(msg.toString()); } // check connected components ConnectivityInspector<Pipe, PipeEdge> cInspector = new ConnectivityInspector<Pipe, PipeEdge>(runGraph); if (cInspector.isGraphConnected() == false) { throw new PipeException( "The pipes provided have occurences which do not actually connect to other pipes"); } // display if (logger.isEnabled(Level.DEBUG)) { StringWriter w = new StringWriter(); DOTExporter<Pipe, PipeEdge> d = new DOTExporter<Pipe, PipeEdge>(new VertexNameProvider<Pipe>() { @Override public String getVertexName(Pipe p) { return p.getName(); } }, new VertexNameProvider<Pipe>() { @Override public String getVertexName(Pipe p) { return p.getName(); } }, new EdgeNameProvider<PipeEdge>() { @Override public String getEdgeName(PipeEdge e) { return String.valueOf(e); } }); d.export(w, runGraph); try { w.close(); } catch (IOException e1) { // should be ok to ignore this... } logger.log(Level.DEBUG, w.toString()); } // all verified, yippe PipeRunner out = new PipeRunner() { @Override public void run() { // use topological order to figure out // how to run this graph in a way // that will ensure the inputs are satisfied // before a vertex is ran... GraphIterator<Pipe, PipeEdge> it = makeTraversalIterator(runGraph); // get the ordering first // which doesn't involve activating any of the pipes // just seeing what the iteration order will be... final List<Pipe> order = IterUtils.toList(it, ArrayList.class); // now make the real run iterator it = makeTraversalIterator(runGraph); it.addTraversalListener(new TraversalListenerAdapter<Pipe, PipeEdge>() { @Override public void vertexTraversed(VertexTraversalEvent<Pipe> v) { if (logger.isEnabled(Level.INFO)) { logger.log(Level.INFO, "Vertex " + v.getVertex() + " was visited"); } } }); StopWatch overallTimer = new StopWatch(); overallTimer.start(); notifyStart(order); // keep track of which ones we exec'ed // maybe for use later?? final List<Pipe> curExecd = new ArrayList<Pipe>(order.size()); // iterate StopWatch perRunTimer = new StopWatch(); List<Pipe> pipeOutputs = null; PipeResult pipeRes = null; while (it.hasNext()) { Pipe toRun = it.next(); perRunTimer.reset(); perRunTimer.start(); notifyStartGenerate(toRun); { pipeRes = toRun.generateOutput(); } perRunTimer.stop(); curExecd.add(toRun); pipeOutputs = toRun.getOutputs(); if (pipeOutputs != null) { for (Pipe tmp : pipeOutputs) { if (tmp == null) { continue; } tmp.attachInput(pipeRes); } } notifyFinishGenerate(toRun, pipeRes, perRunTimer.getTime()); // now clear it toRun.clearInputs(); } overallTimer.stop(); notifyComplete(overallTimer.getTime()); } }; return out; }
From source file:nl.b3p.geotools.data.arcgis.ArcGISFeatureReader.java
private String getOutFields() { if (outFields != null) { return outFields; }/*from ww w . j av a2s . com*/ Set<String> s = new HashSet<String>(); // We always need the id if (objectIdFieldName != null) { // No objectID in 9.x s.add(objectIdFieldName); } if (query.getPropertyNames() == Query.ALL_NAMES) { // Undocumented shortcut! s.clear(); s.add("*"); //for(AttributeDescriptor ad: getFeatureType().getAttributeDescriptors()) { // s.add(ad.getLocalName()); //} returnGeometry = true; } else if (query.getPropertyNames().length > 0) { s.addAll(Arrays.asList(query.getPropertyNames())); returnGeometry = s.contains(getFeatureType().getGeometryDescriptor().getLocalName()); s.remove(ArcGISFeatureSource.DEFAULT_GEOMETRY_ATTRIBUTE_NAME); } StringBuilder sb = new StringBuilder(); for (String name : s) { if (sb.length() > 0) { sb.append(","); } sb.append(name); } outFields = sb.toString(); return outFields; }
From source file:com.wbrenna.gtfsoffline.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); }// ww w .j a v a 2s .co m mProgress = (ProgressBar) findViewById(R.id.progress); //read in the preferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Set<String> emptyString = new HashSet<String>(); emptyString.clear(); Set<String> initial_preferences = mPrefs.getStringSet(getString(R.string.pref_dbs), emptyString); mDBListPrefsOld = initial_preferences; //this is the list of currently checked databases String[] tmpDBActive = initial_preferences.toArray(new String[initial_preferences.size()]); //we have to be careful to exclude databases that aren't in our directory dbHelper = new DatabaseHelper(this); dbHelper.gatherFiles(); mDBList = dbHelper.GetListofDB(); List<String> workingDBList = new ArrayList<String>(); for (int i = 0; i < tmpDBActive.length; i++) { if (mDBList.contains(tmpDBActive[i])) { workingDBList.add(tmpDBActive[i]); } else { initial_preferences.remove(tmpDBActive[i]); } } if (workingDBList.size() == 0) { mDBActive = null; } else { mDBActive = workingDBList.toArray(new String[workingDBList.size()]); } Editor prefsDBEditor = mPrefs.edit(); prefsDBEditor.putStringSet(getString(R.string.pref_dbs), initial_preferences); prefsDBEditor.commit(); //Set up the location management mLocationHelper = new LocationHelper(this); mLocation = mLocationHelper.startLocationManager(); // Define a listener that responds to location updates locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (mLocationHelper.isBetterLocation(location, mLocation)) { mLocation = location; if (mLocation != null) { //new ProcessBusStops().execute(); mSectionsPagerAdapter.notifyDataSetChanged(); } else { Toast.makeText(getBaseContext(), R.string.last_location_fix, Toast.LENGTH_LONG).show(); //Log.e(TAG, "No more location fixes "); } } } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; //TODO: eventually add automated downloading of databases... // Create the adapter that will return a fragment for each of the // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }