Java Code Examples for java.util.Map.Entry.setValue()

The following are Jave code examples for showing how to use setValue() of the java.util.Map.Entry class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DolphinNG   File: IOUtil.java   View Source Code Vote up 6 votes
/**
 * Loads the properties file into properties, with added functionality of
 * loading the files itself for values of the properties mentioned in the file
 * <p>
 * i.e. if file=/home/hello.properties which contains
 * key1=val1,,val2,,file::test.properties,val3
 * key2=a,,b,,c,,file::test.properties and test.properties contains - x y z..
 * <p>
 * then effecive properties returned will be - key1=val1,,val2,,x,,y,,z,,val3
 * key2=a,,b,,c,,x,,y,,z
 *
 * @param file
 * @param fileValueIndicator
 * @param valueSeparator
 * @return
 */
public static Properties loadProperties(String file, String fileValueIndicator, String valueSeparator)
{
    Properties props = loadFileIntoProperties(file);
    Set<Entry<Object, Object>> entrySet = props.entrySet();
    for (Entry<Object, Object> entry : entrySet)
    {
        String value = (String) entry.getValue();
        if (value.contains(fileValueIndicator))
        {
            // the value might have multiple file urls, load each of them append,
            // and remove these file urls on the go
            String[] allValues = value.split(valueSeparator);
            for (String each : allValues)
            {
                if (each.contains(fileValueIndicator))
                {
                    String fileToBeLoaded = each.split(fileValueIndicator)[1];
                    String newValue = getValueListFormatted(fileToBeLoaded, valueSeparator);
                    entry.setValue(value.replace(each, newValue));
                }
            }
        }
    }
    return props;
}
 
Example 2
Project: sstore-soft   File: MapConstraints.java   View Source Code Vote up 6 votes
/**
 * Returns a constrained view of the specified entry, using the specified
 * constraint. The {@link Entry#setValue} operation will be verified with the
 * constraint.
 *
 * @param entry the entry to constrain
 * @param constraint the constraint for the entry
 * @return a constrained view of the specified entry
 */
private static <K, V> Entry<K, V> constrainedEntry(
    final Entry<K, V> entry,
    final MapConstraint<? super K, ? super V> constraint) {
  checkNotNull(entry);
  checkNotNull(constraint);
  return new ForwardingMapEntry<K, V>() {
    @Override protected Entry<K, V> delegate() {
      return entry;
    }
    @Override public V setValue(V value) {
      constraint.checkKeyValue(getKey(), value);
      return entry.setValue(value);
    }
  };
}
 
Example 3
Project: googles-monorepo-demo   File: MapInterfaceTest.java   View Source Code Vote up 6 votes
public void testEntrySetSetValueSameValue() {
  // TODO: Investigate the extent to which, in practice, maps that support
  // put() also support Entry.setValue().
  if (!supportsPut) {
    return;
  }

  final Map<K, V> map;
  try {
    map = makePopulatedMap();
  } catch (UnsupportedOperationException e) {
    return;
  }

  Set<Entry<K, V>> entrySet = map.entrySet();
  Entry<K, V> entry = entrySet.iterator().next();
  final V oldValue = entry.getValue();
  final V returnedValue = entry.setValue(oldValue);
  assertEquals(oldValue, returnedValue);
  assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue)));
  assertEquals(oldValue, map.get(entry.getKey()));
  assertInvariants(map);
}
 
Example 4
Project: guava-mock   File: MapInterfaceTest.java   View Source Code Vote up 6 votes
public void testEntrySetSetValueSameValue() {
  // TODO: Investigate the extent to which, in practice, maps that support
  // put() also support Entry.setValue().
  if (!supportsPut) {
    return;
  }

  final Map<K, V> map;
  try {
    map = makePopulatedMap();
  } catch (UnsupportedOperationException e) {
    return;
  }

  Set<Entry<K, V>> entrySet = map.entrySet();
  Entry<K, V> entry = entrySet.iterator().next();
  final V oldValue = entry.getValue();
  final V returnedValue = entry.setValue(oldValue);
  assertEquals(oldValue, returnedValue);
  assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue)));
  assertEquals(oldValue, map.get(entry.getKey()));
  assertInvariants(map);
}
 
