Sample all Counters whose name matches given pattern

@param namePattern Name pattern, null means all Counters
@return One Sample for each Counter
437518
@Override
	public List<CounterSample> getCounterSamples(String namePattern) {
		List<CounterSample> counterSamples = new ArrayList<>();
		for (Simon simon : manager.getSimons(SimonPattern.createForCounter(namePattern))) {
			counterSamples.add(sampleCounter(simon));
		}
		return counterSamples;
	}
261283
private org.javasimon.jmx.CounterSample sampleCounter(Simon counter) {
		return new CounterSample((org.javasimon.CounterSample) counter.sample());
	}
390005
protected Counter findCounter(String counterName, String displayName) {
    Counter result = counters.get(counterName);
    if (result == null) {
      result = new Counter(counterName, displayName);
      counters.put(counterName, result);
    }
    return result;
  }
1036622
@GET
  @Produces(APPLICATION_JSON)
  @Timed
  @ExceptionMetered
  public List<String> list(@QueryParam("namePattern") final String namePattern,
                           @QueryParam("selector") final List<String> hostSelectors) {

    List<String> hosts = namePattern == null ? model.listHosts() : model.listHosts(namePattern);

    if (!hostSelectors.isEmpty()) {
      // check that all supplied selectors are parseable/valid
      final List<HostSelector> selectors = hostSelectors.stream()
          .map(selectorStr -> {
            final HostSelector parsed = HostSelector.parse(selectorStr);
            if (parsed == null) {
              throw new WebApplicationException(
                  Response.status(Response.Status.BAD_REQUEST)
                      .entity("Invalid host selector: " + selectorStr)
                      .build()
              );
            }
            return parsed;
          })
          .collect(Collectors.toList());

      final Map<String, Map<String, String>> hostsAndLabels = getLabels(hosts);

      final HostMatcher matcher = new HostMatcher(hostsAndLabels);
      hosts = matcher.getMatchingHosts(selectors);
    }

    return hosts;
  }
1229899
public static Set<SelectorName> nameSetFrom( SelectorName name ) {
        if (name == null) return Collections.emptySet();
        return Collections.singleton(name);
    }
158717
public boolean optionMatches(String namePattern, String valuePattern) {
    Matcher nameMatcher = Pattern.compile(namePattern).matcher("");
    Matcher valueMatcher = Pattern.compile(valuePattern).matcher("");
    for (Map.Entry<ProtoMember, Object> entry : map.entrySet()) {
      if (nameMatcher.reset(entry.getKey().member()).matches()
          && valueMatcher.reset(String.valueOf(entry.getValue())).matches()) {
        return true;
      }
    }
    return false;
  }
103178
public static WildcardPattern[] create(@Nullable String[] patterns) {
    if (patterns == null) {
      return new WildcardPattern[0];
    }
    WildcardPattern[] exclusionPAtterns = new WildcardPattern[patterns.length];
    for (int i = 0; i < patterns.length; i++) {
      exclusionPAtterns[i] = create(patterns[i]);
    }
    return exclusionPAtterns;
  }
741897
public List<BaseDescr> getRemainingPatterns() {
        if ( this.patterns.size() > 1 ) {
            return this.patterns.subList( 1,
                                          this.patterns.size() );
        } else if ( this.patterns.size() == 1 ) {
            // in case there is only one pattern, we do a rewrite, so:
            // forall( Cheese( type == "stilton" ) )
            // becomes
            // forall( BASE_IDENTIFIER : Cheese() Cheese( this == BASE_IDENTIFIER, type == "stilton" ) )
            PatternDescr original = (PatternDescr) this.patterns.get( 0 );
            PatternDescr remaining = (PatternDescr) original.clone();
            remaining.addConstraint( new ExprConstraintDescr( "this == " + BASE_IDENTIFIER ) );
            remaining.setResource(original.getResource());
            return Collections.singletonList( (BaseDescr)remaining );
        }
        return Collections.emptyList();
    }
617400
public static boolean contains(String name, Iterable<String> patterns) {
        String nameUpper = name.toUpperCase();
        for (String pattern : patterns) {
            String patternUpper = pattern.toUpperCase();
            if (nameUpper.equals(patternUpper) || nameUpper.contains(patternUpper)) {
                return true;
            }
        }

        return false;
    }
84928
public boolean matches(String name) {
		if (name == null) {
			return pattern.equals("");
		}
		if (all != null) {
			return all.equals(name);
		}
		if (middle != null) {
			return name.contains(middle);
		}
		if (start != null && !name.startsWith(start)) {
			return false;
		}

		return end == null || name.endsWith(end);
	}
199142
public Collection<? extends NameClassPair> listInstances(NamingConstants.JavaColonNamespace namespace, String contextName) throws NamingException {
        if (namespace == NamingConstants.JavaColonNamespace.COMP) {
            return listInstances(compLock, compBindings, contextName);
        }
        if (namespace == NamingConstants.JavaColonNamespace.COMP_ENV) {
            return listInstances(compLock, compEnvBindings, contextName);
        }
        if (namespace == this.namespace) {
            return listInstances(nonCompEnvLock, nonCompBindings, contextName);
        }
        return Collections.emptyList();
    }
