Java Code Examples for java.util.Properties.equals()

The following are Jave code examples for showing how to use equals() of the java.util.Properties 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: incubator-netbeans   File: J2SEProjectConfigurations.java   View Source Code Vote up 6 votes
private static void generateConfig(FileObject prjDir, String cfgFilePath, EditableProperties propsToWrite) throws IOException {
    
    if (propsToWrite == null) {
        // do not create anything if props is null
        return;
    }
    FileObject jwsConfigFO = FileUtil.createData(prjDir, cfgFilePath);
    Properties props = new Properties();
    InputStream is = jwsConfigFO.getInputStream();
    props.load(is);
    is.close();
    if (props.equals(propsToWrite)) {
        // file already exists and props are the same
        return;
    }
    OutputStream os = jwsConfigFO.getOutputStream();
    propsToWrite.store(os);
    os.close();
    
}
 
Example 2
Project: jdk8u-jdk   File: ConcurrentLoadAndStoreXML.java   View Source Code Vote up 6 votes
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 3
Project: openjdk-jdk10   File: LoadAndStoreXML.java   View Source Code Vote up 6 votes
/**
 * Test loadFromXML with a document that does not have an encoding declaration
 */
static void testLoadWithoutEncoding() throws IOException {
    System.out.println("testLoadWithoutEncoding");

    Properties expected = new Properties();
    expected.put("foo", "bar");

    String s = "<?xml version=\"1.0\"?>" +
               "<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">" +
               "<properties>" +
               "<entry key=\"foo\">bar</entry>" +
               "</properties>";
    ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
    Properties props = new Properties();
    props.loadFromXML(in);

    if (!props.equals(expected)) {
        System.err.println("loaded: " + props + ", expected: " + expected);
        throw new RuntimeException("Test failed");
    }
}
 
Example 4
Project: openjdk-jdk10   File: ConcurrentLoadAndStoreXML.java   View Source Code Vote up 6 votes
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 5
Project: apollo-custom   File: SimpleConfig.java   View Source Code Vote up 6 votes
@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_configProperties)) {
    return;
  }
  Properties newConfigProperties = new Properties();
  newConfigProperties.putAll(newProperties);

  List<ConfigChange>
      changes =
      calcPropertyChanges(namespace, m_configProperties, newConfigProperties);
  Map<String, ConfigChange> changeMap = Maps.uniqueIndex(changes,
      new Function<ConfigChange, String>() {
        @Override
        public String apply(ConfigChange input) {
          return input.getPropertyName();
        }
      });

  m_configProperties = newConfigProperties;
  clearConfigCache();

  this.fireConfigChange(new ConfigChangeEvent(m_namespace, changeMap));

  Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
}
 
Example 6
Project: apollo-custom   File: DefaultConfig.java   View Source Code Vote up 6 votes
@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_configProperties.get())) {
    return;
  }
  Properties newConfigProperties = new Properties();
  newConfigProperties.putAll(newProperties);

  Map<String, ConfigChange> actualChanges = updateAndCalcConfigChanges(newConfigProperties);

  //check double checked result
  if (actualChanges.isEmpty()) {
    return;
  }

  this.fireConfigChange(new ConfigChangeEvent(m_namespace, actualChanges));

  Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
}
 
Example 7
Project: apollo-custom   File: AbstractConfigFile.java   View Source Code Vote up 6 votes
@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_configProperties.get())) {
    return;
  }
  Properties newConfigProperties = new Properties();
  newConfigProperties.putAll(newProperties);

  String oldValue = getContent();

  update(newProperties);

  String newValue = getContent();

  PropertyChangeType changeType = PropertyChangeType.MODIFIED;

  if (oldValue == null) {
    changeType = PropertyChangeType.ADDED;
  } else if (newValue == null) {
    changeType = PropertyChangeType.DELETED;
  }

  this.fireConfigChange(new ConfigFileChangeEvent(m_namespace, oldValue, newValue, changeType));

  Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
}
 