Example 5
Project: andbg   File: DexWriter.java   View Source Code Vote up 6 votes
private void writeAnnotations(@Nonnull DexDataWriter writer) throws IOException {
    InternalEncodedValueWriter encodedValueWriter = new InternalEncodedValueWriter(writer);

    annotationSectionOffset = writer.getPosition();
    for (Entry<? extends AnnotationKey, Integer> entry: annotationSection.getItems()) {
        entry.setValue(writer.getPosition());

        AnnotationKey key = entry.getKey();

        writer.writeUbyte(annotationSection.getVisibility(key));
        writer.writeUleb128(typeSection.getItemIndex(annotationSection.getType(key)));

        Collection<? extends AnnotationElement> elements = Ordering.from(BaseAnnotationElement.BY_NAME)
                .immutableSortedCopy(annotationSection.getElements(key));

        writer.writeUleb128(elements.size());

        for (AnnotationElement element: elements) {
            writer.writeUleb128(stringSection.getItemIndex(annotationSection.getElementName(element)));
            writeEncodedValue(encodedValueWriter, annotationSection.getElementValue(element));
        }
    }
}
 
Example 6
Project: s-store   File: MapConstraints.java   View Source Code Vote up 6 votes
/**
 * Returns a constrained view of the specified entry, using the specified
 * constraint. The {@link Entry#setValue} operation will be verified with the
 * constraint.
 *
 * @param entry the entry to constrain
 * @param constraint the constraint for the entry
 * @return a constrained view of the specified entry
 */
private static <K, V> Entry<K, V> constrainedEntry(
    final Entry<K, V> entry,
    final MapConstraint<? super K, ? super V> constraint) {
  checkNotNull(entry);
  checkNotNull(constraint);
  return new ForwardingMapEntry<K, V>() {
    @Override protected Entry<K, V> delegate() {
      return entry;
    }
    @Override public V setValue(V value) {
      constraint.checkKeyValue(getKey(), value);
      return entry.setValue(value);
    }
  };
}
 
Example 7
Project: train-simulator   File: Station.java   View Source Code Vote up 5 votes
public void tick(double time) {
  if (trainsLeaving.size() > 1) {
    throw new IllegalStateException("This shouldn't be possible!");
  }
  for (Entry<Train, Double> trainElement : trains.entrySet()) {
    Train t = trainElement.getKey();
    SignalController signalController = nextBlockSignalController
        .get(t.getEcu().getJourneyPlan().getJourneyPath().getTrackAfterStation(this));
    if (signalController == null) {
      if (t.getEcu().getJourneyPlan().getJourneyPath().getLast() != this) {
        logger.error("SignallController is null (shouldn't be)");
      }
      continue;
    }
    double delay = trainElement.getValue();
    if (trainsLeaving.contains(t)) {
      if (t.getEngine().getObjective() != TrainObjective.PROCEED) {
        t.signalChange(SignalType.GREEN);
      }
      continue; // ignore them, they're leaving
    }
    if (trainsLeaving.size() > 0) {
      // if there are other trains leaving, wait for them to leave
      continue;
    }
    if (signalController.getStatus() == GREEN) {
      delay -= time;
      if (delay <= 0) {
        t.signalChange(SignalType.GREEN);
        trainsLeaving.add(t);
      }
    } else {
      break;
    }

    trainElement.setValue(delay);
    break; // Only do this for one train
  }
}
 
Example 8
Project: GitHub   File: Support.java   View Source Code Vote up 5 votes
public static Object unwrapBsonable(Object value) {
  if (value instanceof Document) {
    for (Entry<String, Object> entry : ((Document) value).entrySet()) {
      entry.setValue(unwrapBsonable(entry.getValue()));
    }
    return value;
  }

  if (value instanceof Iterable<?>) {
    return ImmutableList.copyOf(unwrapBsonableIterable((Iterable<?>) value));
  }

  if (value instanceof Constraints.ConstraintHost) {
    return convertToBson((Constraints.ConstraintHost) value);
  }

  if (value == null
      || value instanceof Number
      || value instanceof Boolean
      || value instanceof String) {
    return value;
  }

  if (value instanceof Adapted<?>) {
    return ((Adapted) value).toBson();
  }

  return String.valueOf(value);
}
 
