code
stringlengths
73
34.1k
label
stringclasses
1 value
public static String setProperty(ArgumentUnit argumentUnit, String propertyName, String propertyValue) { Properties properties = ArgumentUnitUtils.getProperties(argumentUnit); String result = (String) properties.setProperty(propertyName, propertyValue); ArgumentUnitUtils.setPrope...
java
public static String getProperty(ArgumentUnit argumentUnit, String propertyName) { Properties properties = ArgumentUnitUtils.getProperties(argumentUnit); return (String) properties.get(propertyName); }
java
public static boolean isImplicit(ArgumentUnit argumentUnit) throws IllegalStateException { // is the implicit flag set? String implicitProperty = ArgumentUnitUtils.getProperty(argumentUnit, ArgumentUnitUtils.PROP_KEY_IS_IMPLICIT); // is the length really zero? ...
java
public static void setIsImplicit(ArgumentUnit argumentUnit, boolean implicit) throws IllegalArgumentException { int length = argumentUnit.getEnd() - argumentUnit.getBegin(); if (length > 0) { throw new IllegalArgumentException("Cannot set 'implicit' property to component " +...
java
public static <E extends DSet.Entry> DSet<E> newDSet (Iterable<? extends E> source) { return new DSet<E>(source); }
java
public void writeObject (ObjectOutputStream out) throws IOException { out.writeInt(_size); for (int ii = 0; ii < _size; ii++) { out.writeObject(_entries[ii]); } }
java
public void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException { _size = in.readInt(); // ensure our capacity is a power of 2 (for consistency) int capacity = INITIAL_CAPACITY; while (capacity < _size) { capacity <<= 1; } ...
java
public void addTranslation (String oldname, String newname) { if (_translations == null) { _translations = Maps.newHashMap(); } _translations.put(oldname, newname); }
java
public String readIntern () throws IOException { // create our intern map if necessary if (_internmap == null) { _internmap = Lists.newArrayList(); // insert a zeroth element _internmap.add(null); } // read in the intern code for this inst...
java
protected ClassMapping readClassMapping () throws IOException, ClassNotFoundException { // create our classmap if necessary if (_classmap == null) { _classmap = Lists.newArrayList(); // insert a zeroth element _classmap.add(null); } // rea...
java
protected ClassMapping mapClass (short code, String cname) throws IOException, ClassNotFoundException { // create a class mapping record, and cache it ClassMapping cmap = createClassMapping(code, cname); _classmap.add(code, cmap); return cmap; }
java
protected ClassMapping createClassMapping (short code, String cname) throws IOException, ClassNotFoundException { // resolve the class and streamer ClassLoader loader = (_loader != null) ? _loader : Thread.currentThread().getContextClassLoader(); Class<?> sclass = Class.f...
java
public boolean gotPong (PongResponse pong) { if (_ping == null) { // an errant pong that is likely being processed late after // a new connection was opened. return false; } // don't freak out if they keep calling gotPong() after we're done if (_it...
java
public void subscribe (DObjectManager omgr) { if (_active) { log.warning("Active safesub asked to resubscribe " + this + ".", new Exception()); return; } // note that we are now again in the "wishing to be subscribed" state _active = true; // make su...
java
public void unsubscribe (DObjectManager omgr) { if (!_active) { // we may be non-active and have no object which could mean // that subscription failed; in which case we don't want to // complain about anything, just quietly ignore the // unsubscribe request ...
java
public void clear (final Name username) { // if we're holding this username for a session observer, postpone until after the current // dispatch finishes if (_holds.contains(username)) { _holds.remove(username); _omgr.postRunnable(new Runnable () { pub...
java
protected void prune (long now, List<Entry> history) { int prunepos = 0; for (int ll = history.size(); prunepos < ll; prunepos++) { Entry entry = history.get(prunepos); if (now - entry.message.timestamp < HISTORY_EXPIRATION) { break; // stop when we get to the...
java
protected void reportSuccess () { for (int ii = 0, ll = _listeners.size(); ii < ll; ii++) { ClientResolutionListener crl = _listeners.get(ii); try { // add a reference for each listener _clobj.reference(); crl.clientResolved(_username, ...
java
protected void reportFailure (Exception cause) { for (int ii = 0, ll = _listeners.size(); ii < ll; ii++) { ClientResolutionListener crl = _listeners.get(ii); try { crl.resolutionFailed(_username, cause); } catch (Exception e) { log.warning(...
java
public MarcContentHandler setMarcListener(String type, MarcListener listener) { this.listeners.put(type, listener); return this; }
java
public boolean moveTo (int placeId) { // make sure the placeId is valid if (placeId < 0) { log.warning("Refusing moveTo(): invalid placeId " + placeId + "."); return false; } // first check to see if our observers are happy with this move request if (...
java
public boolean leavePlace () { if (_pendingPlaceId != -1) { return false; } _lservice.leavePlace(); didLeavePlace(); // let our observers know that we're no longer in a location _observers.apply(_didChangeOp); return true; }
java
public boolean mayMoveTo (final int placeId, ResultListener<PlaceConfig> rl) { final boolean[] vetoed = new boolean[1]; _observers.apply(new ObserverOp<LocationObserver>() { public boolean apply (LocationObserver obs) { vetoed[0] = (vetoed[0] || !obs.locationMayChange(pla...
java
protected void mayLeavePlace () { if (_controller != null) { try { _controller.mayLeavePlace(_plobj); } catch (Exception e) { log.warning("Place controller choked in mayLeavePlace", "plobj", _plobj, e); } } }
java
public void didMoveTo (int placeId, PlaceConfig config) { if (_moveListener != null) { _moveListener.requestCompleted(config); _moveListener = null; } // keep track of our previous place id _previousPlaceId = _placeId; // clear out our last request t...
java
public void didLeavePlace () { // unsubscribe from our old place object if (_subber != null) { _subber.unsubscribe(_ctx.getDObjectManager()); _subber = null; } // let the old controller know that things are going away if (_plobj != null && _controller...
java
public void failedToMoveTo (int placeId, String reason) { if (_moveListener != null) { _moveListener.requestFailed(new MoveFailedException(reason)); _moveListener = null; } // clear out our last request time _lastRequestTime = 0; // let our observers...
java
public boolean checkRepeatMove () { long now = System.currentTimeMillis(); if (now - _lastRequestTime < STALE_REQUEST_DURATION) { return true; } else { _lastRequestTime = now; return false; } }
java
public void setFailureHandler (FailureHandler handler) { if (_failureHandler != null) { log.warning("Requested to set failure handler, but we've already got one. The " + "conflicting entities will likely need to perform more sophisticated " + "coor...
java
public void removeGlobals () { Iterator<String> i = _imports.iterator(); while (i.hasNext()) { String name = i.next(); if (name.indexOf('.') == -1) { i.remove(); } else if (name.startsWith("java.lang")) { i.remove(); } ...
java
public void removeSamePackage (String pkg) { Iterator<String> i = _imports.iterator(); while (i.hasNext()) { String name = i.next(); if (name.startsWith(pkg) && name.indexOf('.', pkg.length() + 1) == -1) { i.remove(); } ...
java
public void translateClassArrays () { ImportSet arrayTypes = new ImportSet(); Iterator<String> i = _imports.iterator(); while (i.hasNext()) { String name = i.next(); int bracket = name.lastIndexOf('['); if (bracket != -1 && name.charAt(brac...
java
public void popIn () { String front = _pushed.remove(_pushed.size() - 1); if (front != null) { _imports.add(front); } }
java
public void replace (String... replace) { HashSet<String> toAdd = Sets.newHashSet(); Iterator<String> i = _imports.iterator(); while (i.hasNext()) { String name = i.next(); for (int j = 0; j < replace.length; j += 2) { if (name.equals(replace[j])) { ...
java
public int removeAll (String pattern) { Pattern pat = makePattern(pattern); int removed = 0; Iterator<String> i = _imports.iterator(); while (i.hasNext()) { String name = i.next(); if (pat.matcher(name).matches()) { i.remove(); ...
java
public List<List<String>> toGroups () { List<String> list = Lists.newArrayList(_imports); Collections.sort(list, new Comparator<String>() { public int compare (String class1, String class2) { return ComparisonChain.start() .compare(findImportGroup(clas...
java
public List<String> toList () { ComparableArrayList<String> list = new ComparableArrayList<String>(); list.addAll(_imports); list.sort(); return list; }
java
protected int findImportGroup (String imp) { int bestGroup = -1; int bestPrefixLength = -1; int ii = -1; for (String prefix : getImportGroups()) { ii++; if (!imp.startsWith(prefix)) { continue; } if (prefix.length() > be...
java
protected static Pattern makePattern (String input) { StringBuilder pattern = new StringBuilder('^'); while (true) { String[] parts = _splitter.split(input, 2); pattern.append(Pattern.quote(parts[0])); if (parts.length == 1) { break; }...
java
public static Method getMethod (String name, Object target, Map<String, Method> cache) { Class<?> tclass = target.getClass(); String key = tclass.getName() + ":" + name; Method method = cache.get(key); if (method == null) { method = findMethod(tclass, name); ...
java
public static Method getMethod (String name, Object target, Object[] args) { Class<?> tclass = target.getClass(); Method meth = null; try { MethodFinder finder = new MethodFinder(tclass); meth = finder.findMethod(name, args); } catch (NoSuchMethodException n...
java
public static Method findMethod (Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method : methods) { if (method.getName().equals(name)) { return method; } } return null; }
java
public void authenticateConnection (Invoker invoker, final AuthingConnection conn, final ResultListener<AuthingConnection> onComplete) { final AuthRequest req = conn.getAuthRequest(); final AuthResponseData rdata = createResponseData(); final AuthRespo...
java
public int append(int newByte) { int old = buffer2[pos]; buffer2[pos] = newByte; buffer[pos] = cs ? (char) newByte : Character.toLowerCase((char) newByte); pos = (++pos < buffer.length) ? pos : 0; return old; }
java
public boolean hasData() { int apos = token.length - 1; int rpos = pos - 1; for (; rpos > -1 && apos > -1; rpos--, apos--) { if (buffer2[rpos] != -1) { return true; } } for (rpos = buffer2.length - 1; apos > -1; rpos--, apos--) { ...
java
public void clear(int i) { char ch = (char) -1; int apos = i - 1; int rpos = pos - 1; for (; rpos > -1 && apos > -1; rpos--, apos--) { buffer[rpos] = ch; buffer2[rpos] = -1; } for (rpos = buffer.length - 1; apos > -1; rpos--, apos--) { ...
java
public void moveTo (int arg1, LocationService.MoveListener arg2) { LocationMarshaller.MoveMarshaller listener2 = new LocationMarshaller.MoveMarshaller(); listener2.listener = arg2; sendRequest(MOVE_TO, new Object[] { Integer.valueOf(arg1), listener2 }); }
java
public void speak (ClientObject caller, String message, byte mode) { // ensure that the caller has normal chat privileges BodyObject source = (_locator != null) ? _locator.forClient(caller) : (BodyObject) caller; String errmsg = source.checkAccess(ChatCodes.CHAT_ACCESS, null); ...
java
protected void sendSpeak (BodyObject source, String message, byte mode) { SpeakUtil.sendSpeak(_speakObj, source.getVisibleName(), null, message, mode); }
java
protected ArgumentComponent selectMainArgumentComponent( List<ArgumentComponent> argumentComponents) { ArgumentComponent result = null; int maxLength = Integer.MIN_VALUE; for (ArgumentComponent argumentComponent : argumentComponents) { int length = argumentComponent....
java
public static void requireAccess (ClientObject clobj, Permission perm, Object context) throws InvocationException { String errmsg = clobj.checkAccess(perm, context); if (errmsg != null) { throw new InvocationException(errmsg); } }
java
public void writeTo (ObjectOutputStream out) throws IOException { out.writeShort(_mask.length); out.write(_mask); }
java
public void readFrom (ObjectInputStream in) throws IOException { int length = in.readShort(); _mask = new byte[length]; in.read(_mask); }
java
public void init (ConnectionManager cmgr, SocketChannel channel, long createStamp) throws IOException { _cmgr = cmgr; _channel = channel; _lastEvent = createStamp; _connectionId = ++_lastConnectionId; }
java
public void networkFailure (IOException ioe) { // if we're already closed, then something is seriously funny if (isClosed()) { log.warning("Failure reported on closed connection " + this + ".", new Exception()); return; } // let the connection manager know we...
java
public boolean checkIdle (long idleStamp) { if (_lastEvent > idleStamp) { return false; } if (!isClosed()) { log.info("Disconnecting non-communicative client", "conn", this, "idle", (System.currentTimeMillis() - _lastEvent) + "ms"); } ...
java
protected void closeSocket () { if (_channel == null) { return; } log.debug("Closing channel " + this + "."); try { _channel.close(); } catch (IOException ioe) { log.warning("Error closing connection", "conn", this, "error", ioe); ...
java
public String checkToken (BureauCredentials creds) { Bureau bureau = _bureaus.get(creds.clientId); if (bureau == null) { return "Bureau " + creds.clientId + " not found"; } if (bureau.clientObj != null) { return "Bureau " + creds.clientId + " already logged in...
java
public void startAgent (AgentObject agent) { agent.setLocal(AgentData.class, new AgentData()); Bureau bureau = _bureaus.get(agent.bureauId); if (bureau != null && bureau.ready()) { _omgr.registerObject(agent); log.info("Bureau ready, sending createAgent", "agent", a...
java
public void destroyAgent (AgentObject agent) { FoundAgent found = resolve(null, agent.getOid(), "destroyAgent"); if (found == null) { return; } log.info("Destroying agent", "agent", agent.which()); // transition the agent to a new state and perform the effect of...
java
public PresentsSession lookupClient (String bureauId) { Bureau bureau = _bureaus.get(bureauId); if (bureau == null) { return null; } return bureau.client; }
java
public Exception getLaunchError (AgentObject agentObj) { AgentData data = agentObj.getLocal(AgentData.class); if (data == null) { return null; } return data.launchError; }
java
protected void bureauInitialized (ClientObject client, String bureauId) { final Bureau bureau = _bureaus.get(bureauId); if (bureau == null) { log.warning("Initialization of non-existent bureau", "bureauId", bureauId); return; } bureau.clientObj = client; ...
java
protected void agentCreated (ClientObject client, int agentId) { FoundAgent found = resolve(client, agentId, "agentCreated"); if (found == null) { return; } log.info("Agent creation confirmed", "agent", found.agent.which()); if (found.state == AgentState.STARTED...
java
protected void agentCreationFailed (ClientObject client, int agentId) { FoundAgent found = resolve(client, agentId, "agentCreationFailed"); if (found == null) { return; } log.info("Agent creation failed", "agent", found.agent.which()); if (found.state == AgentSt...
java
protected void clientDestroyed (Bureau bureau) { log.info("Client destroyed, destroying all agents", "bureau", bureau); // clean up any agents attached to this bureau for (AgentObject agent : bureau.agentStates.keySet()) { _omgr.destroyObject(agent.getOid()); } b...
java
protected FoundAgent resolve (ClientObject client, int agentId, String resolver) { com.threerings.presents.dobj.DObject dobj = _omgr.getObject(agentId); if (dobj == null) { log.warning("Non-existent agent", "function", resolver, "agentId", agentId); return null; } ...
java
protected String generateToken (String bureauId) { String tokenSource = bureauId + "@" + System.currentTimeMillis() + "r" + Math.random(); return StringUtil.md5hex(tokenSource); }
java
protected void launchTimeoutExpired (Bureau bureau) { if (bureau.clientObj != null) { return; // all's well, ignore } if (!_bureaus.containsKey(bureau.bureauId)) { // bureau has already managed to get destroyed before the launch timeout, ignore return; ...
java
protected void handleLaunchError (Bureau bureau, Exception error, String cause) { if (cause == null && error != null) { cause = error.getMessage(); } log.info("Bureau failed to launch", "bureau", bureau, "cause", cause); // clean up any agents attached to this bureau ...
java
public void gotConfigInfo (final String[] keys, final int[] oids) { // make sure we're still added if (!isDisplayable()) { return; } Integer indexes[] = new Integer[keys.length]; for (int ii = 0; ii < indexes.length; ii++) { indexes[ii] = ii; ...
java
@Override public Chunk<byte[], BytesReference> readChunk() throws IOException { Chunk<byte[], BytesReference> chunk = internalReadChunk(); if (chunk != null) { processChunk(chunk); } return chunk; }
java
public boolean addChatterObserver (ChatterObserver co) { boolean added = _chatterObservers.add(co); co.chattersUpdated(_chatters.listIterator()); return added; }
java
public void registerCommandHandler (MessageBundle msg, String command, CommandHandler handler) { // the usage key is derived from the untranslated command handler._usageKey = "m.usage_" + command; String key = "c." + command; handler._aliases = msg.exists(key) ? msg.get(key).split("...
java
public void clearDisplays () { _displays.apply(new ObserverList.ObserverOp<ChatDisplay>() { public boolean apply (ChatDisplay observer) { observer.clear(); return true; } }); }
java
public void displayInfo (String bundle, String message) { displaySystem(bundle, message, SystemMessage.INFO, PLACE_CHAT_TYPE); }
java
public void displayInfo (String bundle, String message, String localtype) { displaySystem(bundle, message, SystemMessage.INFO, localtype); }
java
public void displayFeedback (String bundle, String message) { displaySystem(bundle, message, SystemMessage.FEEDBACK, PLACE_CHAT_TYPE); }
java
public void displayAttention (String bundle, String message) { displaySystem(bundle, message, SystemMessage.ATTENTION, PLACE_CHAT_TYPE); }
java
public void dispatchMessage (ChatMessage message, String localType) { setClientInfo(message, localType); dispatchPreparedMessage(message); }
java
public String requestChat (SpeakService speakSvc, String text, boolean record) { if (text.startsWith("/")) { // split the text up into a command and arguments String command = text.substring(1).toLowerCase(); String[] hist = new String[1]; String args = ""; ...
java
public void requestBroadcast (String message) { message = filter(message, null, true); if (message == null) { displayFeedback(_bundle, MessageBundle.compose("m.broadcast_failed", "m.filtered")); return; } _cservice.broadcast(message, new ChatService.Invocation...
java
public <T extends Name> void requestTell ( final T target, String msg, final ResultListener<T> rl) { // make sure they can say what they want to say final String message = filter(msg, target, true); if (message == null) { if (rl != null) { rl.requestFailed...
java
public void setAwayMessage (String message) { if (message != null) { message = filter(message, null, true); if (message == null) { // they filtered away their own away message... change it to something message = "..."; } } /...
java
public void addAuxiliarySource (DObject source, String localtype) { source.addListener(this); _auxes.put(source.getOid(), localtype); }
java
public String filter (String msg, Name otherUser, boolean outgoing) { _filterMessageOp.setMessage(msg, otherUser, outgoing); _filters.apply(_filterMessageOp); return _filterMessageOp.getMessage(); }
java
protected void registerCommandHandlers () { MessageBundle msg = _ctx.getMessageManager().getBundle(_bundle); registerCommandHandler(msg, "help", new HelpHandler()); registerCommandHandler(msg, "clear", new ClearHandler()); registerCommandHandler(msg, "speak", new SpeakHandler()); ...
java
protected void processReceivedMessage (ChatMessage msg, String localtype) { String autoResponse = null; Name speaker = null; Name speakerDisplay = null; byte mode = (byte)-1; // figure out if the message was triggered by another user if (msg instanceof UserMessage) {...
java
protected void addToHistory (String cmd) { // remove any previous instance of this command _history.remove(cmd); // append it to the end _history.add(cmd); // prune the history once it extends beyond max size if (_history.size() > MAX_COMMAND_HISTORY) { ...
java
protected String mogrifyChat ( String text, byte mode, boolean transformsAllowed, boolean capFirst) { int tlen = text.length(); if (tlen == 0) { return text; // check to make sure there aren't too many caps } else if (tlen > 7 && suppressTooManyCaps()) { ...
java
protected void addChatter (Name name) { // check to see if the chatter validator approves.. if ((_chatterValidator != null) && (!_chatterValidator.isChatterValid(name))) { return; } boolean wasthere = _chatters.remove(name); _chatters.addFirst(name); if (...
java
protected void setClientInfo (ChatMessage msg, String localType) { if (msg.localtype == null) { msg.setClientInfo(xlate(msg.bundle, msg.message), localType); } }
java
protected String xlate (String bundle, String message) { if (bundle != null && _ctx.getMessageManager() != null) { MessageBundle msgb = _ctx.getMessageManager().getBundle(bundle); if (msgb == null) { log.warning("No message bundle available to translate message", "bun...
java
protected void displaySystem (String bundle, String message, byte attLevel, String localtype) { // nothing should be untranslated, so pass the default bundle if need be. if (bundle == null) { bundle = _bundle; } SystemMessage msg = new SystemMessage(message, bundle, attLe...
java
protected String getLocalType (int oid) { String type = _auxes.get(oid); return (type == null) ? PLACE_CHAT_TYPE : type; }
java
public static String dumpArguments(JCas jCas, boolean includeProperties, boolean includeRelations) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PrintStream out = new PrintStream(outputStream); String documentId = DocumentMetaData.get(jCas).getDocumentId(); ou...
java
public static String argumentUnitToString(ArgumentUnit argumentUnit) { return String.format("%s [%d, %d] \"%s\"", argumentUnit.getType().getShortName(), argumentUnit.getBegin(), argumentUnit.getEnd(), argumentUnit.getCoveredText()); }
java
public HashMap<String, String> loadConfig (String node, String object) { HashMap<String, String> data = Maps.newHashMap(); for (ConfigRecord record : from(ConfigRecord.class). where(ConfigRecord.OBJECT.eq(object), ConfigRecord.NODE.eq(node)).select()) { data.put(record.f...
java
public void updateConfig (String node, String object, String field, String value) { store(new ConfigRecord(node, object, field, value)); }
java
public InetAddress getInetAddress () { Connection conn = getConnection(); return (conn == null) ? null : conn.getInetAddress(); }
java