id stringlengths 7 14 | text stringlengths 1 106k |
|---|---|
1263661_2 | @Override
public boolean isValid() {
byte[] verify = this.capability.getVerificationKey();
byte[] fromServer = this.getPublicKeyHash();
int n = fromServer.length;
if (verify.length != fromServer.length) {
return false;
}
for (int i = 0; i < n; i++) {
if (verify[i] != fromServer[i]) {
return false;
}
}
byte[] hash = Cryptoutil.hash(this.ciphertext, -1);
return Cryptoutil.signature_valid(this.signature, hash, this.pubkey);
} |
1263661_3 | public CSVFolder getShareFolder() {
return this.sharedfolder;
} |
1263661_4 | public CSVFile uploadFile(CSVFile file)
throws ServerCommunicationException, InvalidWriteEnablerException,
ImmutableFileExistsException {
return (CSVFile) uploadObject(file);
} |
1263661_5 | public CSVFile downloadFile(CSVFile file)
throws ServerCommunicationException, InvalidWriteEnablerException,
ImmutableFileExistsException, RemoteFileDoesNotExistException,
FailedToVerifySignatureException {
return (CSVFile) downloadObject(file);
} |
1263661_6 | public CSVFolder uploadFolder(CSVFolder folder)
throws ServerCommunicationException, InvalidWriteEnablerException,
ImmutableFileExistsException {
return (CSVFolder) uploadObject(folder);
} |
1263661_7 | public CSVFolder downloadFolder(CSVFolder folder)
throws ServerCommunicationException, InvalidWriteEnablerException,
ImmutableFileExistsException, RemoteFileDoesNotExistException,
FailedToVerifySignatureException {
return (CSVFolder) downloadObject(folder);
} |
1263661_8 | public CSVFolder cd(String alias) throws ServerCommunicationException,
RemoteFileDoesNotExistException, NoSuchAliasException,
FailedToVerifySignatureException {
if (alias.equals("..")) {
this.location.pop();
return this.location.peek();
}
if (!this.location.peek().getContents().containsKey(alias)) {
throw new NoSuchAliasException(alias);
}
Capability capability = this.location.peek().getContents().get(alias);
CSVFolder folder = downloadFolder(capability);
this.location.push(folder);
return folder;
} |
1263661_9 | public CSVFile downloadFile(CSVFile file)
throws ServerCommunicationException, InvalidWriteEnablerException,
ImmutableFileExistsException, RemoteFileDoesNotExistException,
FailedToVerifySignatureException {
return (CSVFile) downloadObject(file);
} |
1269176_0 | public static String formatMemorySize(long memorySizeBytes) {
StringBuilder builder = new StringBuilder();
MemSize best = MemSize.getBestMemSize(memorySizeBytes);
double value = MemSize.getBestMemSizeValue(memorySizeBytes, best);
DecimalFormat df = new DecimalFormat("##.#");
builder.append(df.format(value));
builder.append(best.entity);
return builder.toString();
} |
1269176_1 | public static <T> T[] arrayMerge(T[]... arrays) {
Class objectClass = null;
int count = 0;
for(T[] array: arrays) {
if(array != null) {
count +=array.length;
if(array.length > 0)
objectClass = array[0].getClass();
}
}
if(objectClass == null)
return null;
List<T> mergedList = new ArrayList<T>();
for(T[] array: arrays)
if(array != null)
mergedList.addAll(Arrays.asList(array));
return mergedList.toArray((T[])Array.newInstance(objectClass, count));
} |
1269176_2 | public static <T> T[] arrayMerge(T[]... arrays) {
Class objectClass = null;
int count = 0;
for(T[] array: arrays) {
if(array != null) {
count +=array.length;
if(array.length > 0)
objectClass = array[0].getClass();
}
}
if(objectClass == null)
return null;
List<T> mergedList = new ArrayList<T>();
for(T[] array: arrays)
if(array != null)
mergedList.addAll(Arrays.asList(array));
return mergedList.toArray((T[])Array.newInstance(objectClass, count));
} |
1269176_3 | public static <T> T[] arrayMerge(T[]... arrays) {
Class objectClass = null;
int count = 0;
for(T[] array: arrays) {
if(array != null) {
count +=array.length;
if(array.length > 0)
objectClass = array[0].getClass();
}
}
if(objectClass == null)
return null;
List<T> mergedList = new ArrayList<T>();
for(T[] array: arrays)
if(array != null)
mergedList.addAll(Arrays.asList(array));
return mergedList.toArray((T[])Array.newInstance(objectClass, count));
} |
1269176_4 | public static <T> T[] arrayMerge(T[]... arrays) {
Class objectClass = null;
int count = 0;
for(T[] array: arrays) {
if(array != null) {
count +=array.length;
if(array.length > 0)
objectClass = array[0].getClass();
}
}
if(objectClass == null)
return null;
List<T> mergedList = new ArrayList<T>();
for(T[] array: arrays)
if(array != null)
mergedList.addAll(Arrays.asList(array));
return mergedList.toArray((T[])Array.newInstance(objectClass, count));
} |
1269176_5 | public static <T> T[] arrayMerge(T[]... arrays) {
Class objectClass = null;
int count = 0;
for(T[] array: arrays) {
if(array != null) {
count +=array.length;
if(array.length > 0)
objectClass = array[0].getClass();
}
}
if(objectClass == null)
return null;
List<T> mergedList = new ArrayList<T>();
for(T[] array: arrays)
if(array != null)
mergedList.addAll(Arrays.asList(array));
return mergedList.toArray((T[])Array.newInstance(objectClass, count));
} |
1269176_6 | public static int figureAngle(Point2D end1, Point2D end2) {
return figureAngle(end2.getX() - end1.getX(), end2.getY() - end1.getY());
} |
1269176_7 | } |
1269176_8 | } |
1269176_9 | public static boolean isSmallInt(long v) {
return ((v - MIN_SMALL_COORD) & Integer.MIN_VALUE) == 0;
} |
1273791_1 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_2 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_3 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_4 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_5 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_6 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_7 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_8 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1273791_9 | @Override
public List<Token> tokenize(String text) {
return createTokenList(text);
} |
1274071_0 | public PreorderNodeListGenerator resolve(String coordinate, List<RemoteRepository> repositories)
throws MavenResolverException {
try {
Dependency project = new Dependency(new DefaultArtifact(coordinate), "compile");
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(project);
for (RemoteRepository repo : repositories) {
collectRequest.addRepository(repo);
}
DependencyNode node = this.repoSystem.collectDependencies(this.session, collectRequest).getRoot();
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setRoot(node);
this.repoSystem.resolveDependencies(session, dependencyRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
node.accept(nlg);
return nlg;
} catch (DependencyCollectionException | DependencyResolutionException e) {
throw new MavenResolverException("Unable to resolve " + coordinate + " from " + repositories.toString(), e);
}
} |
1274071_1 | public static Result execute(List<AdaptationCommand> cmds) {
Result result = new Result();
for (AdaptationCommand cmd : cmds) {
try {
cmd.execute();
result.executedCmds.add(cmd);
} catch (KevoreeAdaptationException e) {
result.error = e;
return result;
}
}
return result;
} |
1274071_2 | public static Result execute(List<AdaptationCommand> cmds) {
Result result = new Result();
for (AdaptationCommand cmd : cmds) {
try {
cmd.execute();
result.executedCmds.add(cmd);
} catch (KevoreeAdaptationException e) {
result.error = e;
return result;
}
}
return result;
} |
1274071_3 | public static Result execute(List<AdaptationCommand> cmds) {
Result result = new Result();
for (AdaptationCommand cmd : cmds) {
try {
cmd.execute();
result.executedCmds.add(cmd);
} catch (KevoreeAdaptationException e) {
result.error = e;
return result;
}
}
return result;
} |
1274071_4 | public static Result execute(List<AdaptationCommand> cmds) {
Result result = new Result();
for (AdaptationCommand cmd : cmds) {
try {
cmd.execute();
result.executedCmds.add(cmd);
} catch (KevoreeAdaptationException e) {
result.error = e;
return result;
}
}
return result;
} |
1274332_0 | public boolean simpleBind (String dn, String password)
{
Hashtable<String, String> env = new Hashtable<String, String>();
// Set up environment properties needed for binding.
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, _uri);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put("java.naming.ldap.version", Integer.toString(LdapModule.LDAP_OPT_PROTOCOL_VERSION));
if (LdapModule.LDAP_OPT_REFERRALS == 1) {
env.put(Context.REFERRAL, "follow");
} else {
env.put(Context.REFERRAL, "ignore");
}
if (dn.length() > 0) {
if (password.length() == 0) {
/* If there is a dn but the password is empty, bail out now in case we happen to
* be connecting to a server that treats binds with a valid DN and no password as an
* anonymous bind. */
return false;
}
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
}
try {
_ctx = new InitialDirContext(env);
} catch (NamingException e) {
//e.printStackTrace();
return false;
}
return true;
} |
1274332_1 | public boolean simpleBind (String dn, String password)
{
Hashtable<String, String> env = new Hashtable<String, String>();
// Set up environment properties needed for binding.
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, _uri);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put("java.naming.ldap.version", Integer.toString(LdapModule.LDAP_OPT_PROTOCOL_VERSION));
if (LdapModule.LDAP_OPT_REFERRALS == 1) {
env.put(Context.REFERRAL, "follow");
} else {
env.put(Context.REFERRAL, "ignore");
}
if (dn.length() > 0) {
if (password.length() == 0) {
/* If there is a dn but the password is empty, bail out now in case we happen to
* be connecting to a server that treats binds with a valid DN and no password as an
* anonymous bind. */
return false;
}
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
}
try {
_ctx = new InitialDirContext(env);
} catch (NamingException e) {
//e.printStackTrace();
return false;
}
return true;
} |
1274332_2 | public boolean simpleBind (String dn, String password)
{
Hashtable<String, String> env = new Hashtable<String, String>();
// Set up environment properties needed for binding.
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, _uri);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put("java.naming.ldap.version", Integer.toString(LdapModule.LDAP_OPT_PROTOCOL_VERSION));
if (LdapModule.LDAP_OPT_REFERRALS == 1) {
env.put(Context.REFERRAL, "follow");
} else {
env.put(Context.REFERRAL, "ignore");
}
if (dn.length() > 0) {
if (password.length() == 0) {
/* If there is a dn but the password is empty, bail out now in case we happen to
* be connecting to a server that treats binds with a valid DN and no password as an
* anonymous bind. */
return false;
}
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
}
try {
_ctx = new InitialDirContext(env);
} catch (NamingException e) {
//e.printStackTrace();
return false;
}
return true;
} |
1274332_3 | public boolean simpleBind (String dn, String password)
{
Hashtable<String, String> env = new Hashtable<String, String>();
// Set up environment properties needed for binding.
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, _uri);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put("java.naming.ldap.version", Integer.toString(LdapModule.LDAP_OPT_PROTOCOL_VERSION));
if (LdapModule.LDAP_OPT_REFERRALS == 1) {
env.put(Context.REFERRAL, "follow");
} else {
env.put(Context.REFERRAL, "ignore");
}
if (dn.length() > 0) {
if (password.length() == 0) {
/* If there is a dn but the password is empty, bail out now in case we happen to
* be connecting to a server that treats binds with a valid DN and no password as an
* anonymous bind. */
return false;
}
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
}
try {
_ctx = new InitialDirContext(env);
} catch (NamingException e) {
//e.printStackTrace();
return false;
}
return true;
} |
1274332_4 | public boolean unbind ()
{
// Can't unbind if we never got bound in the first place!
if (_ctx == null) {
return false;
}
try {
_ctx.close();
} catch (NamingException e) {
//e.printStackTrace();
return false;
}
return true;
} |
1274332_5 | public static BooleanValue ldap_bind (LdapLinkResource linkIdentifier, @Optional String bindRdn,
@Optional String bindPassword)
{
boolean success = linkIdentifier.simpleBind(bindRdn, bindPassword);
return BooleanValue.create(success);
} |
1274332_6 | public static BooleanValue ldap_bind (LdapLinkResource linkIdentifier, @Optional String bindRdn,
@Optional String bindPassword)
{
boolean success = linkIdentifier.simpleBind(bindRdn, bindPassword);
return BooleanValue.create(success);
} |
1274332_7 | public static BooleanValue ldap_bind (LdapLinkResource linkIdentifier, @Optional String bindRdn,
@Optional String bindPassword)
{
boolean success = linkIdentifier.simpleBind(bindRdn, bindPassword);
return BooleanValue.create(success);
} |
1274332_8 | public static BooleanValue ldap_bind (LdapLinkResource linkIdentifier, @Optional String bindRdn,
@Optional String bindPassword)
{
boolean success = linkIdentifier.simpleBind(bindRdn, bindPassword);
return BooleanValue.create(success);
} |
1274332_9 | public static BooleanValue ldap_unbind (LdapLinkResource linkIdentifier)
{
// Avoid NPEs from this being called on non-existent linkIdentifiers.
if (linkIdentifier == null) {
return BooleanValue.create(false);
}
boolean success = linkIdentifier.unbind();
return BooleanValue.create(success);
} |
1287669_0 | @Override
public <T> T read(String path, Predicate... filters) {
notEmpty(path, "path can not be null or empty");
return read(pathFromCache(path, filters));
} |
1287669_1 | boolean isUpstreamDefinite() {
if (upstreamDefinite == null) {
upstreamDefinite = isRoot() || prev.isTokenDefinite() && prev.isUpstreamDefinite();
}
return upstreamDefinite;
} |
1287669_2 | boolean isUpstreamDefinite() {
if (upstreamDefinite == null) {
upstreamDefinite = isRoot() || prev.isTokenDefinite() && prev.isUpstreamDefinite();
}
return upstreamDefinite;
} |
1287669_3 | public static String join(String delimiter, String wrap, Iterable<?> objs) {
Iterator<?> iter = objs.iterator();
if (!iter.hasNext()) {
return "";
}
StringBuilder buffer = new StringBuilder();
buffer.append(wrap).append(iter.next()).append(wrap);
while (iter.hasNext()) {
buffer.append(delimiter).append(wrap).append(iter.next()).append(wrap);
}
return buffer.toString();
} |
1287669_4 | public static String concat(CharSequence... strings) {
if (strings.length == 0) {
return "";
}
if (strings.length == 1) {
return strings[0].toString();
}
int length = 0;
// -1 = no result, -2 = multiple results
int indexOfSingleNonEmptyString = -1;
for (int i = 0; i < strings.length; i++) {
CharSequence charSequence = strings[i];
int len = charSequence.length();
length += len;
if (indexOfSingleNonEmptyString != -2 && len > 0) {
if (indexOfSingleNonEmptyString == -1) {
indexOfSingleNonEmptyString = i;
} else {
indexOfSingleNonEmptyString = -2;
}
}
}
if (length == 0) {
return "";
}
if (indexOfSingleNonEmptyString > 0) {
return strings[indexOfSingleNonEmptyString].toString();
}
StringBuilder sb = new StringBuilder(length);
for (CharSequence charSequence : strings) {
sb.append(charSequence);
}
return sb.toString();
} |
1287669_5 | public static String escape(String str, boolean escapeSingleQuote) {
if (str == null) {
return null;
}
int len = str.length();
StringWriter writer = new StringWriter(len * 2);
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
// handle unicode
if (ch > 0xfff) {
writer.write("\\u" + hex(ch));
} else if (ch > 0xff) {
writer.write("\\u0" + hex(ch));
} else if (ch > 0x7f) {
writer.write("\\u00" + hex(ch));
} else if (ch < 32) {
switch (ch) {
case '\b':
writer.write('\\');
writer.write('b');
break;
case '\n':
writer.write('\\');
writer.write('n');
break;
case '\t':
writer.write('\\');
writer.write('t');
break;
case '\f':
writer.write('\\');
writer.write('f');
break;
case '\r':
writer.write('\\');
writer.write('r');
break;
default :
if (ch > 0xf) {
writer.write("\\u00" + hex(ch));
} else {
writer.write("\\u000" + hex(ch));
}
break;
}
} else {
switch (ch) {
case '\'':
if (escapeSingleQuote) {
writer.write('\\');
}
writer.write('\'');
break;
case '"':
writer.write('\\');
writer.write('"');
break;
case '\\':
writer.write('\\');
writer.write('\\');
break;
case '/':
writer.write('\\');
writer.write('/');
break;
default :
writer.write(ch);
break;
}
}
}
return writer.toString();
} |
1287669_6 | public static String unescape(String str) {
if (str == null) {
return null;
}
int len = str.length();
StringWriter writer = new StringWriter(len);
StringBuilder unicode = new StringBuilder(4);
boolean hadSlash = false;
boolean inUnicode = false;
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (inUnicode) {
unicode.append(ch);
if (unicode.length() == 4) {
try {
int value = Integer.parseInt(unicode.toString(), 16);
writer.write((char) value);
unicode.setLength(0);
inUnicode = false;
hadSlash = false;
} catch (NumberFormatException nfe) {
throw new JsonPathException("Unable to parse unicode value: " + unicode, nfe);
}
}
continue;
}
if (hadSlash) {
hadSlash = false;
switch (ch) {
case '\\':
writer.write('\\');
break;
case '\'':
writer.write('\'');
break;
case '\"':
writer.write('"');
break;
case 'r':
writer.write('\r');
break;
case 'f':
writer.write('\f');
break;
case 't':
writer.write('\t');
break;
case 'n':
writer.write('\n');
break;
case 'b':
writer.write('\b');
break;
case 'u':
{
inUnicode = true;
break;
}
default :
writer.write(ch);
break;
}
continue;
} else if (ch == '\\') {
hadSlash = true;
continue;
}
writer.write(ch);
}
if (hadSlash) {
writer.write('\\');
}
return writer.toString();
} |
1287669_7 | public static String unescape(String str) {
if (str == null) {
return null;
}
int len = str.length();
StringWriter writer = new StringWriter(len);
StringBuilder unicode = new StringBuilder(4);
boolean hadSlash = false;
boolean inUnicode = false;
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (inUnicode) {
unicode.append(ch);
if (unicode.length() == 4) {
try {
int value = Integer.parseInt(unicode.toString(), 16);
writer.write((char) value);
unicode.setLength(0);
inUnicode = false;
hadSlash = false;
} catch (NumberFormatException nfe) {
throw new JsonPathException("Unable to parse unicode value: " + unicode, nfe);
}
}
continue;
}
if (hadSlash) {
hadSlash = false;
switch (ch) {
case '\\':
writer.write('\\');
break;
case '\'':
writer.write('\'');
break;
case '\"':
writer.write('"');
break;
case 'r':
writer.write('\r');
break;
case 'f':
writer.write('\f');
break;
case 't':
writer.write('\t');
break;
case 'n':
writer.write('\n');
break;
case 'b':
writer.write('\b');
break;
case 'u':
{
inUnicode = true;
break;
}
default :
writer.write(ch);
break;
}
continue;
} else if (ch == '\\') {
hadSlash = true;
continue;
}
writer.write(ch);
}
if (hadSlash) {
writer.write('\\');
}
return writer.toString();
} |
1287669_8 | public static String hex(char ch) {
return Integer.toHexString(ch).toUpperCase();
} |
1287669_9 | public static boolean isEmpty(CharSequence cs) {
return cs == null || cs.length() == 0;
} |
1290826_0 | boolean verify_otp(String userName, String otp) {
try {
String authString = userName + ":" + otp;
String authStringEnc = Base64.encodeBase64URLSafeString(authString.getBytes());
BufferedReader in = attemptAuthentication(authStringEnc);
String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.contains(expectedOutput)) {
return true;
}
}
} catch (Exception ex) {
log.error("Failed verifying OATH OTP :", ex);
}
return false;
} |
1290826_1 | boolean verify_otp(String userName, String otp) {
try {
String authString = userName + ":" + otp;
String authStringEnc = Base64.encodeBase64URLSafeString(authString.getBytes());
BufferedReader in = attemptAuthentication(authStringEnc);
String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.contains(expectedOutput)) {
return true;
}
}
} catch (Exception ex) {
log.error("Failed verifying OATH OTP :", ex);
}
return false;
} |
1290826_2 | ; |
1290826_3 | ; |
1290826_4 | public static boolean isValidOTPFormat(String otp) {
if (otp == null){
return false;
}
int len = otp.length();
for (char c : otp.toCharArray()) {
if (c < 0x20 || c > 0x7E) {
return false;
}
}
return OTP_MIN_LEN <= len && len <= OTP_MAX_LEN;
} |
1290826_5 | public static boolean isValidOTPFormat(String otp) {
if (otp == null){
return false;
}
int len = otp.length();
for (char c : otp.toCharArray()) {
if (c < 0x20 || c > 0x7E) {
return false;
}
}
return OTP_MIN_LEN <= len && len <= OTP_MAX_LEN;
} |
1290826_6 | public static boolean isValidOTPFormat(String otp) {
if (otp == null){
return false;
}
int len = otp.length();
for (char c : otp.toCharArray()) {
if (c < 0x20 || c > 0x7E) {
return false;
}
}
return OTP_MIN_LEN <= len && len <= OTP_MAX_LEN;
} |
1290826_7 | ; |
1290826_8 | public static String getPublicId(String otp) {
if ((otp == null) || (otp.length() < OTP_MIN_LEN)){
//not a valid OTP format, throw an exception
throw new IllegalArgumentException("The OTP is too short to be valid");
}
Integer len = otp.length();
/* The OTP part is always the last 32 bytes of otp. Whatever is before that
* (if anything) is the public ID of the YubiKey. The ID can be set to ''
* through personalization.
*/
return otp.substring(0, len - 32).toLowerCase();
} |
1290826_9 | public static String getPublicId(String otp) {
if ((otp == null) || (otp.length() < OTP_MIN_LEN)){
//not a valid OTP format, throw an exception
throw new IllegalArgumentException("The OTP is too short to be valid");
}
Integer len = otp.length();
/* The OTP part is always the last 32 bytes of otp. Whatever is before that
* (if anything) is the public ID of the YubiKey. The ID can be set to ''
* through personalization.
*/
return otp.substring(0, len - 32).toLowerCase();
} |
1293378_0 | public float getCrossover() {
return crossover;
} |
1293378_1 | public float getElitism() {
return elitism;
} |
1293378_2 | public float getMutation() {
return mutation;
} |
1293378_3 | public Chromosome[] getPopulation() {
Chromosome[] arr = new Chromosome[popArr.length];
System.arraycopy(popArr, 0, arr, 0, popArr.length);
return arr;
} |
1293378_4 | public void evolve() {
// Create a buffer for the new generation
Chromosome[] buffer = new Chromosome[popArr.length];
// Copy over a portion of the population unchanged, based on
// the elitism ratio.
int idx = Math.round(popArr.length * elitism);
System.arraycopy(popArr, 0, buffer, 0, idx);
// Iterate over the remainder of the population and evolve as
// appropriate.
while (idx < buffer.length) {
// Check to see if we should perform a crossover.
if (rand.nextFloat() <= crossover) {
// Select the parents and mate to get their children
Chromosome[] parents = selectParents();
Chromosome[] children = parents[0].mate(parents[1]);
// Check to see if the first child should be mutated.
if (rand.nextFloat() <= mutation) {
buffer[idx++] = children[0].mutate();
} else {
buffer[idx++] = children[0];
}
// Repeat for the second child, if there is room.
if (idx < buffer.length) {
if (rand.nextFloat() <= mutation) {
buffer[idx] = children[1].mutate();
} else {
buffer[idx] = children[1];
}
}
} else { // No crossover, so copy verbatium.
// Determine if mutation should occur.
if (rand.nextFloat() <= mutation) {
buffer[idx] = popArr[idx].mutate();
} else {
buffer[idx] = popArr[idx];
}
}
// Increase our counter
++idx;
}
// Sort the buffer based on fitness.
Arrays.sort(buffer);
// Reset the population
popArr = buffer;
} |
1293378_5 | public int getFitness() {
return fitness;
} |
1293378_6 | public Chromosome mutate() {
char[] arr = gene.toCharArray();
int idx = rand.nextInt(arr.length);
int delta = (rand.nextInt() % 90) + 32;
arr[idx] = (char) ((arr[idx] + delta) % 122);
return new Chromosome(String.valueOf(arr));
} |
1293378_7 | public Chromosome[] mate(Chromosome mate) {
// Convert the genes to arrays to make thing easier.
char[] arr1 = gene.toCharArray();
char[] arr2 = mate.gene.toCharArray();
// Select a random pivot point for the mating
int pivot = rand.nextInt(arr1.length);
// Provide a container for the child gene data
char[] child1 = new char[gene.length()];
char[] child2 = new char[gene.length()];
// Copy the data from each gene to the first child.
System.arraycopy(arr1, 0, child1, 0, pivot);
System.arraycopy(arr2, pivot, child1, pivot, (child1.length - pivot));
// Repeat for the second child, but in reverse order.
System.arraycopy(arr2, 0, child2, 0, pivot);
System.arraycopy(arr1, pivot, child2, pivot, (child2.length - pivot));
return new Chromosome[] { new Chromosome(String.valueOf(child1)),
new Chromosome(String.valueOf(child2))};
} |
1293378_8 | @Override
public int compareTo(Chromosome c) {
if (fitness < c.fitness) {
return -1;
} else if (fitness > c.fitness) {
return 1;
}
return 0;
} |
1293378_9 | @Override
public boolean equals(Object o) {
if (!(o instanceof Chromosome)) {
return false;
}
Chromosome c = (Chromosome) o;
return (gene.equals(c.gene) && fitness == c.fitness);
} |
1294371_2 | public Set<K> keySet() {
return new KeySet();
} |
1294371_3 | public void advance(int offset) throws IllegalArgumentException {
if (offset == 0) {
return;
}
int newStart = myStart + offset;
if (newStart < 0) {
throw new IllegalArgumentException(String.format(
"Can't apply given offset (%d) to the current text change object (%s). Reason: new start index becomes negative after that (%d)",
offset, this, newStart
));
}
setStart(newStart);
setEnd(myEnd + offset);
} |
1294371_4 | public void advance(int offset) throws IllegalArgumentException {
if (offset == 0) {
return;
}
int newStart = myStart + offset;
if (newStart < 0) {
throw new IllegalArgumentException(String.format(
"Can't apply given offset (%d) to the current text change object (%s). Reason: new start index becomes negative after that (%d)",
offset, this, newStart
));
}
setStart(newStart);
setEnd(myEnd + offset);
} |
1294371_5 | @NotNull
public List<IncrementalCacheUpdateEvent> getEvents() {
return myEvents;
} |
1294371_6 | @NotNull
public List<IncrementalCacheUpdateEvent> getEvents() {
return myEvents;
} |
1294371_7 | @NotNull
public List<IncrementalCacheUpdateEvent> getEvents() {
return myEvents;
} |
1294371_8 | @NotNull
public List<IncrementalCacheUpdateEvent> getEvents() {
return myEvents;
} |
1294371_9 | @NotNull
public List<IncrementalCacheUpdateEvent> getEvents() {
return myEvents;
} |
1302098_0 | public boolean setBit(long index, boolean value) {
boolean answer = false;
BitArray ba = getBitArray(index);
if (ba != null) {
int offset = getOffset(index);
if (offset >= 0) {
answer = ba.set(offset, value);
}
}
return answer;
} |
1302098_1 | public static CompositeData parseComposite(URI uri) throws URISyntaxException {
CompositeData rc = new CompositeData();
rc.scheme = uri.getScheme();
String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim();
parseComposite(uri, rc, ssp);
rc.fragment = uri.getFragment();
return rc;
} |
1302098_2 | public static CompositeData parseComposite(URI uri) throws URISyntaxException {
CompositeData rc = new CompositeData();
rc.scheme = uri.getScheme();
String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim();
parseComposite(uri, rc, ssp);
rc.fragment = uri.getFragment();
return rc;
} |
1302098_3 | public static CompositeData parseComposite(URI uri) throws URISyntaxException {
CompositeData rc = new CompositeData();
rc.scheme = uri.getScheme();
String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim();
parseComposite(uri, rc, ssp);
rc.fragment = uri.getFragment();
return rc;
} |
1302098_4 | public static CompositeData parseComposite(URI uri) throws URISyntaxException {
CompositeData rc = new CompositeData();
rc.scheme = uri.getScheme();
String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim();
parseComposite(uri, rc, ssp);
rc.fragment = uri.getFragment();
return rc;
} |
1302098_5 | public static CompositeData parseComposite(URI uri) throws URISyntaxException {
CompositeData rc = new CompositeData();
rc.scheme = uri.getScheme();
String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim();
parseComposite(uri, rc, ssp);
rc.fragment = uri.getFragment();
return rc;
} |
1302098_6 | public static boolean checkParenthesis(String str) {
boolean result = true;
if (str != null) {
int open = 0;
int closed = 0;
int i = 0;
while ((i = str.indexOf('(', i)) >= 0) {
i++;
open++;
}
i = 0;
while ((i = str.indexOf(')', i)) >= 0) {
i++;
closed++;
}
result = open == closed;
}
return result;
} |
1302098_7 | static public <T> T decode(Class<T> clazz, URL url) throws IOException, XMLStreamException, JAXBException, SAXException {
return decode(clazz, url, null);
} |
1302098_8 | static public void encode(Object in, OutputStream os, boolean format) throws JAXBException {
ClassLoader original = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(ClassFinder.class_loader());
Marshaller marshaller = context().createMarshaller();
if( format ) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, java.lang.Boolean.TRUE);
}
marshaller.marshal(in, new OutputStreamWriter(os));
} finally {
Thread.currentThread().setContextClassLoader(original);
}
} |
1307005_0 | public File newFolder(String folder) throws IOException {
return newFolder(new String[]{folder});
} |
1307005_1 | public File newFile() throws IOException {
return File.createTempFile("junit", null, getRoot());
} |
1307227_0 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_1 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_2 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_3 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_4 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_5 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_6 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_7 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
1307227_8 | public static LoggerStore createLoggerStore(final String configuratorType, final String resource) {
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final Map<String, Object> data = new HashMap<String, Object>();
data.put(INITIAL_FACTORY, getFactoryClassName(configuratorType));
data.put(FILE_LOCATION, resource);
return factory.createLoggerStore(data);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.