Example 9
Project: andbg   File: DexWriter.java   View Source Code Vote up 5 votes
private void writeTypes(@Nonnull DexDataWriter writer) throws IOException {
    typeSectionOffset = writer.getPosition();
    int index = 0;

    List<Entry<? extends TypeKey, Integer>> typeEntries = Lists.newArrayList(typeSection.getItems());
    Collections.sort(typeEntries, toStringKeyComparator);

    for (Entry<? extends TypeKey, Integer> entry : typeEntries) {
        entry.setValue(index++);
        writer.writeInt(stringSection.getItemIndex(typeSection.getString(entry.getKey())));
    }
}
 
Example 10
Project: opencron   File: HibernateDao.java   View Source Code Vote up 5 votes
/**
 * 将Map中的primitive类型数组转换为对象数组,以支持In操作
 *
 * @param map
 * @return
 */
public static Map namedParameters(Map map) {
    for (Object o : map.entrySet()) {
        Entry en = (Entry) o;
        en.setValue(handle(en.getValue()));
    }
    return map;
}
 
Example 11
Project: andbg   File: DexWriter.java   View Source Code Vote up 5 votes
private void writeProtos(@Nonnull DexDataWriter writer) throws IOException {
    protoSectionOffset = writer.getPosition();
    int index = 0;

    List<Entry<? extends ProtoKey, Integer>> protoEntries = Lists.newArrayList(protoSection.getItems());
    Collections.sort(protoEntries, DexWriter.<ProtoKey>comparableKeyComparator());

    for (Entry<? extends ProtoKey, Integer> entry: protoEntries) {
        entry.setValue(index++);
        ProtoKey key = entry.getKey();
        writer.writeInt(stringSection.getItemIndex(protoSection.getShorty(key)));
        writer.writeInt(typeSection.getItemIndex(protoSection.getReturnType(key)));
        writer.writeInt(typeListSection.getNullableItemOffset(protoSection.getParameters(key)));
    }
}
 
Example 12
Project: guava-mock   File: MapsTest.java   View Source Code Vote up 5 votes
public void testFilteredValuesIllegalSetValue() {
  Map<String, Integer> unfiltered = createUnfiltered();
  Map<String, Integer> filtered = Maps.filterValues(unfiltered, EVEN);
  filtered.put("a", 2);
  filtered.put("b", 4);
  assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered);

  Entry<String, Integer> entry = filtered.entrySet().iterator().next();
  try {
    entry.setValue(5);
    fail();
  } catch (IllegalArgumentException expected) {}

  assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered);
}
 
Example 13
Project: guava-mock   File: HashBiMapTest.java   View Source Code Vote up 5 votes
public void testBashIt() throws Exception {
  BiMap<Integer, Integer> bimap = HashBiMap.create(N);
  BiMap<Integer, Integer> inverse = bimap.inverse();

  for (int i = 0; i < N; i++) {
    assertNull(bimap.put(2 * i, 2 * i + 1));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i + 1, (int) bimap.get(2 * i));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i, (int) inverse.get(2 * i + 1));
  }
  for (int i = 0; i < N; i++) {
    int oldValue = bimap.get(2 * i);
    assertEquals(2 * i + 1, (int) bimap.put(2 * i, oldValue - 2));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i - 1, (int) bimap.get(2 * i));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i, (int) inverse.get(2 * i - 1));
  }
  Set<Entry<Integer, Integer>> entries = bimap.entrySet();
  for (Entry<Integer, Integer> entry : entries) {
    entry.setValue(entry.getValue() + 2 * N);
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * N + 2 * i - 1, (int) bimap.get(2 * i));
  }
}
 
Example 14
Project: intellij-deps-ini4j   File: BasicMultiMapTest.java   View Source Code Vote up 5 votes
@Test public void testEntrySet()
{
    _map.putAll(KEY1, Arrays.asList(VALUES));
    _map.put(KEY2, VALUE2);
    _map.put(KEY3, VALUE3);
    Set<Entry<String, String>> set = _map.entrySet();

    assertNotNull(set);
    assertEquals(3, set.size());
    for (Entry<String, String> e : set)
    {
        if (e.getKey().equals(KEY1))
        {
            assertEquals(VALUES[2], e.getValue());
            e.setValue(VALUES[1]);
        }
        else if (e.getKey().equals(KEY2))
        {
            assertEquals(VALUE2, e.getValue());
            e.setValue(VALUE3);
        }
        else if (e.getKey().equals(KEY3))
        {
            assertEquals(VALUE3, e.getValue());
            e.setValue(VALUE2);
        }
    }

    assertEquals(VALUES[1], _map.get(KEY1));
    assertEquals(VALUES.length, _map.length(KEY1));
    assertEquals(VALUE3, _map.get(KEY2));
    assertEquals(VALUE2, _map.get(KEY3));
}
 