640292
public Map<String, Class<?>> scan(String classNamePattern) throws IOException {
        final Map<String, Class<?>> scannedClasses = new LinkedHashMap<>();
        scan(classNamePattern, scannedClasses);
        return scannedClasses;
    }
995272
public static final String convertPattern(String pattern) {
        if (pattern == null) {
            return null;
        }
        else {
            String convertedPattern = pattern;
            for (PatternConverter converter : PATTERN_CONVERTERS) {
                convertedPattern = converter.convert(convertedPattern);
            }

            return convertedPattern;
        }
    }
325726
protected PMultipleBind getMultipleSetBind(PExp setExp,
			ILexNameToken... patternNames)
	{
		ASetMultipleBind setBind = new ASetMultipleBind();
		List<PPattern> patternList = new Vector<PPattern>();

		for (ILexNameToken patternName : patternNames)
		{
			AIdentifierPattern pattern = new AIdentifierPattern();
			pattern.setName(patternName.clone());
			patternList.add(pattern);
		}

		setBind.setPlist(patternList);
		setBind.setSet(setExp.clone());

		return setBind;
	}
1226023
protected boolean name_matches(String pattern) {
	pattern = pattern.toLowerCase().replaceAll("[*]{1}", ".*?");
	return name.toLowerCase().matches(pattern) || get_fully_qualified_name().toLowerCase().matches(pattern);
    }
853641
public void applyPattern(String newPattern) {
        StringBuffer[] segments = new StringBuffer[2];
        for (int i = 0; i < segments.length; ++i) {
            segments[i] = new StringBuffer();
        }
        double[] newChoiceLimits = new double[30];
        String[] newChoiceFormats = new String[30];
        int count = 0;
        int part = 0;
        double startValue = 0;
        double oldStartValue = Double.NaN;
        boolean inQuote = false;
        for (int i = 0; i < newPattern.length(); ++i) {
            char ch = newPattern.charAt(i);
            if (ch=='\'') {
                // Check for "''" indicating a literal quote
                if ((i+1)<newPattern.length() && newPattern.charAt(i+1)==ch) {
                    segments[part].append(ch);
                    ++i;
                } else {
                    inQuote = !inQuote;
                }
            } else if (inQuote) {
                segments[part].append(ch);
            } else if (ch == '<' || ch == '#' || ch == '\u2264') {
                if (segments[0].length() == 0) {
                    throw new IllegalArgumentException();
                }
                try {
                    String tempBuffer = segments[0].toString();
                    if (tempBuffer.equals("\u221E")) {
                        startValue = Double.POSITIVE_INFINITY;
                    } else if (tempBuffer.equals("-\u221E")) {
                        startValue = Double.NEGATIVE_INFINITY;
                    } else {
                        startValue = Double.valueOf(segments[0].toString()).doubleValue();
                    }
                } catch (Exception e) {
                    throw new IllegalArgumentException();
                }
                if (ch == '<' && startValue != Double.POSITIVE_INFINITY &&
                        startValue != Double.NEGATIVE_INFINITY) {
                    startValue = nextDouble(startValue);
                }
                if (startValue <= oldStartValue) {
                    throw new IllegalArgumentException();
                }
                segments[0].setLength(0);
                part = 1;
            } else if (ch == '|') {
                if (count == newChoiceLimits.length) {
                    newChoiceLimits = doubleArraySize(newChoiceLimits);
                    newChoiceFormats = doubleArraySize(newChoiceFormats);
                }
                newChoiceLimits[count] = startValue;
                newChoiceFormats[count] = segments[1].toString();
                ++count;
                oldStartValue = startValue;
                segments[1].setLength(0);
                part = 0;
            } else {
                segments[part].append(ch);
            }
        }
        // clean up last one
        if (part == 1) {
            if (count == newChoiceLimits.length) {
                newChoiceLimits = doubleArraySize(newChoiceLimits);
                newChoiceFormats = doubleArraySize(newChoiceFormats);
            }
            newChoiceLimits[count] = startValue;
            newChoiceFormats[count] = segments[1].toString();
            ++count;
        }
        choiceLimits = new double[count];
        System.arraycopy(newChoiceLimits, 0, choiceLimits, 0, count);
        choiceFormats = new String[count];
        System.arraycopy(newChoiceFormats, 0, choiceFormats, 0, count);
    }
535538
public <E extends SamplingEntry> Iterable<E> getRandomSamples(int sampleCount) {
        if (sampleCount < 0) {
            throw new IllegalArgumentException("Sample count cannot be a negative value.");
        }
        if (sampleCount == 0 || size() == 0) {
            return Collections.EMPTY_LIST;
        }
        return new LazySamplingEntryIterableIterator<E>(sampleCount);
    }