예제 #1
1
  protected static <T extends Enum<T>> T parseEnum(
      Class<T> enumClass, String name, T defaultValue, Pair<String, T>... additionalPairs) {
    if (name == null) {
      return defaultValue;
    }

    name = name.toLowerCase();
    for (T enumConstant : enumClass.getEnumConstants()) {
      if (enumConstant.name().equalsIgnoreCase(name)) {
        return enumConstant;
      }
    }
    for (T enumConstant : enumClass.getEnumConstants()) {
      if (enumConstant.name().toLowerCase().startsWith(name)) {
        return enumConstant;
      }
    }

    for (Pair<String, T> additional : additionalPairs) {
      if (additional.first().equalsIgnoreCase(name)) {
        return additional.other();
      }
    }
    for (Pair<String, T> additional : additionalPairs) {
      if (additional.first().toLowerCase().startsWith(name)) {
        return additional.other();
      }
    }

    throw new IllegalArgumentException("No '" + name + "' or '" + name + ".*' in " + enumClass);
  }
 @Override
 protected void doSomething() throws Throwable {
   Pair<Integer, Node> pair = getNode(random, true);
   int index = pair.first();
   Node node = pair.other();
   node.delete();
   setNode(index, db.createNode());
 }
예제 #3
0
파일: Server.java 프로젝트: Analect/neo4j
 protected void tryToFinishOffChannel(Channel channel) {
   Pair<RequestContext, AtomicLong> slave;
   slave = unmapSlave(channel);
   if (slave == null) {
     return;
   }
   tryToFinishOffChannel(channel, slave.first());
 }
  private String createParameterString(Pair<String, String>[] params) {
    String paramString = "";
    for (Pair<String, String> param : params) {
      String delimiter = paramString.isEmpty() || paramString.endsWith("{") ? "" : ",";

      paramString += delimiter + "\"" + param.first() + "\":\"" + param.other() + "\"";
    }

    return paramString;
  }
  protected String createParameterString(Pair<String, String>[] params) {
    String paramString = "\"params\": {";
    for (Pair<String, String> param : params) {
      String delimiter = paramString.endsWith("{") ? "" : ",";

      paramString += delimiter + "\"" + param.first() + "\":\"" + param.other() + "\"";
    }
    paramString += "}";

    return paramString;
  }
 private void assertBitPackedArrayGetsCorrectlySerializedAndDeserialized(
     Object array, PropertyType type, int expectedBitsUsedPerItem, int expectedRecordCount) {
   Collection<DynamicRecord> records = storeArray(array);
   Pair<byte[], byte[]> asBytes = loadArray(records);
   assertArrayHeader(asBytes.first(), type, expectedBitsUsedPerItem);
   Bits bits = Bits.bitsFromBytes(asBytes.other());
   int length = Array.getLength(array);
   for (int i = 0; i < length; i++)
     assertEquals(
         ((Number) Array.get(array, i)).longValue(), bits.getLong(expectedBitsUsedPerItem));
 }
 @Test
 public void stringArrayGetsStoredAsUtf8() throws Exception {
   String[] array = new String[] {"first", "second"};
   Collection<DynamicRecord> records = arrayStore.allocateRecords(arrayStore.nextBlockId(), array);
   Pair<byte[], byte[]> loaded = loadArray(records);
   assertStringHeader(loaded.first(), array.length);
   ByteBuffer buffer = ByteBuffer.wrap(loaded.other());
   for (String item : array) {
     byte[] expectedData = UTF8.encode(item);
     assertEquals(expectedData.length, buffer.getInt());
     byte[] loadedItem = new byte[expectedData.length];
     buffer.get(loadedItem);
     assertTrue(Arrays.equals(expectedData, loadedItem));
   }
 }
예제 #8
0
 @Override
 public void startup(Pair<String, String> config) throws Throwable {
   String storeDir = config.first();
   String backupConfigValue = config.other();
   if (backupConfigValue == null) {
     this.db = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);
   } else {
     // TODO This is using the old config style - is this class even used anywhere!?
     this.db =
         new GraphDatabaseFactory()
             .newEmbeddedDatabaseBuilder(storeDir)
             .setConfig("enable_online_backup", backupConfigValue)
             .newGraphDatabase();
   }
 }
예제 #9
0
 PluginManager(Config serverConfig, Iterable<ServerPlugin> plugins, LogProvider logProvider) {
   Map<String, Pair<ServerPlugin, ServerExtender>> extensions =
       new HashMap<String, Pair<ServerPlugin, ServerExtender>>();
   Log log = logProvider.getLog(getClass());
   for (ServerPlugin plugin : plugins) {
     PluginPointFactory factory = new PluginPointFactoryImpl();
     final ServerExtender extender = new ServerExtender(factory);
     try {
       plugin.loadServerExtender(extender);
     } catch (Exception ex) {
       log.warn("Failed to load plugin [%s]: %s", plugin.toString(), ex.getMessage());
       continue;
     } catch (LinkageError err) {
       log.warn("Failed to load plugin [%s]: %s", plugin.toString(), err.getMessage());
       continue;
     }
     Pair<ServerPlugin, ServerExtender> old =
         extensions.put(plugin.name, Pair.of(plugin, extender));
     if (old != null) {
       log.warn(
           String.format(
               "Extension naming conflict \"%s\" between \"%s\" and \"%s\"",
               plugin.name, old.first().getClass(), plugin.getClass()));
     }
   }
   for (Pair<ServerPlugin, ServerExtender> extension : extensions.values()) {
     log.info(String.format("Loaded server plugin \"%s\"", extension.first().name));
     for (PluginPoint point : extension.other().all()) {
       log.info(
           String.format(
               "  %s.%s: %s",
               point.forType().getSimpleName(), point.name(), point.getDescription()));
     }
     this.extensions.put(extension.first().name, extension.other());
   }
 }
예제 #10
0
  @POST
  public Response exec(@Context InputFormat input, String data) {
    Map<String, Object> args;
    try {
      args = input.readMap(data);
    } catch (BadInputException e) {
      return output.badRequest(e);
    }

    if (!args.containsKey("command")) {
      return Response.status(Status.BAD_REQUEST)
          .entity("Expected command argument not present.")
          .build();
    }

    ScriptSession scriptSession;
    try {
      scriptSession = getSession(args);
    } catch (IllegalArgumentException e) {
      return output.badRequest(e);
    }

    log.debug(scriptSession.toString());
    try {
      Pair<String, String> result = scriptSession.evaluate((String) args.get("command"));
      List<Representation> list =
          new ArrayList<Representation>(
              asList(
                  ValueRepresentation.string(result.first()),
                  ValueRepresentation.string(result.other())));

      return output.ok(new ListRepresentation(RepresentationType.STRING, list));
    } catch (Exception e) {
      List<Representation> list =
          new ArrayList<Representation>(
              asList(
                  ValueRepresentation.string(e.getClass() + " : " + e.getMessage() + "\n"),
                  ValueRepresentation.string(null)));
      return output.ok(new ListRepresentation(RepresentationType.STRING, list));
    }
  }