Example 15
Project: guava-mock   File: MutableTypeToInstanceMapTest.java   View Source Code Vote up 5 votes
public void testEntrySetToArrayMutationThrows() {
  map.putInstance(String.class, "test");
  @SuppressWarnings("unchecked") // Should get a CCE later if cast is wrong
  Entry<Object, Object> entry = (Entry<Object, Object>) map.entrySet().toArray()[0];
  assertEquals(TypeToken.of(String.class), entry.getKey());
  assertEquals("test", entry.getValue());
  try {
    entry.setValue(1);
    fail();
  } catch (UnsupportedOperationException expected) {}
}
 
Example 16
Project: andbg   File: DexWriter.java   View Source Code Vote up 5 votes
private void writeTypeLists(@Nonnull DexDataWriter writer) throws IOException {
    writer.align();
    typeListSectionOffset = writer.getPosition();
    for (Entry<? extends TypeListKey, Integer> entry: typeListSection.getItems()) {
        writer.align();
        entry.setValue(writer.getPosition());

        Collection<? extends TypeKey> types = typeListSection.getTypes(entry.getKey());
        writer.writeInt(types.size());
        for (TypeKey typeKey: types) {
            writer.writeUshort(typeSection.getItemIndex(typeKey));
        }
    }
}
 
Example 17
Project: andbg   File: DexWriter.java   View Source Code Vote up 5 votes
private void writeMethods(@Nonnull DexDataWriter writer) throws IOException {
    methodSectionOffset = writer.getPosition();
    int index = 0;

    List<Entry<? extends MethodRefKey, Integer>> methodEntries = Lists.newArrayList(methodSection.getItems());
    Collections.sort(methodEntries, DexWriter.<MethodRefKey>comparableKeyComparator());
    
    for (Entry<? extends MethodRefKey, Integer> entry: methodEntries) {
        entry.setValue(index++);
        MethodRefKey key = entry.getKey();
        writer.writeUshort(typeSection.getItemIndex(methodSection.getDefiningClass(key)));
        writer.writeUshort(protoSection.getItemIndex(methodSection.getPrototype(key)));
        writer.writeInt(stringSection.getItemIndex(methodSection.getName(key)));
    }
}
 
Example 18
Project: googles-monorepo-demo   File: HashBiMapTest.java   View Source Code Vote up 5 votes
public void testBashIt() throws Exception {
  BiMap<Integer, Integer> bimap = HashBiMap.create(N);
  BiMap<Integer, Integer> inverse = bimap.inverse();

  for (int i = 0; i < N; i++) {
    assertNull(bimap.put(2 * i, 2 * i + 1));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i + 1, (int) bimap.get(2 * i));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i, (int) inverse.get(2 * i + 1));
  }
  for (int i = 0; i < N; i++) {
    int oldValue = bimap.get(2 * i);
    assertEquals(2 * i + 1, (int) bimap.put(2 * i, oldValue - 2));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i - 1, (int) bimap.get(2 * i));
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * i, (int) inverse.get(2 * i - 1));
  }
  Set<Entry<Integer, Integer>> entries = bimap.entrySet();
  for (Entry<Integer, Integer> entry : entries) {
    entry.setValue(entry.getValue() + 2 * N);
  }
  for (int i = 0; i < N; i++) {
    assertEquals(2 * N + 2 * i - 1, (int) bimap.get(2 * i));
  }
}
 
