Java Code Examples for java.util.SortedMap#containsKey()

The following examples show how to use java.util.SortedMap#containsKey() . These examples are extracted from open source projects. 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
/**
 * Creates thin client descriptions from the test configuration parameters.
 */
protected static Map configure(TestConfig config, GfxdTestConfig sconfig) {

  ConfigHashtable tab = config.getParameters();
  List<String> usedClients = new ArrayList();

  // create a description for each thin client name
  SortedMap<String,ThinClientDescription> tcds = new TreeMap();
  Vector names = tab.vecAt(ThinClientPrms.names, new HydraVector());
  for (int i = 0; i < names.size(); i++) {
    String name = (String)names.elementAt(i);
    if (tcds.containsKey(name)) {
      String s = BasePrms.nameForKey(ThinClientPrms.names)
               + " contains duplicate entries: " + names;
      throw new HydraConfigException(s);
    }
    ThinClientDescription tcd = createThinClientDescription(name, config, i,
                                                            usedClients);
    tcds.put(name, tcd);
  }
  return tcds;
}
 
Example 2
private static SortedMap<String, Object> makeMap(
        String[] itemNames, Object[] itemValues)
        throws OpenDataException {

    if (itemNames == null || itemValues == null)
        throw new IllegalArgumentException("Null itemNames or itemValues");
    if (itemNames.length == 0 || itemValues.length == 0)
        throw new IllegalArgumentException("Empty itemNames or itemValues");
    if (itemNames.length != itemValues.length) {
        throw new IllegalArgumentException(
                "Different lengths: itemNames[" + itemNames.length +
                "], itemValues[" + itemValues.length + "]");
    }

    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (int i = 0; i < itemNames.length; i++) {
        String name = itemNames[i];
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Null or empty item name");
        if (map.containsKey(name))
            throw new OpenDataException("Duplicate item name " + name);
        map.put(itemNames[i], itemValues[i]);
    }

    return map;
}
 
Example 3
/**
 * <p>Construct a descriptor where the names and values of the fields
 * are the keys and values of the given Map.</p>
 *
 * @throws IllegalArgumentException if the parameter is null, or
 * if a field name is null or empty, or if the same field name appears
 * more than once (which can happen because field names are not case
 * sensitive).
 */
public ImmutableDescriptor(Map<String, ?> fields) {
    if (fields == null)
        throw new IllegalArgumentException("Null Map");
    SortedMap<String, Object> map =
            new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
    for (Map.Entry<String, ?> entry : fields.entrySet()) {
        String name = entry.getKey();
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Empty or null field name");
        if (map.containsKey(name))
            throw new IllegalArgumentException("Duplicate name: " + name);
        map.put(name, entry.getValue());
    }
    int size = map.size();
    this.names = map.keySet().toArray(new String[size]);
    this.values = map.values().toArray(new Object[size]);
}
 
Example 4
private static SortedMap<String, Object> makeMap(
        String[] itemNames, Object[] itemValues)
        throws OpenDataException {

    if (itemNames == null || itemValues == null)
        throw new IllegalArgumentException("Null itemNames or itemValues");
    if (itemNames.length == 0 || itemValues.length == 0)
        throw new IllegalArgumentException("Empty itemNames or itemValues");
    if (itemNames.length != itemValues.length) {
        throw new IllegalArgumentException(
                "Different lengths: itemNames[" + itemNames.length +
                "], itemValues[" + itemValues.length + "]");
    }

    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (int i = 0; i < itemNames.length; i++) {
        String name = itemNames[i];
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Null or empty item name");
        if (map.containsKey(name))
            throw new OpenDataException("Duplicate item name " + name);
        map.put(itemNames[i], itemValues[i]);
    }

    return map;
}
 
Example 5
/**
 * <p>Construct a descriptor where the names and values of the fields
 * are the keys and values of the given Map.</p>
 *
 * @throws IllegalArgumentException if the parameter is null, or
 * if a field name is null or empty, or if the same field name appears
 * more than once (which can happen because field names are not case
 * sensitive).
 */
public ImmutableDescriptor(Map<String, ?> fields) {
    if (fields == null)
        throw new IllegalArgumentException("Null Map");
    SortedMap<String, Object> map =
            new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
    for (Map.Entry<String, ?> entry : fields.entrySet()) {
        String name = entry.getKey();
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Empty or null field name");
        if (map.containsKey(name))
            throw new IllegalArgumentException("Duplicate name: " + name);
        map.put(name, entry.getValue());
    }
    int size = map.size();
    this.names = map.keySet().toArray(new String[size]);
    this.values = map.values().toArray(new Object[size]);
}
 