Example 8
Project: VASSAL-src   File: ServerAddressBook.java   View Source Code Vote up 5 votes
public void setCurrentServer(Properties p) {

    // Check for Basic Types, regardless of other properties
    int index = 0;
    final String type = p.getProperty(TYPE_KEY);
    final String dtype = p.getProperty(DYNAMIC_TYPE);
    final String ctype = p.getProperty(P2P_MODE_KEY);
    for (Enumeration<?> e = addressBook.elements(); e.hasMoreElements();) {
      final AddressBookEntry entry = (AddressBookEntry) e.nextElement();
      final Properties ep = entry.getProperties();

      if (ep.equals(p)) {
        setCurrentServer(index);
        return;
      }

      else if (DYNAMIC_TYPE.equals(type) && DYNAMIC_TYPE.equals(ep.getProperty(TYPE_KEY))
          && ep.getProperty(DYNAMIC_TYPE).equals(dtype)) {
        setCurrentServer(index);
        return;
      }
      else if (P2P_TYPE.equals(type) && P2P_TYPE.equals(ep.getProperty(TYPE_KEY))
          && ep.getProperty(P2P_MODE_KEY).equals(ctype)) {
        setCurrentServer(index);
      }

      index++;
    }

    // Some Server we don't know about, add a server entry
    final AddressBookEntry newEntry = buildEntry(p);
    if (newEntry != null) {
      addressBook.addElement(newEntry);
      setCurrentServer(addressBook.indexOf(newEntry));
    }
    saveAddressBook();

  }
 
Example 9
Project: apollo-custom   File: LocalFileConfigRepository.java   View Source Code Vote up 5 votes
@Override
public void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_fileProperties)) {
    return;
  }
  Properties newFileProperties = new Properties();
  newFileProperties.putAll(newProperties);
  updateFileProperties(newFileProperties);
  this.fireRepositoryChange(namespace, newProperties);
}
 
Example 10
Project: apollo-custom   File: LocalFileConfigRepository.java   View Source Code Vote up 5 votes
private synchronized void updateFileProperties(Properties newProperties) {
  if (newProperties.equals(m_fileProperties)) {
    return;
  }
  this.m_fileProperties = newProperties;
  persistLocalCacheFile(m_baseDir, m_namespace);
}
 
Example 11
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: MixAll.java   View Source Code Vote up 4 votes
public static boolean isPropertiesEqual(final Properties p1, final Properties p2) {
    return p1.equals(p2);
}
 
Example 12
Project: monarch   File: DistributedTestCase.java   View Source Code Vote up 4 votes
/**
 * Returns this VM's connection to the distributed system.  If
 * necessary, the connection will be lazily created using the given
 * <code>Properties</code>.  Note that this method uses hydra's
 * configuration to determine the location of log files, etc.
 * Note: "final" was removed so that WANTestBase can override this method.
 * This was part of the xd offheap merge.
 *
 * @see hydra.DistributedConnectionMgr#connect
 * @since 3.0
 */
public /*final*/ InternalDistributedSystem getSystem(Properties props) {
  // Setting the default disk store name is now done in setUp
  if (system == null) {
    system = InternalDistributedSystem.getAnyInstance();
  }
  if (system == null || !system.isConnected()) {
    // Figure out our distributed system properties
    Properties p = getAllDistributedSystemProperties(props);
    lastSystemCreatedInTest = getTestClass();
    if (logPerTest) {
      String testMethod = getTestName();
      String testName = lastSystemCreatedInTest.getName() + '-' + testMethod;
      String oldLogFile = p.getProperty(DistributionConfig.LOG_FILE_NAME);
      p.put(DistributionConfig.LOG_FILE_NAME,
          oldLogFile.replace("system.log", testName+".log"));
      String oldStatFile = p.getProperty(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME);
      p.put(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME,
          oldStatFile.replace("statArchive.gfs", testName+".gfs"));
    }
    system = (InternalDistributedSystem)DistributedSystem.connect(p);
    lastSystemProperties = p;
  } else {
    boolean needNewSystem = false;
    if(!getTestClass().equals(lastSystemCreatedInTest)) {
      Properties newProps = getAllDistributedSystemProperties(props);
      needNewSystem = !newProps.equals(lastSystemProperties);
      if(needNewSystem) {
        getLogWriter().info(
            "Test class has changed and the new DS properties are not an exact match. "
                + "Forcing DS disconnect. Old props = "
                + lastSystemProperties + "new props=" + newProps);
      }
    } else {
      Properties activeProps = system.getProperties();
      for (Iterator iter = props.entrySet().iterator();
           iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        if (!value.equals(activeProps.getProperty(key))) {
          needNewSystem = true;
          getLogWriter().info("Forcing DS disconnect. For property " + key
              + " old value = " + activeProps.getProperty(key)
              + " new value = " + value);
          break;
        }
      }
    }
    if(needNewSystem) {
      // the current system does not meet our needs to disconnect and
      // call recursively to get a new system.
      getLogWriter().info("Disconnecting from current DS in order to make a new one");
      disconnectFromDS();
      getSystem(props);
    }
  }
  return system;
}
 