Example 19
Project: JMELink-SP   File: SubstanceProject.java   View Source Code Vote up 4 votes
public Collection<Substance> exportSubstances() throws IOException {
	Map<Object,Object> shader_settings=_LINK.getLink().getShaderSettings();

	Map<Object,Object> texture_sets=(Map<Object,Object>)shader_settings.get("texturesets");
	if(texture_sets!=null){
		Map<String,Map> substances=new HashMap<String,Map>();

		for(java.util.Map.Entry<Object,Object> texture_set:texture_sets.entrySet()){
			String tx_set_name=(String)texture_set.getKey();
			Map<Object,Object> shader_settingx=(Map)((Map)shader_settings.get("shaders")).get((String)((Map)texture_set.getValue()).get("shader"));
			HashMap shader_setting=new HashMap();
			for(java.util.Map.Entry<Object,Object> xe:shader_settingx.entrySet()){
				shader_setting.put(xe.getKey(),xe.getValue());
			}
			substances.put(tx_set_name,(Map)(shader_setting));

		}

		Collection<Substance> out=new ArrayList<Substance>();
		for(java.util.Map.Entry<String,Map> substance:substances.entrySet()){

			Substance sx=new Substance();
			sx.putAll(substance.getValue());
			sx.put("name",substance.getKey());
			sx.setSubstancesList(_SLIST);
			SubstanceDef sdef=_SLIST.getSubstanceDef(sx);

			if(sdef!=null){
				Exporter ex=sdef.getExporter(sx,_LINK);
				byte preset[]=ex.getPreset();
				File temppreset=File.createTempFile("substancejmelink",".spexp");
				Files.write(temppreset.toPath(),preset);

				Map<Object,Object> map=_LINK.getLink().exportTextures(new String[]{substance.getKey()},
						temppreset.getAbsolutePath(),
						
					_SLIST.getFileSystemPath(),null);

				Map<Object,Object> txs=(Map<Object,Object>)map.get(substance.getKey());

				for(Entry<Object,Object> tx:txs.entrySet()){
					tx.setValue(ex.transformTexture(tx.getKey().toString(),tx.getValue().toString()));
				}
				
				sx.put("textures",txs);

				out.add(sx);
			}else{
				LOGGER.log(Level.FINE,"No substance can map "+sx.get("name"));
			}
		}
		return out;
	}
	return null;

}
 
Example 20
Project: OpenJSharp   File: Encodings.java   View Source Code Vote up 4 votes
/**
 * Loads a list of all the supported encodings.
 *
 * System property "encodings" formatted using URL syntax may define an
 * external encodings list. Thanks to Sergey Ushakov for the code
 * contribution!
 */
private void loadEncodingInfo() {
    try {
        // load (java name)->(preferred mime name) mapping.
        final Properties props = loadProperties();

        // create instances of EncodingInfo from the loaded mapping
        Enumeration keys = props.keys();
        Map<String, EncodingInfo> canonicals = new HashMap<>();
        while (keys.hasMoreElements()) {
            final String javaName = (String) keys.nextElement();
            final String[] mimes = parseMimeTypes(props.getProperty(javaName));

            final String charsetName = findCharsetNameFor(javaName, mimes);
            if (charsetName != null) {
                final String kj = toUpperCaseFast(javaName);
                final String kc = toUpperCaseFast(charsetName);
                for (int i = 0; i < mimes.length; ++i) {
                    final String mimeName = mimes[i];
                    final String km = toUpperCaseFast(mimeName);
                    EncodingInfo info = new EncodingInfo(mimeName, charsetName);
                    _encodingTableKeyMime.put(km, info);
                    if (!canonicals.containsKey(kc)) {
                        // canonicals will map the charset name to
                        //   the info containing the prefered mime name
                        //   (the preferred mime name is the first mime
                        //   name in the list).
                        canonicals.put(kc, info);
                        _encodingTableKeyJava.put(kc, info);
                    }
                    _encodingTableKeyJava.put(kj, info);
                }
            } else {
                // None of the java or mime names on the line were
                // recognized => this charset is not supported?
            }
        }

        // Fix up the _encodingTableKeyJava so that the info mapped to
        // the java name contains the preferred mime name.
        // (a given java name can correspond to several mime name,
        //  but we want the _encodingTableKeyJava to point to the
        //  preferred mime name).
        for (Entry<String, EncodingInfo> e : _encodingTableKeyJava.entrySet()) {
            e.setValue(canonicals.get(toUpperCaseFast(e.getValue().javaName)));
        }

    } catch (java.net.MalformedURLException mue) {
        throw new com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException(mue);
    } catch (java.io.IOException ioe) {
        throw new com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException(ioe);
    }
}