Example 6
private static SortedMap<String, Object> makeMap(
        String[] itemNames, Object[] itemValues)
        throws OpenDataException {

    if (itemNames == null || itemValues == null)
        throw new IllegalArgumentException("Null itemNames or itemValues");
    if (itemNames.length == 0 || itemValues.length == 0)
        throw new IllegalArgumentException("Empty itemNames or itemValues");
    if (itemNames.length != itemValues.length) {
        throw new IllegalArgumentException(
                "Different lengths: itemNames[" + itemNames.length +
                "], itemValues[" + itemValues.length + "]");
    }

    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (int i = 0; i < itemNames.length; i++) {
        String name = itemNames[i];
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Null or empty item name");
        if (map.containsKey(name))
            throw new OpenDataException("Duplicate item name " + name);
        map.put(itemNames[i], itemValues[i]);
    }

    return map;
}
 
Example 7
Source Project: ironjacamar   File: IronJacamar.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Filter and sort
 * @param fms The FrameworkMethods
 * @param isStatic Filter static
 * @return The filtered and sorted FrameworkMethods
 * @exception Exception If an order definition is incorrect
 */
private Collection<FrameworkMethod> filterAndSort(List<FrameworkMethod> fms, boolean isStatic) throws Exception
{
   SortedMap<Integer, FrameworkMethod> m = new TreeMap<>();

   for (FrameworkMethod fm : fms)
   {
      SecurityActions.setAccessible(fm.getMethod());

      if (Modifier.isStatic(fm.getMethod().getModifiers()) == isStatic)
      {
         Deployment deployment = (Deployment)fm.getAnnotation(Deployment.class);
         int order = deployment.order();

         if (order <= 0 || m.containsKey(Integer.valueOf(order)))
            throw new Exception("Incorrect order definition '" + order + "' on " +
                                fm.getDeclaringClass().getName() + "#" + fm.getName());
         
         m.put(Integer.valueOf(order), fm);
      }
   }

   return m.values();
}
 
Example 8
Source Project: aion   File: TxPoolV1.java    License: MIT License 6 votes vote down vote up
/**
 * @implNote check the transaction already in the pool given sender and the transaction nonce. The repay transaction
 * will return false due to the same sender and nonce. But it will been updated in the following pendingState
 * process.
 * @param sender the transaction sender
 * @param txNonce the transaction nonce
 * @return boolean value to confirm the transaction is in pool.
 */