Example 13
Project: monarch   File: JUnit4DistributedTestCase.java   View Source Code Vote up 4 votes
/**
 * Returns this VM's connection to the distributed system. If necessary, the connection will be
 * lazily created using the given {@code Properties}.
 *
 * <p>
 * Do not override this method. Override {@link #getDistributedSystemProperties()} instead.
 *
 * <p>
 * Note: "final" was removed so that WANTestBase can override this method. This was part of the xd
 * offheap merge.
 *
 * @since GemFire 3.0
 */
public final InternalDistributedSystem getSystem(final Properties props) {
  // Setting the default disk store name is now done in setUp
  if (system == null) {
    system = InternalDistributedSystem.getAnyInstance();
  }
  if (system == null || !system.isConnected()) {
    // Figure out our distributed system properties
    Properties p = DistributedTestUtils.getAllDistributedSystemProperties(props);
    lastSystemCreatedInTest = getTestClass(); // used to be getDeclaringClass()
    if (logPerTest) {
      String testMethod = getTestMethodName();
      String testName = lastSystemCreatedInTest.getName() + '-' + testMethod;
      String oldLogFile = p.getProperty(LOG_FILE);
      p.put(LOG_FILE, oldLogFile.replace("system.log", testName + ".log"));
      String oldStatFile = p.getProperty(STATISTIC_ARCHIVE_FILE);
      p.put(STATISTIC_ARCHIVE_FILE, oldStatFile.replace("statArchive.gfs", testName + ".gfs"));
    }
    system = (InternalDistributedSystem) DistributedSystem.connect(p);
    lastSystemProperties = p;
  } else {
    boolean needNewSystem = false;
    if (!getTestClass().equals(lastSystemCreatedInTest)) { // used to be getDeclaringClass()
      Properties newProps = DistributedTestUtils.getAllDistributedSystemProperties(props);
      needNewSystem = !newProps.equals(lastSystemProperties);
      if (needNewSystem) {
        LogWriterUtils.getLogWriter()
            .info("Test class has changed and the new DS properties are not an exact match. "
                + "Forcing DS disconnect. Old props = " + lastSystemProperties + "new props="
                + newProps);
      }
    } else {
      Properties activeProps = system.getProperties();
      for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        if (!value.equals(activeProps.getProperty(key))) {
          needNewSystem = true;
          LogWriterUtils.getLogWriter().info("Forcing DS disconnect. For property " + key
              + " old value = " + activeProps.getProperty(key) + " new value = " + value);
          break;
        }
      }
    }
    if (needNewSystem) {
      // the current system does not meet our needs to disconnect and
      // call recursively to get a new system.
      LogWriterUtils.getLogWriter()
          .info("Disconnecting from current DS in order to make a new one");
      disconnectFromDS();
      getSystem(props);
    }
  }
  return system;
}
 
Example 14
Project: rmq4note   File: MixAll.java   View Source Code Vote up 4 votes
public static boolean isPropertiesEqual(final Properties p1, final Properties p2) {
    return p1.equals(p2);
}