id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
16d5d9d2-0795-468d-afa5-6007253282a8 | @Test
public void entre5Dias2() {
inicial = new DateTime(2010, 07, 19, 11, 1, 0, 0);
finall = new DateTime(2010, 07, 20, 14, 59, 0, 0);
Tempo labor = calc.quantidadeDeHoras(inicial, finall, janela);
assertEquals(9, labor.getHoras());
assertEquals(58, labor.getMinutos());
} |
b70a5643-7313-42e2-8688-91e67099fcc7 | @Test
public void entreAnos() {
inicial = new DateTime(2009, 12, 31, 14, 0, 0, 0);
finall = new DateTime(2010, 1, 1, 12, 0, 0, 0);
Tempo labor = calc.quantidadeDeHoras(inicial, finall, janela);
assertEquals(8, labor.getHoras());
assertEquals(0, labor.getMinutos());
} |
85c75042-9a9c-472f-8edb-3cf3712cc1c6 | @Test
public void entreFinaisDeSemana() {
inicial = new DateTime(2010, 7, 9, 20, 0, 0, 0);
finall = new DateTime(2010, 7, 12, 8, 1, 0, 0);
Tempo labor = calc.quantidadeDeHoras(inicial, finall, janela);
assertEquals(0, labor.getHoras());
assertEquals(1, labor.getMinutos());
} |
21210539-7bd3-44bc-a995-acfe73e2cb07 | @Test
public void testezao01() {
inicial = new DateTime(2012, 6, 4, 11, 35, 0, 0);
finall = new DateTime(2012, 6, 4, 11, 37, 0, 0);
Tempo labor = calc.quantidadeDeHoras(inicial, finall, janela);
assertEquals(0, labor.getHoras());
assertEquals(2, labor.getMinutos());
} |
73f8c295-bff2-48fc-8335-65ee886b9299 | @Test
public void testezao02() {
inicial = new DateTime(2012, 6, 4, 8, 58, 0, 0);
finall = new DateTime(2012, 6, 14, 14, 35, 0, 0);
Tempo labor = calc.quantidadeDeHoras(inicial, finall, janela);
assertEquals(2, labor.getDias());
assertEquals(19, labor.getHoras());
assertEquals(37, labor.getMinutos());
} |
46b2b699-1f5f-45c4-ac88-c2837274ac54 | @Test
public void testezao03() {
inicial = new DateTime(2012, 6, 4, 8, 58, 0, 0);
finall = new DateTime(2012, 6, 4, 8, 58, 0, 0);
Tempo labor = calc.quantidadeDeHoras(inicial, finall, janela);
assertEquals(0, labor.getDias());
assertEquals(0, labor.getHoras());
assertEquals(0, labor.getMinutos());
} |
8cdbaa18-622a-43c3-993a-9b449f056ee8 | public Main() {
loadProperties();
initComponents();
setLocationRelativeTo(null);
if(!isPasswordCorrect()) {
System.exit(0);
}
} |
13531485-8b96-44fd-9f97-2263c91773aa | private boolean isPasswordCorrect() {
String passwordPropertyMd5 = properties.getProperty(Globals.PROPERTY_KEY_PASSWORD);
//Comprobar si hay configurada una contraseña de acceso
if(passwordPropertyMd5!=null) {
//Solicitar contraseña de acceso
PasswordDialog passwordDialog = new PasswordDialog(this, true);
passwordDialog.setVisible(true);
if(passwordDialog.isOkButtonPressed()) {
String passwordMd5 = passwordDialog.getPasswordMd5();
//Comprobar si la contraseña es correcta
if(!passwordPropertyMd5.equals(passwordMd5)) {
JOptionPane.showMessageDialog(this,
Globals.BUNDLE.getString("wrongPassword"),
Globals.BUNDLE.getString("appTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
} else { //Se ha pulsado en botón Cancelar en la ventana de solicitud de contraseña
return false;
}
} else { //No hay contraseña establecida aún
//Abrir la ventana de configuración para pedir nueva contraseña
SettingsDialog settingsDialog = new SettingsDialog(this, true);
settingsDialog.setProperties(properties);
settingsDialog.setVisible(true);
//Si no se ha pulsado el botón OK, no se acepta la password introducida
if(!settingsDialog.isOkButtonPressed()) {
return false;
}
}
//Todo ha ido bien. Se considera que la contraseña introducida es correcta
return true;
} |
abbb2edf-6652-4a60-ac64-5b44d7af10dd | private void loadProperties() {
try {
properties.load(new FileReader(Globals.PROPERTIES_FILE_NAME));
String propLanguage = properties.getProperty(Globals.PROPERTY_KEY_LANGUAGE, Globals.DEFAULT_LANGUAGE);
Locale.setDefault(new Locale(propLanguage));
} catch (FileNotFoundException ex) {
//No hay problema si no existe el fichero de propiedades, se creará después
} catch (IOException ex) {
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
}
} |
f5eb2ed5-af74-4845-8e86-68015ff97c55 | @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jButtonSettings = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jButtonSettings.setText("Settings");
jButtonSettings.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSettingsActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButtonSettings)
.addContainerGap(299, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButtonSettings)
.addContainerGap(265, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents |
eedb1d75-88c5-461e-8f4b-ba1505733b49 | public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
} |
49e07c0c-0e8a-429a-8b25-bfb9cca4dbb2 | public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSettingsActionPerformed(evt);
} |
21f3aac7-04eb-4b59-b109-fed13cce980f | private void jButtonSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSettingsActionPerformed
SettingsDialog settingsDialog = new SettingsDialog(this, true);
settingsDialog.setProperties(properties);
settingsDialog.setVisible(true);
}//GEN-LAST:event_jButtonSettingsActionPerformed |
5d9a3214-cffb-4c44-b70b-45a828a2a305 | private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
try {
//Guardar las propiedades en el archivo
properties.store(new FileWriter(Globals.PROPERTIES_FILE_NAME), "");
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_formWindowClosing |
32b0bcb5-ab1f-4441-b582-821d1b803e5b | public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().setVisible(true);
}
});
} |
180e50ce-e0e0-4a50-83c4-2b3ca11102f5 | public void run() {
new Main().setVisible(true);
} |
bc90f09a-2657-4f88-bf28-08517a107103 | public PasswordDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
setResizable(false);
setLocationRelativeTo(parent);
getRootPane().setDefaultButton(jButtonOk);
} |
0d2ac19e-c1b0-47e4-a122-bd607c92ef57 | public boolean isOkButtonPressed() {
return OkButtonPressed;
} |
0c506c06-8acc-464c-9a5f-739060b1f1c2 | public String getPasswordMd5() {
return passwordMd5;
} |
af173ad7-5066-4c70-a081-f1993dec2169 | @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPasswordField1 = new javax.swing.JPasswordField();
jButtonOk = new javax.swing.JButton();
jButtonCancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("res/strings"); // NOI18N
setTitle(bundle.getString("appTitle")); // NOI18N
jLabel1.setText(bundle.getString("password")); // NOI18N
jButtonOk.setText(bundle.getString("login")); // NOI18N
jButtonOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonOkActionPerformed(evt);
}
});
jButtonCancel.setText(bundle.getString("cancel")); // NOI18N
jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 60, Short.MAX_VALUE)
.addComponent(jButtonOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonCancel))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPasswordField1)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonOk)
.addComponent(jButtonCancel))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents |
dbb537bb-4f42-47ad-836d-6f5901ec8619 | public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonOkActionPerformed(evt);
} |
2968a92c-ebf4-4661-b7d2-67adb1f25236 | public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelActionPerformed(evt);
} |
97c4ff35-0081-4a5d-b0c1-1ead35174f95 | private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
OkButtonPressed = false;
dispose();
}//GEN-LAST:event_jButtonCancelActionPerformed |
bf31c742-0237-4f79-bb0e-b044e401b1b8 | private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
passwordMd5 = Util.toMd5(jPasswordField1.getPassword(), true);
OkButtonPressed = true;
dispose();
}//GEN-LAST:event_jButtonOkActionPerformed |
6e8982d4-f578-451b-95d7-0a548e51f063 | public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
PasswordDialog dialog = new PasswordDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
} |
3a824f65-0489-4100-93a3-32ee0e0564fa | public void run() {
PasswordDialog dialog = new PasswordDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} |
f79069fc-7bf7-4ca2-a6a4-a155e4968520 | @Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
} |
1907248d-8d67-4b1d-8fa7-85af0a3ccb5b | public static String toMd5(char[] input, boolean clearInput) {
String md5 = null;
if (input != null) {
try {
//Convertir la entrada a array de bytes, ya que así se requiere
// para poder codificarla a MD5. No se debe conviertir a String
// por cuestiones de seguridad
byte[] arrayBytesInput = toBytes(input);
//Realizar la codificación
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] arrayBytesMd5 = md.digest(arrayBytesInput);
//it is recommended that the returned character array be cleared
// after use by setting each character to zero
Arrays.fill(arrayBytesInput, (byte) 0);
if(clearInput) {
Arrays.fill(input, '\u0000');
}
//Convertir a hexadecimal pasándolo a BigInteger
BigInteger bigIntMd5 = new BigInteger(1, arrayBytesMd5);
md5 = bigIntMd5.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while (md5.length() < 32) {
md5 = "0" + md5;
}
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
}
}
return md5;
} |
328a5eee-61eb-4767-80b2-97ca2441caa6 | public static byte[] toBytes(char[] chars) {
CharBuffer charBuffer = CharBuffer.wrap(chars);
ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer);
byte[] bytes = Arrays.copyOfRange(byteBuffer.array(),
byteBuffer.position(), byteBuffer.limit());
Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data
Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data
return bytes;
} |
c50bb517-3820-4edd-a952-8eeb21dcad03 | public static void restartJarApplication(Class appClass) {
try {
final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
final File currentJar = new File(appClass.getProtectionDomain().getCodeSource().getLocation().toURI());
/* Build command: java -jar application.jar */
final ArrayList<String> command = new ArrayList<String>();
command.add(javaBin);
command.add("-jar");
command.add(currentJar.getPath());
final ProcessBuilder builder = new ProcessBuilder(command);
builder.start();
System.exit(0);
} catch (URISyntaxException ex) {
Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
}
} |
bd80535b-77ae-40ea-b542-bb1041376d5f | public SettingsDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
setResizable(false);
setLocationRelativeTo(parent);
getRootPane().setDefaultButton(jButtonOk);
} |
44bce476-f770-4b8c-ae1e-5740b190191e | public void setProperties(Properties properties) {
this.properties = properties;
fillComboBoxLanguages();
//Si no hay una contraseña en el archivo de propiedades, activar campos
// para obligar nueva contraseña
if(properties.getProperty(Globals.PROPERTY_KEY_PASSWORD)==null) {
jCheckBox1.setSelected(true);
jCheckBox1.setEnabled(false);
jPasswordFieldOld.setEnabled(false);
jPasswordFieldNew.setEnabled(true);
jPasswordFieldConfirm.setEnabled(true);
}
} |
138b2fcb-7c32-445b-af8e-bb8dd2d99b40 | public boolean isOkButtonPressed() {
return okButtonPressed;
} |
cc4c251f-fc75-4967-aa5e-c0fbdc87bb6f | public void fillComboBoxLanguages() {
//Crear un array con los nombres completos de los idiomas
String[] labelLanguages = new String[Globals.LANGUAGES.length];
for (int i = 0; i < labelLanguages.length; i++) {
//Obtener el nombre de cada idioma
labelLanguages[i] = (new Locale(Globals.LANGUAGES[i])).getDisplayName();
}
//Pasar al JComboBox el array de nombres de idiomas
DefaultComboBoxModel cbModel = new DefaultComboBoxModel(labelLanguages);
jComboBoxLanguage.setModel(cbModel);
//Leer el idioma que se encuentra en el archivo de propiedades
String languageInProperties = properties.getProperty(Globals.PROPERTY_KEY_LANGUAGE);
//Obtener la posición en la que se encuentra dentro del array <languages> el idioma que
// se ha leído en el archivo de propiedades
int indexOfLanguage = Arrays.asList(Globals.LANGUAGES).indexOf(languageInProperties);
if(indexOfLanguage==-1) {
indexOfLanguage = 0;
}
//Marcar como seleccionado el idioma del archivo de propiedades
jComboBoxLanguage.setSelectedIndex(indexOfLanguage);
} |
8a9e7834-2b53-49cd-b846-a7648c6d2151 | public static boolean isPasswordValid(char[] password, int minLength,
boolean digitRequired, boolean lowerCaseRequired,
boolean upperCaseRequired, boolean specialCharRequired) {
boolean hasDigit = false;
boolean hasLower = false;
boolean hasUpper = false;
boolean hasSpecialChar = false;
if(password.length >= minLength) {
for(int i=0; i<password.length; i++) {
char c = password[i];
if(Character.isDigit(c)) {
hasDigit = true;
}
if(Character.isLetter(c) && Character.isLowerCase(c)) {
hasLower = true;
}
if(Character.isLetter(c) && !Character.isLowerCase(c)) {
hasUpper = true;
}
if(!Character.isDigit(c) && !Character.isAlphabetic(c)) {
hasSpecialChar = true;
}
}
//Comprobar si se cumplen todas las condiciones impuestas
if(digitRequired == hasDigit && lowerCaseRequired == hasLower &&
upperCaseRequired == hasUpper &&
specialCharRequired == hasSpecialChar) {
return true;
}
}
return false;
} |
ced42023-7b64-46fa-a2c0-f9d029b1cc82 | @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jButtonCancel = new javax.swing.JButton();
jButtonOk = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jComboBoxLanguage = new javax.swing.JComboBox();
jLabel1 = new javax.swing.JLabel();
jPasswordFieldOld = new javax.swing.JPasswordField();
jLabel2 = new javax.swing.JLabel();
jPasswordFieldNew = new javax.swing.JPasswordField();
jLabel3 = new javax.swing.JLabel();
jPasswordFieldConfirm = new javax.swing.JPasswordField();
jCheckBox1 = new javax.swing.JCheckBox();
jTextField1.setText("jTextField1");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("res/strings"); // NOI18N
setTitle(bundle.getString("settings")); // NOI18N
jButtonCancel.setText(bundle.getString("cancel")); // NOI18N
jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelActionPerformed(evt);
}
});
jButtonOk.setText(bundle.getString("ok")); // NOI18N
jButtonOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonOkActionPerformed(evt);
}
});
jLabel4.setText(bundle.getString("language")); // NOI18N
jComboBoxLanguage.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jLabel1.setText(bundle.getString("oldPassword")); // NOI18N
jPasswordFieldOld.setColumns(10);
jPasswordFieldOld.setEnabled(false);
jLabel2.setText(bundle.getString("newPassword")); // NOI18N
jPasswordFieldNew.setColumns(10);
jPasswordFieldNew.setEnabled(false);
jLabel3.setText(bundle.getString("confirmPassword")); // NOI18N
jPasswordFieldConfirm.setColumns(10);
jPasswordFieldConfirm.setEnabled(false);
jCheckBox1.setText(bundle.getString("changePassword")); // NOI18N
jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBoxLanguage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(88, 88, 88)
.addComponent(jButtonOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonCancel))
.addComponent(jCheckBox1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPasswordFieldOld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPasswordFieldNew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPasswordFieldConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jComboBoxLanguage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jCheckBox1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jPasswordFieldOld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jPasswordFieldNew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jPasswordFieldConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonCancel)
.addComponent(jButtonOk))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents |
231d820f-43bd-4ec5-9b91-fcd70234cdd8 | public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelActionPerformed(evt);
} |
dcb5b704-bb56-4103-bc35-ea7c4f0b252a | public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonOkActionPerformed(evt);
} |
b7f16504-8395-4cb4-b2cb-e8e0ed366753 | public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox1ActionPerformed(evt);
} |
6f29d063-cb91-471a-806a-8d28a0a4b473 | private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
jPasswordFieldOld.setEnabled(jCheckBox1.isSelected());
jPasswordFieldNew.setEnabled(jCheckBox1.isSelected());
jPasswordFieldConfirm.setEnabled(jCheckBox1.isSelected());
}//GEN-LAST:event_jCheckBox1ActionPerformed |
b6fb6c19-01da-4921-80c8-f595aa93af9a | private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
boolean error = false;
char[] oldPassword = null, newPassword = null, confirmPassword = null;
//Obtener la posición del idioma seleccionado en la lista desplegable
int indexLanguageSelected = jComboBoxLanguage.getSelectedIndex();
//Establecer la propiedad del idioma
properties.setProperty(Globals.PROPERTY_KEY_LANGUAGE, Globals.LANGUAGES[indexLanguageSelected]);
if (jCheckBox1.isSelected()) {
//Obtener las contraseñas introducidas por el usuario
oldPassword = jPasswordFieldOld.getPassword();
newPassword = jPasswordFieldNew.getPassword();
confirmPassword = jPasswordFieldConfirm.getPassword();
//Codificar la contraseña anterior para compararla después
String oldPasswordMd5 = Util.toMd5(oldPassword, false);
//Obtener la contraseña codificada que hay en el archivo de propiedades
String passwordPropertyMd5 = null;
passwordPropertyMd5 = properties.getProperty(Globals.PROPERTY_KEY_PASSWORD);
//Comprobar si no había contraseña en el archivo de propiedades y se ha
// dejado en blanco la contraseña anterior en la ventana
if (passwordPropertyMd5 == null && oldPassword.length == 0
|| //O bien, si hay una contraseña en el archivo de propiedades y
// coincide con la contraseña anterior en la ventana
passwordPropertyMd5 != null && passwordPropertyMd5.equals(oldPasswordMd5)) {
//Comprobar si coincinden la nueva contraseña y la confirmación
if (Arrays.equals(newPassword, confirmPassword)) {
//Comprobar si la contraseña cumple con los requisitos mínimos
if (isPasswordValid(newPassword,
Globals.PASSWORD_MIN_LENGTH, Globals.PASSWORD_REQUIRE_DIGIT,
Globals.PASSWORD_REQUIRE_LOWERCASE, Globals.PASSWORD_REQUIRE_UPPERCASE,
Globals.PASSWORD_REQUIRE_SPECIALCHAR)) {
//Codificar la nueva contraseña
String newPasswordMd5 = Util.toMd5(newPassword, true);
//Guardar la contraseña codificada en el archivo de propiedades
properties.setProperty(Globals.PROPERTY_KEY_PASSWORD, newPasswordMd5);
} else { //No se cumplen las condiciones mínimas de la nueva contraseña
error = true;
//Informar al usuario que no se cumplen las condiciones mínimas para la contraseña
String message = Globals.BUNDLE.getString("passwordNotValid")
+ "\n - " + MessageFormat.format(Globals.BUNDLE.getString("passwordMinLength"), Globals.PASSWORD_MIN_LENGTH)
+ (Globals.PASSWORD_REQUIRE_DIGIT ? "\n - " + Globals.BUNDLE.getString("passwordRequireDigit") : "")
+ (Globals.PASSWORD_REQUIRE_LOWERCASE ? "\n - " + Globals.BUNDLE.getString("passwordRequireLowerCase") : "")
+ (Globals.PASSWORD_REQUIRE_UPPERCASE ? "\n - " + Globals.BUNDLE.getString("passwordRequireUpperCase") : "")
+ (Globals.PASSWORD_REQUIRE_SPECIALCHAR ? "\n - " + Globals.BUNDLE.getString("passwordrequireSpecialChar") : "");
JOptionPane.showMessageDialog(this, message, Globals.BUNDLE.getString("appTitle"), JOptionPane.WARNING_MESSAGE);
}
} else { //La nueva contraseña y la confirmación no coinciden
error = true;
JOptionPane.showMessageDialog(this,
Globals.BUNDLE.getString("passwordsMismatch"),
Globals.BUNDLE.getString("appTitle"),
JOptionPane.WARNING_MESSAGE);
}
} else { //La contraseña anterior introducida por el usuario no coincide
// con la que se encuentra en el archivo de propiedades
error = true;
JOptionPane.showMessageDialog(this,
Globals.BUNDLE.getString("wrongPassword"),
Globals.BUNDLE.getString("appTitle"),
JOptionPane.ERROR_MESSAGE);
}
}
if(!error) {
//Limpiar de la memoria las contraseñas
Arrays.fill(oldPassword, '\u0000');
Arrays.fill(newPassword, '\u0000');
Arrays.fill(confirmPassword, '\u0000');
//Preguntar al usuario si desea reiniciar ahora para que los cambios tengan efecto
int response = JOptionPane.showConfirmDialog(this,
Globals.BUNDLE.getString("mustRestart"),
Globals.BUNDLE.getString("appTitle"),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.YES_OPTION) {
//Guardar las propiedades en el archivo y reiniciar
try {
properties.store(new FileWriter(Globals.PROPERTIES_FILE_NAME), "");
Util.restartJarApplication(SettingsDialog.class);
} catch (IOException ex) {
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
okButtonPressed = true;
dispose();
}
}
}//GEN-LAST:event_jButtonOkActionPerformed |
07d36219-4004-405c-a829-984f0836264f | private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
dispose();
}//GEN-LAST:event_jButtonCancelActionPerformed |
f01e063b-57e5-4012-97b7-eabf9025555a | public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
SettingsDialog dialog = new SettingsDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
} |
86edc07a-3267-4a5d-a7b9-736a4d5f617a | public void run() {
SettingsDialog dialog = new SettingsDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} |
b9a7d609-6ddd-4fb3-9f6e-48fc9eab4bb4 | @Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
} |
5a0056c1-d3aa-4bff-a485-859710735c57 | void call(int index); |
01e64dcb-1cc0-4801-a60f-04d336828edd | RunnableBlock(final Runnable task) {
_task = task;
} |
650c764b-5106-44ef-9975-97648c5daf78 | public void call(final int index) {
_task.run();
} |
0a1838aa-0769-486a-874f-bebf0e3af79c | public static void parallel(final int numThreads, final Runnable block) {
parallel(numThreads, new RunnableBlock(block));
} |
7f1d1cb5-8f52-49c1-b6eb-cac938e9067c | public static void parallel(final int numThreads, final Block block) {
final Thread[] threads = new Thread[numThreads];
final Throwable[] failure = { null };
for (int i = 0; i < threads.length; ++i) {
final int index = i;
threads[i] = new Thread("worker #" + i) {
@Override
public void run() {
try {
block.call(index);
} catch (final Throwable xx) {
failure[0] = xx;
}
}
};
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
try {
t.join();
} catch (final InterruptedException xx) {
throw new RuntimeException("unexpected", xx);
}
}
if (failure[0] instanceof RuntimeException) {
throw (RuntimeException) failure[0];
} else if (failure[0] instanceof Error) {
throw (Error) failure[0];
} else {
assert (failure[0] == null);
}
} |
63778f58-b3f8-4394-a6b7-27aa0885562b | @Override
public void run() {
try {
block.call(index);
} catch (final Throwable xx) {
failure[0] = xx;
}
} |
2762d24c-1a66-413c-a1f3-bd22f2296194 | public static long timeParallel(final int numThreads, final Runnable block) {
return timeParallel(numThreads, new RunnableBlock(block));
} |
c58963df-ddec-4b07-b77f-53ea757e2ce3 | public static long timeParallel(final int numThreads, final Block block) {
final long[] times = new long[2];
final CyclicBarrier barrier = new CyclicBarrier(numThreads,
new Runnable() {
public void run() {
times[0] = times[1];
times[1] = System.currentTimeMillis();
}
});
parallel(numThreads, new Block() {
public void call(final int index) {
try {
barrier.await();
} catch (final Exception xx) {
throw new RuntimeException("unexpected", xx);
}
try {
block.call(index);
} finally {
try {
barrier.await();
} catch (final Exception xx) {
throw new RuntimeException("unexpected", xx);
}
}
}
});
return times[1] - times[0];
} |
b67af223-28e5-4f71-a705-cd16af63dd7f | public void run() {
times[0] = times[1];
times[1] = System.currentTimeMillis();
} |
ddf5c94e-1856-49a8-9d1a-3aeda2e8562a | public void call(final int index) {
try {
barrier.await();
} catch (final Exception xx) {
throw new RuntimeException("unexpected", xx);
}
try {
block.call(index);
} finally {
try {
barrier.await();
} catch (final Exception xx) {
throw new RuntimeException("unexpected", xx);
}
}
} |
5afbcb68-aef8-41c9-9999-68e6085f13b7 | private static int getHash(int x, int bits) {
int mask = (int) ((1L << (1 << bits)) - 1);
return x & mask;
} |
ba73fd69-78a7-4fd6-84ee-2ff892ea780b | public static void main(String[] args) {
ConcurrentTester tester = new ConcurrentTester();
/*numThreads = Integer.parseInt(args[0]);
outerPasses = workers / numThreads;
boolean withoutRemove = args[1].equals("without_remove");*/
tester.testConcurrent(true);
} |
5507a5f7-c7ef-4098-9e23-f79fadaae30d | public void testConcurrent(final boolean withoutRemove) {
final UHTree map = UHTreeCreator.getNewUHTree(order);
final Random random = new Random(0);
final int keyRange = 500000; // Rango de los elementos a ingresar en el
// UHTree.
final RandomDistribution.Zipf zipf = new RandomDistribution.Zipf(
random, 0, keyRange, 1.3);
for(int i = 0; i < keyRange; i++) map.add(i, i);
long t1 = System.nanoTime();
for (int outer = 0; outer < outerPasses; ++outer) {
ParUtil.parallel(numThreads, new Runnable() {
public void run() {
for (int inner = 0; inner < innerOps; ++inner) {
final int pct = random.nextInt(100);
final int key = zipf.nextInt();
final int hash = getHash(key, order);
if (pct < putPct) {
map.add(hash, key);
} else if (pct < searchPct || withoutRemove) {
map.contains(hash, key);
} else {
map.remove(hash, key);
}
}
//System.out.println("Finished pass.");
}
});
}
long t2 = System.nanoTime();
System.out.println((t2 - t1) / (1000000000.0) + " segundos.");
for (int i = 0; i < keyRange; i++)
map.remove(getHash(i, order), i);
assert map.isEmpty();
} |
f9416459-9084-4c58-b043-164ebd765d51 | public void run() {
for (int inner = 0; inner < innerOps; ++inner) {
final int pct = random.nextInt(100);
final int key = zipf.nextInt();
final int hash = getHash(key, order);
if (pct < putPct) {
map.add(hash, key);
} else if (pct < searchPct || withoutRemove) {
map.contains(hash, key);
} else {
map.remove(hash, key);
}
}
//System.out.println("Finished pass.");
} |
041c0d5e-b59a-4c5e-9ac6-607f4cfcfa1f | public UHList() {
} |
0c493aa5-1e62-4fc0-9c42-b4549a6c948a | public UHList(Object value) {
addNewElement(value);
} |
b22b800f-329b-4bc9-a685-0f1b351347af | public void addNewElement(Object value) {
if (value instanceof UHList) {
set.putAll(((UHList) value).set);
} else {
UHElement newElement = new UHElement(value);
set.put(newElement, newElement);
}
} |
b9f26e3e-f304-47cc-acbd-13667f0ec714 | public boolean contains(Object value, UHNode uhNode) {
UHElement element = set.get(new UHElement(value));
if (element == null) {
return false;
} else {
element.incr();
if (best == null || best.getCount() < element.getCount()) {
best = element;
}
uhNode.updateBest(best);
return true;
}
} |
b8343ae8-2279-425c-86e4-8653a0e83056 | public boolean isEmpty() {
return set.isEmpty();
} |
5ac54507-ada5-467c-b968-318c36ac7ce6 | public ConcurrentHashMap<UHElement, UHElement> getSet() {
return set;
} |
28b8e4e4-10fd-4930-a257-ec039ed3f210 | public boolean remove(Object value) {
assert !(value instanceof UHList);
boolean success = set.remove(new UHElement(value)) != null;
if (success && value.equals(best))
best = null;
return success;
} |
6522e848-c220-49f8-b15d-0ceecf1ac1cc | public UHTree(int order) {
root = new UHNode(order);
} |
c62b405d-d26e-40f3-97d1-019cef66d06a | public boolean contains(int hash, Object value) {
return root.contains(hash, value);
} |
aafb0719-cc77-426d-8374-9a51c7252e3d | public boolean remove(int hash, Object value) {
return root.remove(hash, value);
} |
85ce2293-8cd9-4251-93b1-616b686128df | public void add(int hash, Object value) {
root.add(hash, value);
} |
419caf03-a1d4-4072-9332-e7934e889337 | public boolean isEmpty() {
return root.isEmpty();
} |
fe0aab4f-7915-4cbc-806f-75c1a2a01455 | public int getMinHash() {
return root.getMinHash();
} |
2190f24b-08b7-40b9-802b-543e966f7a5b | public UHElement(Object value) {
this.value = value;
} |
8163a93d-bceb-4d53-9b4e-344fb7a68955 | public void incr() {
count++;
} |
f1e05707-8991-4a42-bc1b-58c33428b256 | public int getCount() {
return count;
} |
0147c637-0888-4694-b9fb-49a22ab463f0 | public Object getValue() {
return value;
} |
a4ad3a77-d910-4ebb-8fe1-99fdb86180ce | @Override
public boolean equals(Object other) {
if (other instanceof UHElement) {
UHElement uhElement = (UHElement) other;
return value.equals(uhElement.getValue());
} else
return value.equals(other);
} |
e93a3edb-7953-41d4-9d1c-c03751aa4941 | @Override
public int hashCode() {
return value.hashCode();
} |
3739bd1b-35bb-4327-bd16-c907ed669ae5 | public static UHTree getNewUHTree(int order) {
return new UHTree(order);
} |
6c386e94-6395-4405-8565-39427535538d | public static IntegerHeap getNewIntegerHeap(int order) {
if (order <= 2) {
return new UHBitmaskHeap(order);
} else {
return new UHNode(order);
}
} |
950da3b0-bcd5-4609-a772-6f2c770157fd | public int nextInt(); |
de5e4b53-3516-49ec-a6f3-12c24b2faa1a | public Flat(Random random, int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("Invalid range");
}
this.random = random;
this.min = min;
this.max = max;
} |
1f4351c7-f4c3-4824-a0a9-937c6fdd15ac | @Override
public int nextInt() {
return random.nextInt(max - min) + min;
} |
30852fd2-0aa3-4265-bd89-692a74bfa0ba | public Zipf(Random r, int min, int max, double sigma) {
this(r, min, max, sigma, DEFAULT_EPSILON);
} |
729a054f-7f58-43ff-9f98-08eed4bcc33f | public Zipf(Random r, int min, int max, double sigma, double epsilon) {
if ((max <= min) || (sigma <= 1) || (epsilon <= 0)
|| (epsilon >= 0.5)) {
throw new IllegalArgumentException("Invalid arguments");
}
random = r;
k = new ArrayList<Integer>();
v = new ArrayList<Double>();
double sum = 0;
int last = -1;
for (int i = min; i < max; ++i) {
sum += Math.exp(-sigma * Math.log(i - min + 1));
if ((last == -1) || i * (1 - epsilon) > last) {
k.add(i);
v.add(sum);
last = i;
}
}
if (last != max - 1) {
k.add(max - 1);
v.add(sum);
}
v.set(v.size() - 1, 1.0);
for (int i = v.size() - 2; i >= 0; --i) {
v.set(i, v.get(i) / sum);
}
} |
679394b1-b54b-4243-9bfe-8d8e699af5a8 | @Override
public int nextInt() {
double d = random.nextDouble();
int idx = Collections.binarySearch(v, d);
if (idx > 0) {
++idx;
} else {
idx = -(idx + 1);
}
if (idx >= v.size()) {
idx = v.size() - 1;
}
if (idx == 0) {
return k.get(0);
}
int ceiling = k.get(idx);
int lower = k.get(idx - 1);
return ceiling - random.nextInt(ceiling - lower);
} |
8775bc4c-c19e-49aa-ad73-0e8b235b6d66 | private static double select(int n, int k) {
double ret = 1.0;
for (int i = k + 1; i <= n; ++i) {
ret *= (double) i / (i - k);
}
return ret;
} |
2e46fd50-89d7-4888-840e-6ee486236431 | private static double power(double p, int k) {
return Math.exp(k * Math.log(p));
} |
74052a79-f37b-4f1d-958e-0a5faf8bc42e | public Binomial(Random random, int min, int max, double p) {
if (min >= max) {
throw new IllegalArgumentException("Invalid range");
}
this.random = random;
this.min = min;
this.n = max - min - 1;
if (n > 0) {
v = new double[n + 1];
double sum = 0.0;
for (int i = 0; i <= n; ++i) {
sum += select(n, i) * power(p, i) * power(1 - p, n - i);
v[i] = sum;
}
for (int i = 0; i <= n; ++i) {
v[i] /= sum;
}
} else {
v = null;
}
} |
de02396e-8627-4fda-92fb-1e6ba8424ab2 | @Override
public int nextInt() {
if (v == null) {
return min;
}
double d = random.nextDouble();
int idx = Arrays.binarySearch(v, d);
if (idx > 0) {
++idx;
} else {
idx = -(idx + 1);
}
if (idx >= v.length) {
idx = v.length - 1;
}
return idx + min;
} |
74bd1907-0dc9-46cc-b2b7-88238822f293 | public UHBitmaskHeap(int order) {
mask = 0;
} |
ce0941b5-92b5-4137-9b41-066e73404b60 | public boolean isEmpty() {
return mask == 0;
} |
8d60bbac-0b21-4136-b902-df6aa4e9f654 | public void add(int x, Object y) {
mask |= 1 << x;
} |
48d558ca-6aff-4e08-8319-bff2a4bf9544 | public boolean remove(int x, Object y) {
if ((mask & (1 << x)) != 0) {
mask ^= 1 << x;
return true;
} else {
return false;
}
} |
63a0aca5-1fd6-4f4a-a4c3-1ea5d2030301 | public int getMinHash() {
assert mask != 0;
return Integer.numberOfTrailingZeros(mask);
} |
a6941b9e-6a9b-41bd-bf9b-149d03bf135b | public UHNode(int order) {
isEmpty = true;
this.order = order;
shift = 1 << (order - 1);
max = (int) ((1L << (1 << order)) - 1);
minElements = new UHList();
HQ = UHTreeCreator.getNewIntegerHeap(order - 1);
LQ = new UHNode[max + 1];
} |
b612bfac-41fc-4959-acd6-110652687c4c | public boolean isEmpty() {
assert !isEmpty || isEmpty && best == null;
return isEmpty;
} |
0e7b1638-5278-4ad3-9fb8-0d0364a20cb5 | public int getMinHash() {
assert isEmpty == false;
return min;
} |
44c49cdd-1895-465f-872d-6dacc356e9b1 | public UHList getMinElements() {
assert isEmpty == false;
return minElements;
} |
92ba0b6c-6e3b-4aeb-85c3-263a4ab13fee | public static int compareUnsignedInt(int a, int b) {
long val = (a & 0xffffffffL) - (b & 0xffffffffL);
return val < 0 ? -1 : val > 0 ? 1 : 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.