public boolean isContained(AionAddress sender, BigInteger txNonce) {
    Objects.requireNonNull(sender);
    Objects.requireNonNull(txNonce);

    lock.lock();
    try {
        SortedMap<BigInteger, ByteArrayWrapper> accountInfo = accountView.get(sender);
        if (accountInfo == null) {
            return false;
        } else {
            return accountInfo.containsKey(txNonce);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 9
/**
 * <p>Construct a descriptor where the names and values of the fields
 * are the keys and values of the given Map.</p>
 *
 * @throws IllegalArgumentException if the parameter is null, or
 * if a field name is null or empty, or if the same field name appears
 * more than once (which can happen because field names are not case
 * sensitive).
 */
public ImmutableDescriptor(Map<String, ?> fields) {
    if (fields == null)
        throw new IllegalArgumentException("Null Map");
    SortedMap<String, Object> map =
            new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
    for (Map.Entry<String, ?> entry : fields.entrySet()) {
        String name = entry.getKey();
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Empty or null field name");
        if (map.containsKey(name))
            throw new IllegalArgumentException("Duplicate name: " + name);
        map.put(name, entry.getValue());
    }
    int size = map.size();
    this.names = map.keySet().toArray(new String[size]);
    this.values = map.values().toArray(new Object[size]);
}
 
Example 10
Source Project: buck   File: Unzip.java    License: Apache License 2.0 6 votes vote down vote up
private void extractDirectory(
    ExistingFileMode existingFileMode,
    SortedMap<Path, ZipArchiveEntry> pathMap,
    DirectoryCreator creator,
    Path target)
    throws IOException {
  ProjectFilesystem filesystem = creator.getFilesystem();
  if (filesystem.isDirectory(target, LinkOption.NOFOLLOW_LINKS)) {
    // We have a pre-existing directory: delete its contents if they aren't in the zip.
    if (existingFileMode == ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES) {
      for (Path path : filesystem.getDirectoryContents(target)) {
        if (!pathMap.containsKey(path)) {
          filesystem.deleteRecursivelyIfExists(path);
        }
      }
    }
  } else if (filesystem.exists(target, LinkOption.NOFOLLOW_LINKS)) {
    filesystem.deleteFileAtPath(target);
    creator.mkdirs(target);
  } else {
    creator.forcefullyCreateDirs(target);
  }
}
 
Example 11
private static SortedMap<String, Object> makeMap(
        String[] itemNames, Object[] itemValues)
        throws OpenDataException {

    if (itemNames == null || itemValues == null)
        throw new IllegalArgumentException("Null itemNames or itemValues");
    if (itemNames.length == 0 || itemValues.length == 0)
        throw new IllegalArgumentException("Empty itemNames or itemValues");
    if (itemNames.length != itemValues.length) {
        throw new IllegalArgumentException(
                "Different lengths: itemNames[" + itemNames.length +
                "], itemValues[" + itemValues.length + "]");
    }

    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (int i = 0; i < itemNames.length; i++) {
        String name = itemNames[i];
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Null or empty item name");
        if (map.containsKey(name))
            throw new OpenDataException("Duplicate item name " + name);
        map.put(itemNames[i], itemValues[i]);
    }

    return map;
}
 
Example 12
private Delete makeDeleteToRemoveOldIndexEntry(
    final IndexSpecification indexSpec, final byte[] row,
    final SortedMap<byte[], byte[]> oldColumnValues) throws IOException {
  for (byte[] indexedCol : indexSpec.getIndexedColumns()) {
    if (!oldColumnValues.containsKey(indexedCol)) {
      LOG.debug("Index [" + indexSpec.getIndexId()
          + "] not trying to remove old entry for row ["
          + Bytes.toString(row) + "] because col ["
          + Bytes.toString(indexedCol) + "] is missing");
      return null;
    }
  }

  byte[] oldIndexRow = indexSpec.getKeyGenerator().createIndexKey(row,
      oldColumnValues);
  LOG.debug("Index [" + indexSpec.getIndexId() + "] removing old entry ["
      + Bytes.toString(oldIndexRow) + "]");
  return new Delete(oldIndexRow);
}
 
Example 13
private static SortedMap<String, Object> makeMap(
        String[] itemNames, Object[] itemValues)
        throws OpenDataException {

    if (itemNames == null || itemValues == null)
        throw new IllegalArgumentException("Null itemNames or itemValues");
    if (itemNames.length == 0 || itemValues.length == 0)
        throw new IllegalArgumentException("Empty itemNames or itemValues");
    if (itemNames.length != itemValues.length) {
        throw new IllegalArgumentException(
                "Different lengths: itemNames[" + itemNames.length +
                "], itemValues[" + itemValues.length + "]");
    }

    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (int i = 0; i < itemNames.length; i++) {
        String name = itemNames[i];
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("Null or empty item name");
        if (map.containsKey(name))
            throw new OpenDataException("Duplicate item name " + name);
        map.put(itemNames[i], itemValues[i]);
    }

    return map;
}
 
Example 14
Source Project: batfish   File: Batfish.java    License: Apache License 2.0 5 votes vote down vote up
private SortedMap<String, BgpAdvertisementsByVrf> parseEnvironmentBgpTables(
    NetworkSnapshot snapshot,
    SortedMap<String, String> inputData,
    ParseEnvironmentBgpTablesAnswerElement answerElement) {
  _logger.info("\n*** PARSING ENVIRONMENT BGP TABLES ***\n");
  _logger.resetTimer();
  SortedMap<String, BgpAdvertisementsByVrf> bgpTables = new TreeMap<>();
  List<ParseEnvironmentBgpTableJob> jobs = new ArrayList<>();
  SortedMap<String, Configuration> configurations = loadConfigurations(snapshot);
  for (Entry<String, String> bgpObject : inputData.entrySet()) {
    String currentKey = bgpObject.getKey();
    String objectText = bgpObject.getValue();
    String hostname = Paths.get(currentKey).getFileName().toString(); //
    String optionalSuffix = ".bgp";
    if (hostname.endsWith(optionalSuffix)) {
      hostname = hostname.substring(0, hostname.length() - optionalSuffix.length());
    }
    if (!configurations.containsKey(hostname)) {
      continue;
    }
    Warnings warnings = buildWarnings(_settings);
    ParseEnvironmentBgpTableJob job =
        new ParseEnvironmentBgpTableJob(
            _settings, snapshot, objectText, hostname, currentKey, warnings, _bgpTablePlugins);
    jobs.add(job);
  }
  BatfishJobExecutor.runJobsInExecutor(
      _settings,
      _logger,
      jobs,
      bgpTables,
      answerElement,
      _settings.getHaltOnParseError(),
      "Parse environment BGP tables");
  _logger.printElapsedTime();
  return bgpTables;
}
 
Example 15
@Override
protected boolean matchesSafely(
    ConvertConfigurationAnswerElement item, Description mismatchDescription) {
  SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> byFile =
      item.getDefinedStructures();
  if (!byFile.containsKey(_filename)) {
    mismatchDescription.appendText(
        String.format("File '%s' has no defined structures", _filename));
    return false;
  }
  SortedMap<String, SortedMap<String, DefinedStructureInfo>> byType = byFile.get(_filename);
  if (!byType.containsKey(_type)) {
    mismatchDescription.appendText(
        String.format("File '%s' has no defined structure of type '%s'", _filename, _type));
    return false;
  }
  SortedMap<String, DefinedStructureInfo> byStructureName = byType.get(_type);
  if (!byStructureName.containsKey(_structureName)) {
    mismatchDescription.appendText(
        String.format(
            "File '%s' has no defined structure of type '%s' named '%s'",
            _filename, _type, _structureName));
    return false;
  }
  if (!_subMatcher.matches(byStructureName.get(_structureName).getDefinitionLines())) {
    mismatchDescription.appendText(
        String.format(
            "File '%s' has no defined structure of type '%s' named '%s' matching definition lines '%s'",
            _filename, _type, _structureName, _subMatcher));
    return false;
  }
  return true;
}
 
Example 16
Source Project: cfr   File: CodeAnalyser.java    License: MIT License 5 votes vote down vote up
private void generateUnverifiableInstr(int offset, List<Op01WithProcessedDataAndByteJumps> op1list, List<Op02WithProcessedDataAndRefs> op2list, Map<Integer, Integer> lutByIdx, SortedMap<Integer, Integer> lutByOffset) {
    ByteData rawData = originalCodeAttribute.getRawData();
    int codeLength = originalCodeAttribute.getCodeLength();
    do {
        Op01WithProcessedDataAndByteJumps op01 = getSingleInstr(rawData, offset);
        // we can't cope if this instruction has multiple successors.
        int[] targets = op01.getRawTargetOffsets();
        boolean noTargets = false;
        if (targets != null) {
            if (targets.length == 0) {
                noTargets = true;
            } else {
                throw new ConfusedCFRException("Can't currently recover from branching unverifiable instructions.");
            }
        }
        int targetIdx = op1list.size();
        op1list.add(op01);
        lutByIdx.put(targetIdx, offset);
        lutByOffset.put(offset, targetIdx);
        Op02WithProcessedDataAndRefs op02 = op01.createOp2(cp, targetIdx);
        op2list.add(op02);
        if (noTargets) return;
        int nextOffset = offset + op01.getInstructionLength();
        if (lutByOffset.containsKey(nextOffset)) {
            // fine.  We now have to create a jump back to here.
            targetIdx = op1list.size();
            int fakeOffset = -op1list.size();
            lutByIdx.put(targetIdx, fakeOffset);
            lutByOffset.put(fakeOffset, targetIdx);
            int[] rawTargets = new int[1];
            rawTargets[0] = nextOffset - fakeOffset;
            Op01WithProcessedDataAndByteJumps fakeGoto = new Op01WithProcessedDataAndByteJumps(JVMInstr.GOTO, null, rawTargets, fakeOffset);
            op1list.add(fakeGoto);
            op2list.add(fakeGoto.createOp2(cp, targetIdx));
            return;
        }
        offset = nextOffset;
    } while (offset < codeLength);
}
 
Example 17
Source Project: lumongo   File: LumongoSegment.java    License: Apache License 2.0 5 votes vote down vote up
private void handleTerm(SortedMap<String, Lumongo.Term.Builder> termsMap, TermsEnum termsEnum, BytesRef text, Pattern termFilter, Pattern termMatch)
		throws IOException {

	String textStr = text.utf8ToString();
	if (termFilter != null || termMatch != null) {

		if (termFilter != null) {
			if (termFilter.matcher(textStr).matches()) {
				return;
			}
		}

		if (termMatch != null) {
			if (!termMatch.matcher(textStr).matches()) {
				return;
			}
		}
	}

	if (!termsMap.containsKey(textStr)) {
		termsMap.put(textStr, Lumongo.Term.newBuilder().setValue(textStr).setDocFreq(0).setTermFreq(0));
	}
	Lumongo.Term.Builder builder = termsMap.get(textStr);
	builder.setDocFreq(builder.getDocFreq() + termsEnum.docFreq());
	builder.setTermFreq(builder.getTermFreq() + termsEnum.totalTermFreq());
	BoostAttribute boostAttribute = termsEnum.attributes().getAttribute(BoostAttribute.class);
	if (boostAttribute != null) {
		builder.setScore(boostAttribute.getBoost());
	}

}
 
Example 18
private void parseEncoders () {
	encodeChain = null;
	
	String[]			coders;
	SortedMap <String, Charset>	charsets = Charset.availableCharsets ();
	
	if ((encoders != null) && ((coders = encoders.toLowerCase ().split (", *")) != null) && (coders.length > 0)) {
		encodeChain = new ArrayList<>(coders.length);
		
		for (String coder : coders) {
			Coder	c;

			switch (coder) {
			case "hex":
			case "hexlower":
				c  = new CoderHexLower ();
				break;
			case "hexupper":
				c = new CoderHexUpper ();
				break;
			case "url":
				c = new CodeURL ();
				break;
			default:
				try {
					if (digestMap.containsKey (coder)) {
						coder = digestMap.get (coder);
					}
					c = new CoderDigest (coder);
				} catch (Exception e) {
					if (charsets.containsKey (coder) && charsets.get (coder).canEncode ()) {
						c = new Coder ();
						c.setCharset (charsets.get (coder));
					} else {
						error = coder + ": unknown encoder (" + e.toString () + ")";
						c = null;
					}
				}
				break;
			}
			if (c == null) {
				break;
			}
			encodeChain.add (c);
		}
	}
}
 
Example 19
@Override
public void applyTo(
    SortedMap<String, BgpAdvertisementsByVrf> bgpTables,
    BatfishLogger logger,
    ParseEnvironmentBgpTablesAnswerElement answerElement) {
  appendHistory(logger);
  String filename = Paths.get(_key).getFileName().toString();
  if (_bgpTable != null) {
    String hostname = _name;
    if (bgpTables.containsKey(hostname)) {
      throw new BatfishException("Duplicate hostname: " + hostname);
    } else {
      bgpTables.put(hostname, _bgpTable);
      if (!_warnings.isEmpty()) {
        answerElement.getWarnings().put(filename, _warnings);
      }
      if (!_parseTree.isEmpty()) {
        answerElement.getParseTrees().put(filename, _parseTree);
      }
      if (_bgpTable.getUnrecognized()) {
        answerElement.getParseStatus().put(filename, ParseStatus.PARTIALLY_UNRECOGNIZED);
      } else {
        answerElement.getParseStatus().put(filename, ParseStatus.PASSED);
      }
    }
  } else {
    answerElement.getParseStatus().put(filename, _status);
    if (_status == ParseStatus.FAILED) {
      answerElement
          .getErrors()
          .put(filename, ((BatfishException) _failureCause).getBatfishStackTrace());
      answerElement
          .getErrorDetails()
          .put(
              filename,
              new ErrorDetails(
                  Throwables.getStackTraceAsString(
                      firstNonNull(_failureCause.getCause(), _failureCause))));
    }
  }
}
 
Example 20
@Override
protected boolean matchesSafely(
    ConvertConfigurationAnswerElement item, Description mismatchDescription) {
  SortedMap<String, SortedMap<String, SortedMap<String, SortedMap<String, SortedSet<Integer>>>>>
      byFile = item.getUndefinedReferences();
  if (!byFile.containsKey(_filename)) {
    mismatchDescription.appendText(
        String.format("File '%s' has no undefined references", _filename));
    return false;
  }
  SortedMap<String, SortedMap<String, SortedMap<String, SortedSet<Integer>>>> byType =
      byFile.get(_filename);
  if (!byType.containsKey(_type)) {
    mismatchDescription.appendText(
        String.format("File '%s' has no undefined reference of type '%s'", _filename, _type));
    return false;
  }
  SortedMap<String, SortedMap<String, SortedSet<Integer>>> byStructureName = byType.get(_type);
  if (!byStructureName.containsKey(_structureName)) {
    mismatchDescription.appendText(
        String.format(
            "File '%s' has no undefined reference of type '%s' named '%s'",
            _filename, _type, _structureName));
    return false;
  }
  SortedMap<String, SortedSet<Integer>> byUsage = byStructureName.get(_structureName);
  if (!byUsage.containsKey(_usage)) {
    mismatchDescription.appendText(
        String.format(
            "File '%s' has no undefined references to structures of type '%s' named '%s' of "
                + "usage '%s'",
            _filename, _type, _structureName, _usage));
    return false;
  }
  if (!_subMatcher.matches(byUsage.get(_usage))) {
    mismatchDescription.appendText(
        String.format(
            "File '%s' has no undefined reference of type '%s' named '%s' of usage '%s' matching reference lines '%s'",
            _filename, _type, _structureName, _usage, _subMatcher));
    return false;
  }
  return true;
}